Introduction: INTERFACING HC- SR04 ULTRASONIC SENSOR WITH ARDUINO
1.The ultrasonic sensor also known as distance measuring sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm.Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit.There are only four pins that you need to worry about on the HC-SR04: VCC (Power), Trig (Trigger), Echo (Receive), and GND (Ground). You will find this sensor very easy to interface
Step 1: COMPONENTS REQUIRED
1.HC- SR04 ULTRASONIC SENSOR
2.JUMPER WIRES(4 male-male)
4.ARDUINO WITH USB CABLE(ANY MODEL)
Step 2: WIRING THE COMPONENTS
Wire the components as given
1.VCC-5V ON ARDUINO
2.GND-GND ON ARDUINO
3.ECHO-PIN 10 ON ARDUINO
4.TRIG -PIN 9 ON ARDUINO
Step 3: CODING IN ARDUINO IDE
Please download the code and paste it in the IDE.The next step is based on working on ultrasonic sensor.The explanation of the code is given in the comments in file.
Step 4: WORKING
The sensor emits an ultrasond of 40,000hz and travels in air when it hits an obstacle it is detected by the receiver and time taken is taken as the base for calculating the distance
The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.
In order to generate the ultrasound you need to set the Trig on a High State for 10 µs. That will send out an 8 cycle sonic burst which will travel at the speed sound and it will be received in the Echo pin. The Echo pin will output the time in microseconds the sound wave traveled.
For example, if the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward. So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by
The coding is self explained in comments please download it.
Step 5: FINAL STEP
open your serial monitor and check the measurement.hope you enjoy this instructable and please leave a comment below.
andystechgarage made it!
We have a be nice policy.
Please be positive and constructive.