76
Programming the Distance Sensor
The HC-SR04 ultrasonic distance sensor board is a practical component for your Pi-Bot. Once
programmed, your Pi-Bot will be able to detect an object in front of it and determine its distance.
Note: VCC is the board +5V power supply and the wire is always colored red. The Ground wire is
always colored black. Consistency between these colors will help prevent accidental electrical
damage to the components.
The SR04 ultrasonic detector is used to determine the distance of an object in front of your Pi-Bot. This
is accomplished with the use of an ultrasonic transmitter and an ultrasonic receiver. The sensor emits a
chirp using the transmitter and listens for an echo on the receiver. The time it takes for the return echo
to be detected is proportional to the distance to the object.
The following program,
UltraSonicSensorTest
is simple and easy to understand. Download this program
http://www.stemcenterusa.com/pi-bot/downloads-/
and run it. Open the serial monitor to view
the sensor output as you move an object (wave your hand) in front of the distance sensor. Notice the
screen output is both in cm and inches.
The program will give you erroneous (large numbers) results when the object is out of range, too close.
Modify the program to see the results in cm or inch only.
Summary of Contents for Pi-Bot v2.00
Page 67: ...67 Figure 6 15 ...
Page 78: ...78 UltraSonicSensorTestwithLED Program ...
Page 80: ...80 ObstacleAvoidance Program ...
Page 82: ...82 ObstacleAvoidancewithLED Program ...
Page 83: ...83 ObstacleAvoidancewithLED Program CONTINUED ...
Page 90: ...90 Download and run the following program LineFollowing Program ...
Page 91: ...91 LineFollowing Program CONTINUED ...
Page 94: ...94 AdvancedLineFollowing Program CONTINUED ...
Page 95: ...95 AdvancedLineFollowing Program CONTINUED ...
Page 96: ...96 AdvancedLineFollowing Program CONTINUED ...
Page 110: ...Appendix B Complete Pi Bot Wiring Schematic ...