Keyestudio Smart Little Turtle Robot V3 Manual page 100

Table of Contents

Advertisement

www.keyestudio.com
(8) Code Explanation
int trigPin-
this pin is defined to transmit ultrasonic waves, generally
output.
int echoPin -
this is defined as the pin of reception, generally input
cm = (duration/2) / 29.1-
inches = (duration/2) / 74-
We can calculate the distance by using the following formula:
distance = (traveltime/2) x speed of sound
The speed of sound is: 343m/s = 0.0343 cm/uS = 1/29.1 cm/uS
Or in inches: 13503.9in/s = 0.0135in/uS = 1/74in/uS
We need to divide the traveltime by 2 because we have to take into
account that the wave was sent, hit the object, and then returned back to
the sensor.
(9) Extension Practice:
We have just measured the distance displayed by the ultrasonic. How
about controlling the LED with the measured distance? Let's try it, connect
an LED light module to the D3 pin.
100

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents