Lesson 1 The SR04 Ultrasonic sensor and the BYJ-48 stepper motor
Example code (right click and save as)
SR04 library
Stepper library
Task 1: SR04 hardware connections
Place the library zip folder in the code folder.
Select the port and board.
Although
you already had the library zip folder placed in the code folder, you
still need to include the zip library in your project.
Find it and include it.
Now upload the code to your board.
Turn on the monitor to observe the distance data.
Task 2 Integrate the stepper motor into this test
First, include the stepper motor library zip folder to your project. Refer to the steps in Task 1.
In
your example code, comment out your Example 1 code by selecting the
code and then pressing 'ctrl + /' at the same time. Uncomment your
Example 2by selecting the code and then pressing 'ctrl + /".
Make hardware connections.
Another diagram of the hardware connections.
Here is the code and the serial monitor output.
HW1
Use the IF statement to stop the motor when an object is detected within a 20 cm range in front of the SR04 sensor.