Line 8: Line 8:
 
# Sensor will send 40kHz sonic signal of 8 cycles and detects whether there is pulse signal back
 
# 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:
 
# 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 $$
+
 
 +
$$Distance = (high level time X velocity of sound(340.26 m/s))/2$$
  
 
=Hookup=
 
=Hookup=

Latest revision as of 11:44, 11 April 2016


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.

Basic

This sensor has four pins namely Vcc, Trig, Echo and Gnd. The basic principle behind its working is:

  1. Send a 10us pulse on Trigger pin
  2. Sensor will send 40kHz sonic signal of 8 cycles and detects whether there is pulse signal back
  3. 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

0 Ultrasonic Starter AVR.png

Code

Demo

Downloads