Distance measurement Project
Arduino distance measurement project has the number of applications that require to measure distance between two moving or stationary objects like water level measurement, distance measurement etc.
Ultrasonic sensors like HC-SR04 are widely used to measure the distance without actual contact.
Components Used:
- Arduino UNO
- 16×2 LCD
- HC-SR04 Ultrasonic Distance Sensor
- Breadboard
- Connecting wires
Ultrasonic sensor HC-SR04
Interfacing HC-SR04 to a microcontroller is very much easy. trig pin is used to trigger an ultrasonic sensor and then “listen” for the echo pulse. The sensor measures the time required for the echo return, and returns this to the microcontroller as a variable pulse width via the echo pin.
Key Features:
- Precise, non-contact distance measurements
- Range 2 cm to 4 m range
- work in any lighting condition
- Requires just two microcontroller I/O pin
- Power requirements: +5 VDC;
Timing Diagram
The module works on the natural phenomenon of ECHO of sound. A high pulse is sent for about 10us to trigger the module. After which the module sends 8 cycles of 40 KHz ultrasound signal through transmitter and checks its echo received at receiver. By using this time span triggering pulse and echo you can calculate the distance by using formula as
Distance = (time x Speed)/ 2
Where speed= 340m/s (speed of sound wave or ultrasonic signal)
Here we have divided the product of speed and time by 2 because the time is the total time it took to reach the obstacle and return back.
Circuit Diagram (Arduino Distance measurement Project)
In-circuit connection
Ultrasonic sensor module’s
- “trigger” to A4of arduino
- “echo” to A5of arduino
- Vcc to 5V and
- Gnd to Ground of Arduino
16×2 LCD connected in 4-bit mode as
- RS – pin 2
- En–pin 3
- D4-D7 –pin 4- pin7
- RW, LED-, Vss– GND and Vdd, LED+ – 5V
See also: Fritzing Software tool for Electronics Circuit design without Hardware
Code:
#include <LiquidCrystal.h>
#define trigger 18
#define echo 19
float time=0,distance=0;
LiquidCrystallcd(2,3,4,5,6,7);
void setup()
{
lcd.begin(16,2);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
lcd.setCursor(0,1);
delay(2000);
lcd.clear();
delay(1000);
}
void loop()
{
lcd.clear();
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;
lcd.clear();
lcd.print(“Distance:”);
lcd.print(distance);
lcd.print(“cm”);
lcd.setCursor(0,1);
lcd.print(“Distance:”);
lcd.print(distance/100);
lcd.print(“m”);
delay(1000);
}
Results:
See also: Arduino Traffic Light Controller || IoT Project
Let us know what you think about Arduino distance measurement in the comment section below, if you have new ideas on distance measurement using ultrasonic sensor and Arduino, please let us know.
If you like this post subscribe to our YouTube Channel for IoT video Tutorials.
Greetings! Very useful advice in this particular post! It is the little changes which will make the most significant changes. Many thanks for sharing!
Thank you for your appreciation. Sorry for delayed in reply.
Hey, I think your blog might be having browser compatibility issues. When I look at your blog site in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, superb blog!
Thank you for your appreciation. Sorry for delayed in reply. I will work on compatibility issue.
Awesome blog you have here but I was wanting to know if you knew of any message boards that cover the same topics talked about in this article? I’d really love to be a part of online community where I can get feedback from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Kudos!|
Thank you for your appreciation. Sorry for delayed in reply. You can check Hackstar.io its good community.
Everything typed was actually very reasonable. But, what about this? suppose you typed a catchier title? I am not saying your content isn’t good, however suppose you added a title to possibly get people’s attention? I mean %BLOG_TITLE% is a little boring. You might glance at Yahoo’s front page and watch how they create article headlines to get people to open the links. You might add a video or a related pic or two to grab people interested about everything’ve written. Just my opinion, it could bring your blog a little livelier.
Thank you for your suggestion. Sorry for delayed in reply. I am very thankful that you posted such valuable and informative comment . Thank you , I will work on this.
We stumbled over here from a different web address and thought I might check things out. I like what I see so now i am following you. Look forward to looking at your web page again.|
Thank you for your appreciation. Sorry for delayed in reply.
These are actually great ideas in regarding blogging. You have touched some pleasant points here. Any way keep up wrinting.
Thank you for your appreciation. Sorry for delayed in reply.
Normally I don’t read post on blogs, but I wish to say that this write-up very compelled me to check out and do it! Your writing style has been amazed me. Thanks, quite great post.|
Thank you for your appreciation. Sorry for delayed in reply.
Nice post. I was checking constantly this weblog and I’m inspired! Very useful information specially the ultimate part 🙂 I care for such info a lot. I was seeking this certain info for a very long time. Thanks and best of luck.
Thank you for your appreciation. Sorry for delayed in reply.
My partner and I stumbled over here different web address and thought I might check things out. I like what I see so now i’m following you. Look forward to looking over your web page again.|
Thank you for your appreciation. Sorry for delayed in reply.
naturally like your web-site but you have to take a look at the spelling on several of your posts. A number of them are rife with spelling issues and I find it very troublesome to inform the truth then again I’ll certainly come again again.
Thank you for your suggestion. Sorry for delayed in reply. I will work on your suggestion , sorry for trouble you faced with this issue.
There’s certainly a lot to know about this topic. I like all the points you have made.