Today I am going to show you How to make a Distance Measuring Device with Automatic Alarm using an Arduino Uno Board and Ultrasonic sensor.It will show you distance in a LCD display and If Something will come in a fixed range it will warn you with message on LCD,LED light and sound.All the parts are attached on a breadboard with wires.
Original Post-Distance Measuring Device with Automatic Alarm
Website- We Observed
Step 1: It Can Be Used .......
- As an Automatic Door bell-Just place it on the door and if some one will come in the range(2cm-450cm).it will inform You.
- As Digital Distance Measurement Tool- Measure distance in centimeter or inches.
- Anti-theft Alarm.
- In Parking area -If any vehicle is too close to the wall or other vehicle then it will warn the driver with sound or warning message on lcd.
- In vehicle
Watch it in Action Here-https://youtu.be/e9tAlh4xXSk
Step 2: Requirements:-
This is the list of parts needed to make the Distance Meter with Automatic Alarm.
- 1 x Arduino UNO board
- 1 x HC-05 Ultrosonic sensor
- 1 x LCD Display (16A1,16A2 or any other)
- 1 x Breadboard
- 1 x 10k Potentiometer/variable resistors(You can also use 5k or 50k)
- LED bulb
- Some male to male jumper wires.
- Power Bank or Battery
- Arduino IDE installed in pc with some basic information about how to use it...
Step 3: Basic Information About Parts and Links to Buy-
Step 4: HC-SR04 Ultrasonic Sensor
- The HC-SR04 ultrasonic sensor uses sonar to measure distance to an object. It offers excellent range accuracy and stable readings in an easy-to-use package. It operation is not affected by sunlight or black material like Sharp rangefinders are (soft materials like cloth can be difficult to detect).
- Module main technical parameters:
- 1.Working Voltage : 5V(DC)
- 2.Static current: Less than 2mA.
- 3.Output signal: Electric frequency signal, high level 5V, low level 0V.
- 4.Sensor angle: Not more than 15 degrees.
- 5.Detection distance: 2cm-450cm.
- 6.High precision: Up to 0.3cm
- 7.Input trigger signal: 10us TTL impulse
- 8.Echo signal : output TTL PWL signal Mode of connection: 1.VCC 2.trig(T) 3.echo(R) 4.GND The basic operation principle is below : use IO port TRIG to trigger ranging. It needs 10 us high level signal at least Module will send eight 40kHz square wave automatically, and will test if there is any signal returned. If there is signal returned, output will be high level signal via IO port ECHO. The duration of the high level signal is the time from transmitter to receiving with the ultrasonic. Testing distance = duration of high level*sound velocity(340m/s) / 2 You can use the above calculation to find the distance between the obstacle and the ultrasonic module.
- NOTE : The module has a blind spot of 2cm(very near). So obstacle held too closely will not be detected.
Read more and Buy It: Distance Measuring Device
Step 5: Circuit Diagram:-
Follow The above circuit and Assemble everything on the breadboard carefully and Attach the Arduino board with PC with connecting cable and Upload the following code.
Step 6: Programming:-
//Distance measuring Tool with Automatic Alarm.#By Sourabh Kumar @ https://weobserved.com
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Pin diclaration for LCD
int pingPin = 7; //Pin diclaration for Trig of Ultrasonic sensor
int inPin = 8; //Pin diclaration for ECHO of Ultrasonic sensor
const int buzzer=9; //Pin diclaration for buzzer and led
long duration, inches, cm;
int indec, cmdec;
int inchconv = 147;
int cmconv = 59;
String s1, s2;
lcd.begin(8, 2); //LCD Type change it according to yours lcd
duration = pulseIn(inPin, HIGH);
inches = microsecondsToInches(duration);
indec = (duration - inches * inchconv) * 10 / inchconv;
cm = microsecondsToCentimeters(duration);
cmdec = (duration - cm * cmconv) * 10 / cmconv;
s1 = String(inches) + "." + String(indec) + "in" + " ";
s2 = String(cm) + "." + String(cmdec) + "cm" + " ";
if(cm<=15) //If some obstacle comes in this range(Mine=15cm)Buzzer starts.Change it according to your purpose.
long microsecondsToInches(long microseconds)
return microseconds / inchconv;
long microsecondsToCentimeters(long microseconds)
return microseconds / cmconv;
Download .ino file from here: https://weobserved.com/distance-measuring-device-wi.html
Step 7: If You Have Different LCD Then Modify the Program
- (1)- i am using an old 16x1 lcd which only works correctly when it will be assumed and declared as 8x2 lcd.But when you will use 16x2 display then this problem will not accrue for 16x2 display just find lcd.begin(8, 2); //LCD Type change it according to yours lcd in the code and replace (8,2) according to your display as (column,row) .let you have a 16x2 display then replace (8,2) with (16,2).and if you have 20x4 display just replace the (8,2) with (20,4).
- (2) I fixed the distance to warn me as 15cm if(cm<=15) //If some obstacle comes in this range(Mine=15cm)Buzzer starts.Change it according to your purpose.So when some obstacle will come in the range it will inform me through the alarm .And You can change it According to your purpose and need but in between (2cm-250cm).In this range it works very great.
Step 8: Final Result:-
Now You have code so just Upload it on The Arduino Board.Check The circuit and connect a 9V battery to the arduino board and enjoy.
So I hope Our this post will definitely help you to make a Distance Measuring device with automatic alarm using Arduino Board and HC-SR04 ultrasonic sensor.And this device can be used in many Application and in many place with some basic modification.
Watch it In Action Here-https://youtu.be/e9tAlh4xXSk
Please vote and keep visiting
Visit My Blog- We Observed
Participated in the
Automation Contest 2016