Ultrasonic Sensor SR04 with Starter AVR
In this tutorial we'll look at interfacing HC-SR04 ultrasonic sensor with starter AVR board. This sensor is very popular and used in many projects for finding distance from the obstacle or wall from the sensor. The reason behind its popularity is, it can measure distances from 2 cm up to 400 cm with accuracy of 1 cm.
Contents
Basic
This sensor has four pins namely Vcc, Trig, Echo and Gnd. The basic principle behind its working is:
- Send a 10us pulse on Trigger pin
- Sensor will send 40kHz sonic signal of 8 cycles and detects whether there is pulse signal back
- If the signal back, it will generate a pulse on echo pin. Read echo pin, duration of this pulse on echo pin will give you the distance of the object from sensor by using following formula:
$$Distance = (high level time X velocity of sound(340.26 m/s))/2$$
Hookup
Code
Demo
Downloads