Easy Basics: Project 009e Ultrasonic Sensor HC-SR04, 74HC595, LEDs and active buzzer - simple parking sen

of Acoptex.com in UNO

Basics: Project 009e

Project name: Ultrasonic Sensor HC-SR04, LEDs, 74HC595 and active buzzer - simple parking sensor

Tags: Arduino, Arduino Uno, Ultrasonic Sensor, HC-SR04, LEDs, buzzer, simple parking sensor, 74HC595, shift register

Attachments: sketch

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Ultrasonic Sensor HC-SR04 module

3.Arduino IDE ( you can download it from here  )

4.Jumper cables M-M, F-M

5. Long breadboard 1 pc

6. LED 8 pcs (red - 3pcs, yellow - 3pcs, green -2 pcs)

7. Resistors 9 pcs (220 Ohm)

8.  Chip 74HC595 (shift register) 1 pc

9.Active piezo buzzer 1 pc


In this project we have an ultrasonic sensor measuring the distance, LEDs will light up according to our distance from the sensor. As we get closer to the sensor the buzzer beeps in a different way.

Understanding the 74HC595 IC

The 74HC595 consists of an 8−bit shift register and a storage register with three - state parallel outputs. It converts serial input into parallel output so you can save IO ports of an MCU.When MR (pin10) is high level and OE (pin13) is low level, data is input in the rising edge of SHcp and goes to the memory register through the rising edge of SHcp. If the two clocks are connected together, the shift register is always one pulse earlier than the memory register. There is a serial shift input pin (Ds), a serial output pin (Q) and an asynchronous reset button (low level) in the memory register. The memory register outputs a Bus with a parallel 8-bit and in three states. When OE is enabled (low level), the data in memory register is output to the bus. 

Understanding the HC-SR04 Ultrasonic Module

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. 

The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package. From 2cm to 400 cm or 1” to 13 feet. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.


  • Power Supply :+5V
  • DCQuiescent Current : <2mA
  • Working Current: 15mA
  • Effectual Angle: <15°
  • Ranging Distance : 2cm – 400 cm/1″ – 13ft
  • Resolution : 0.3 cm
  • Measuring Angle: 30 degrees
  • Trigger Input Pulse width: 10uS
  • Dimension: 45mm x 20mm x 15mm

Ultrasonic Sensor emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering the travel time and the speed of the sound you can calculate 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 2.


You can see datasheet here.

Understanding the piezo buzzer

You can read more about it here.

Signals and connections of LED

The operating voltage of the LED is 1.8V and the operating current is 10mA-20mA. The Arduino Uno board can supply 5V or 3.3V power. We will use 5V for this project, so the minimum resistance of the current limiting resistor should be (5 V to 1.8 V)/20 = 160 Om. The 220 Om offered in the kit is suitable and you can also choose other resistors that meet the condition. The larger the resistance is, the dimmer the LED will get.

Signals and connections of the 74HC595 IC

Pins of 74HC595 and their functions:

Q0-Q7: 8-bit parallel data output pins, able to control 8 LEDs or 8 pins of 7-segment display directly.

Q7’: Series output pin, connected to DS of another 74HC595 to connect multiple 74HC595s in series

MR: Reset pin, active at low level; here it is directly connected to 5V.

SHcp: Time sequence input of shift register. On the rising edge, the data in shift register moves successively one bit, i.e. data in Q1 moves to Q2, and so forth. While on the falling edge, the data in shift register remain unchanged.

STcp: Time sequence input of storage register. On the rising edge, data in the shift register moves into memory register.

OE: Output enable pin, active at low level. Here connected to GND.

DS: Serial data input pin

VCC: Positive supply voltage

GND: Ground

You can check the specification of chip 74HC595 here.

Signals and connections of active piezo buzzer

Active piezo buzzer pin marked with (+) sign should be connected to Arduino Uno board digital pin which sends a signal, the other pin of active piezo buzzer should be connected to Arduino Uno board GND.

Signals and connections of HC-SR04 Ultrasonic Module

"Trig" stands for Trigger Pulse Input

"Echo" stands for Echo Pulse Output

"VCC" stands for power supply (+5V)

"GND" stands for GND (0V)

Duration for the sound to reach echo is twice the duration required to reach the object that will create echo. That is if you shout in front of a wall the voice to reaches the wall and returns back to your ear. The moment you hear the sound, the voice has traveled twice the distance between you and the wall. Thus the time taken will be twice as the speed of sound is constant. Hence the following formula:

d = v/t;

therefore d = 29 / (time in miliseconds / 2).

or d = 340 / (time in seconds / 2).


The following picture shows the needed connections with the Arduino Uno 

Step by Step instruction

  1. Open Arduino IDE.
  2. Plug your Adruino Uno board into your PC and select the correct board and com port
  3. Open up serial monitor and set your baud to 9600 baud
  4. Verify and upload the the sketch to your Adruino Uno
  5. Ultrasonic sensor attached to servo motor (on top of it). Servo motor rotates from 0 to 180 and from 180 to 0 degrees
      and detects the distance to the objects in cm and inch. Message send to Serial monitor at 115200 bps.
    LEDs will light up according to our distance from the sensor. As we get closer to the sensor the buzzer beeps in a different way. 


We have learnt how to make the simple parking sensor.


  • No libraries required for this project


  • See attachment on the begining of this project description.

Other projects of Acoptex.com

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 27-01-2018
Viewed: 1083 times