[vc_row][vc_column][vc_column_text]Introduction:
The HC-SR04 Ultrasonic Sensor is a very affordable proximity/distance sensor that has been used mainly for object avoidance in various robotics projects . It essentially gives your Arduino eyes / spacial awareness and can prevent your robot from crashing or falling off a table. It has also been used in turret applications, water level sensing, and even as a parking sensor. This simple project will use the HC-SR04 sensor with an Arduino and a Processing sketch to provide a neat little interactive display on your computer screen.
[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Parts List” tab_id=”1394525308-1-33″][vc_column_text]1. 1 x Arduino UNO
2.1 x HC-SR04 Ultrasonic module
3. Jumper wires[/vc_column_text][/vc_tab][vc_tab title=”Experiment Principle” tab_id=”1394525308-2-50″][vc_column_text]We want to calculate the distance of an object in front of the ultrasonic sensor. This sensor can send a “ping” at a given moment and receive the ping bouncing back on an object at another given moment.
A ping is nothing but a sound that is inaudible for the human hear and this is why this sensor is called “ultrasonic”.
The sensor send a ping at a time t1 and receive the bouncing ping at a time t2.
Knowing the speed of sound, the time difference Δt = t2 – t1 can give us an idea of the distance of an object.
Example, if Δt = 500 microseconds, we know it took 250 microseconds for the ping to hit an object and another 250 microseconds to come back.
The approximate speed of sound in dry air is given by the formula:
c = 331.5 + 0.6 * [air temperature in degrees Celsius]
At 20°C, c = 331.5 + 0.6 * 20 = 343.5 m/s
If we convert the speed in centimetres per microseconds we get:
c = 343.5 * 100 / 1000000 = 0.03435 cm/ųs
The distance is therefore, D = (Δt/2) * c
or D = 250 * 0.03435 = 8.6 cm
Instead of using the Speed of Sound, we can also use the “Pace of Sound”.
The Pace of Sound = 1 / Speed of Sound = 1 / 0.03435 = 29.1 ųs/cm
In this case the equation to calculate the distance become: D = (Δt/2) / Pace of sound
and for the example above: D = 250 / 29.1 = 8.6 cm[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1394526315496-2-5″][vc_column_text]
Arduino 5v —–> ultrasonic moduleVCC
Arduino GND —–> ultrasonic module GND
Arduino D2 —–> ultrasonic module TRIG
Arduino D3 —–> ultrasonic module ECHO[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1394526316827-3-7″][vc_column_text]
#include <core.h> const int TrigPin = 2; const int EchoPin = 3; float cm; void setup() { Serial.begin(9600); pinMode(TrigPin, OUTPUT); pinMode(EchoPin, INPUT); } void loop() { digitalWrite(TrigPin, LOW); //Send a low level voltage pulse to TrigPin delayMicroseconds(2); digitalWrite(TrigPin, HIGH); delayMicroseconds(10); digitalWrite(TrigPin, LOW); cm = pulseIn(EchoPin, HIGH) / 58.0; //Echo time convert to cm cm = (int(cm * 100.0)) / 100.0; //Keep two decimal places Serial.print(cm); Serial.print(“cm”); Serial.println(); delay(1000); }
[/vc_column_text][/vc_tab][vc_tab title=”Results” tab_id=”1394526318103-4-8″][vc_column_text][/vc_column_text][/vc_tab][vc_tab title=”Note” tab_id=”1394526712049-5-2″][vc_column_text]Because the sound at different temperatures, the speed is not the same. So if you need the exact distance, you can add a temperature calibration.[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.