EasyManua.ls Logo

SunFounder 3in1 Kit - Page 253

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder 3in1 Kit
Code
Note:
Open the 6.ultrasonic_module.ino file under the path of 3in1-kit\car_project\6.
ultrasonic_module.
Or copy this code into Arduino IDE.
Or upload the code through the Arduino Web Editor.
After the code is successfully uploaded, turn the car towards the wall. If the distance is too far, it will move forward; if
it is too close, it will move backward; if it is at a safe distance, it will stop.
How it works?
This project is based on the distance read by the ultrasonic module to make the car move accordingly.
1. Add the pin definition for the ultrasonic module, trigPin is used to transmit ultrasonic wave, so set it to OUTPUT;
echoPin is set to INPUT to receive ultrasonic wave.
...
const int trigPin = 3;
const int echoPin = 4;
(continues on next page)
5.7. 6. Play with Ultrasonic Module 249

Related product manuals