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

Setting Up Starter AVR

In this tutorial we will look at setting up the starter AVR board. Once you have done with this basic set up, you can use on board peripherals as well as many other peripherals which can be connected...

Blinky with Starter AVR

After setting up starter AVR board, we will start with simple LED blinking experiment. Two user LED's are provided on starter AVR board, we will use same for this experiment. Basic ...

Interfacing LCD with Starter AVR

In this tutorial we'll look at how to interface different types of character LCD's to the starter AVR board. Basic Starter AVR board has female connector on board to connect LCD's...

Interfacing Seven Segment Display with Starter AVR

Now we will go further and will interface more complex peripherals. In this tutorial we will interface common anode 7 segment display to the starter AVR board. To get idea about basics of 7 segment...