Monday, 1 July 2013

HC-SR04 Ultrasonic Sensor




Have you ever wonder what type of sensor that you can use to sense for obstacle ? Well, in this post, I am going to explain a brief detail about using a HC-SR04 Ultrasonic Sensor for sensing obstacle.

The HC-SR04 sensor is using the sonar to determine the distance to an object like what you know about bats or dolphin. It comes complete with ultrasonic transmitter and recevier module.

Some features of the HC-SR04 ultrasonic sensor :
  • Power supply :  +5V DC
  • Working current : 15mA
  •  Measuring angle : 30 degree
  • Ranging distance : 2cm - 400cm 

Datesheet HC-SR04

A very good video preview on ultrasonic sensor ! 





 Let's get started !
Hardware :
  • HC-SR04 x 1
  • LCD x 1
  • Arduino x 1
  • Buzzer x 1
  • Few jumper wires 
Software :
  • Arduino IDE
Hardware connection :

Connect your HC-SR04 as shown below :


 Connect a buzzer to Pin 7 of arduino UNO.

Software :
I found a pretty easy to use arduino library for this. You may download it here :

Ping Library

You may want to view the guide below on how to use this library in arduino

Ping Library Guide

 I have uploaded below code to my arduino

Download Code

A simple demo on my project using HC-SR04:



Feel free to comment and ask if you have any doubt. Would try my best to answer and help :)

Thanks



-VK