Measuring Distance and displaying it on LCD
SUBSCRIBE
How it works?
Hello,
This project is basically, based on displaying the distance on a LCD display with the help of an HC-SRO4 ultrasonic sensor . The HC-SRO4 Ultrasonic distance sensor consist of two Ultrasonic transducers . In which one acts as a Transmitter and other as a Receiver . Transmitter converts electrical signals into 40KHz ultrasonic sound pulses. the receiver listens for the transmitted pulse (when bounces back) .If it receives them it produces an output pulse whose width can be used to determine the distance the pulse travelled .
This sensor offers an excellent range of 2 to 400cm with an accuracy of 3mm . and luckily it operates on 5 volts , so we can directly hooked to an Arduino Uno or any other 5V logic microcontrollers.
How to connect?
Hello,
In this project I am going to show you how to connect the HC-SRO4 with an "Arduino Uno" and print the distance on LCD display(16*2)
First of all connect the LCD display with Arduino Uno.
Now connect the HC-SRO4 with Arduino too.
*you can use any digital pin in connection. As per your choice .
*In this project I have used pins (12, 11, 10, 9, 5, 4, 3, 2).
Connecting LCD with Arduino-:
VSS pin to GND
VDD/VCC pin to +5volt
VO pin through 1k resistor to ground
RS pin to Digital pin(12)
RW pin to GND
E pin to Digital pin(11)
D4 pin to Digital pin(5)
D5 pin to Digital pin(4)
D6 pin to Digital pin(3)
D7 pin to Digital pin(2)
A pin to +5volt
K pin to GND
Connecting HC-SRO4 with Arduino-:
VCC pin to +5 volts
TRIGGER pin to Digital pin (9)
ECHO pin to Digital pin (10)
GND pin to GND
Arduino Code
#include<NewPing.h>
#include<LiquidCrystal.h>
int contrast=0;
LiquidCrystal lcd (12,11,5,4,3,2); //RS, ENABLE, d4, d5, d6, d7
const int trigPin=9;
const int echoPin=10;
long duration;
int distance;
void setup() {
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
lcd.begin(16,2);// interface of the lCD display
}
void loop() {
//trigerpin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);// measure the response form the HC-SRO4 Echo Pin
distance = duration*0.034/2;// use 340 m/s as speed of sound
lcd.setCursor(0,0);// prints "Distance" on the first row of lcd
lcd.print("Distance: ");
lcd.print(distance);
lcd.print(" cm");
delay(2000);//delay of 2seconds
}
For any queries contact me on -:tombriddle28@gmail.com
YouTube Channel-: Omnific{If this post helps you please do subscribe my
YouTube channel too ,It's only a click for you but it means a lot to me.}




Comments