Ultrasonic Range Finder: Step 1: Parts List
Ultrasonic Range Finder: Step 1: Parts List
by lingib
This instructable describes how to create a non- The accuracy is typically +/- 3mm depending on
contact range-finder using an Arduino and an HC- distance, air temperature, and humidity.
SR04 ultrasonic module to measure distances in the
range 2cm – 400cm.
Step 3: Theory
The HC-SR04 ultrasonic range-finder module (photo 1) provides non-contact measurements in the range 2cm –
400cm. The accuracy is typically +/- 3mm depending on distance, air temperature, and humidity.
For greatest accuracy the target area should be at least 0.5 square meters. Best results are obtained when the
transducer is pointing directly at the target. Useable results, however, are possible within an imaginary “cone” of
+/- 15 degrees.
Interfacing the HC-SR04 to an Arduino is extremely simple as, apart from the two supply pins, only two wires,
“Trig” (trigger) and “Echo”, are required.
A 10uS (microsecond) trigger pulse must be applied to the “Trig” pin to start each measurement.
On receipt of a trigger pulse the module emits an eight cycle “burst” at a frequency of 40kHz (kilohertz) after which
the “Echo” line goes HIGH. There is a short 430uS interval between the trigger pulse and the rising edge of the
“Echo” pin during which time high energy +/-10 volt charges are built up in the transmitter circuit prior to the
ultrasonic burst.
The “Echo” pin drops LOW on receipt of an echo signal or 210mS whichever comes first.
[ Note:
If you block the ultrasonic signals (I used a rolled up sock against the transducers), you will observe a distance
reading of 3550cm which is outside the sensor range of approximately 400cm.
Beyond 400cm the distance readings will suddenly jump to 3550cm. The reason for this follows:
Should an echo not be received, the task scheduler will continue to set TaskFlag1 "TRUE" every 50mS until the
HC-SR04 times out after 210mS and the Echo pin drops low. All 10uS start pulses generated by the measure()
function during this time are ignored by the HC-SR04.
The timeout value of 210mS corresponds to a distance of 3550cm ... hence the sudden jump in the distance
reading.
The important point is that all distance readings less than 400cm are correct. ]
Typical waveforms
Waveforms for 5cm, 10cm, 20cm, and 200cm distances are shown in photos 2,3,4, and 5.
The top trace in each photo is the “Trig” pin ... the lower trace in each photo is the “Echo” pin.
The duration of each “Echo” pulse can be calculated by multiplying the trace length by the “uS/div” value shown in
the lower-right corner of each photo.
This assumes that the “speed-of-sound” is 340m/S, and that the echo-distance is twice the actual distance.
The exact distance can be obtained by adjusting the constant value of 59.
[ Note:
The value of 59 for the constant is derived as follows:
The reciprocal of 0.034cm/uS is 29.412uS/cm which, when multiplied by 2 to allow for the return path, equals
58.824 or 59 when rounded. ]
Example 1:
Example 2:
The code comprises a “measure()” function that is called once every 50mS using the task-scheduler described in
instructable https://www.instructables.com/id/Multi-task-Your-...
Copy the contents of this text file to an Arduino sketch, save it as "Ultrasonic_range_finder" (without the quotes),
then compile and upload it to your Arduino.
Download
https://www.instructables.com/ORIG/F2U/X2XC/JGWJACWP/F2UX2XCJGWJACWP.ino
…
To view the distance readings click “Tools|Serial “59” value for “Distance” until an exact reading is
Monitor” and set the speed to 115200 bauds. displayed.
The distance readings may be calibrated by placing Click here to view my other instructables.
an object along a ruler then adjusting the constant
I add a 4x20 LCD IIC display and another distance measurement sensor which uses a known
distance to determine the speed of sound in air. I then used that value over the unknown distance
to create an auto calibration circuit.
// Using the SainSmart 20x4 LCD through the I2C interface of
// SDA and SCL found on the Arduino boards UNO and MEGA
//Reading Temperature with LM35 Sensor
//Measuring in both scales Celsius and Fahrenheit
//Arduino Thermometer Shield
//DFRobot.com
//Compatible with the Arduino IDE 1.0
//Library version:1.1
/* Ping))) Sensor
where is photo1??
GREAT IDEA!...