# DISTANCE MEASUREMENT AND LCD DISPLAY BY ARDUINO

3,781

22

1

## Introduction: DISTANCE MEASUREMENT AND LCD DISPLAY BY ARDUINO

Ultrasonic sensors are great tools to measure
distance without actual contact and used at several places like water level measurement, distance measurement etc. This is an efficient way to measure small distances precisely. In this project we have used an Ultrasonic Sensor to determine the distance of an obstacle from the sensor. Basic principal of ultrasonic distance measurement is based on ECHO. When sound waves are transmitted in environment then waves are return back to origin as ECHO after striking on the obstacle. So we only need to calculate the travelling time of both sounds means outgoing time and returning time to origin after striking on the obstacle. As speed of the sound is known to us, after some calculation we can calculate the distance.

## Step 1: Geting Started

Components Used

1. 1.Arduino uno board
2. Ultrasonic sensor Module
3. 16x2 LCD Scale
5. 9 volt battery
6. Connecting wire

Ultrasonic sensor HC-SR04 is used
here to measure distance in range of 2cm-400cm with accuracy of 3mm. The sensor module consists of ultrasonic transmitter, receiver and the control circuit. The working principle of ultrasonic sensor is as follows:

High level signal is sent for 10us using Trigger.The module sends eight 40 KHz signals automatically, and then detects whether pulse is received or not.If the signal is received, then it is through high level. The time of high duration is the time gap between sending and receiving the signal.Distance= (Time x Speed of Sound in Air (340 m/s))/2

## Step 2: CIRCUIT AND CONECTION for SENSOR

In circuit connections Ultrasonic sensor module’s
trigger- 8

echo-7

vcc-+5v

GRD-ground

First of all we need to trigger the ultrasonic sensor module to transmit signal by using arduino and then wait for receive ECHO. Arduino reads the time between triggering and Received ECHO. We know that speed of sound is around 340m/s. so we can calculate distance by using given formula:

Distance= (travel time/2) * speed of sound

Where speed of sound around 340m per second.

## Step 3: CIRCUIT AND CONNECTION FOR DISPLAY MODULE

Now we need to connect the lcd display to the arduino, i chose to use a
breadboard to do this but if you want to, you can connect straight to arduino, ill explain why i chose the breadboard method in the lat step :)

Make the following connections

*LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11

* LCD D4 pin to digital pin 5

* LCD D5 pin to digital pin 4

* LCD D6 pin to digital pin 3

* LCD D7 pin to digital pin 2

* LCD R/W pin to ground

* LCD VSS pin to ground

* LCD VCC pin to 5V

(10K resistor: ends to +5V and ground wiper(center) to LCD VO pin (pin 3))

Because we will only be writing, pin 5 will be dropped to ground to show that there will be no reading. For those who wish to use the backlight, connect LCD pin 16 to GND and LCD pin 15 to +4.2V.

Connect one side of the potentiometer to Arduino GND, the opposite to Arduino 5v, and the center to LCD pin 3.

## Step 4: NOW THE SIMPLE CODING...

you need a Library for lcd module

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int trigpin = 8;

const int echopin = 7;

long duration;

long distance1 ;

void setup()

{

pinMode(trigpin,OUTPUT);

pinMode(echopin,INPUT);

Serial.begin(9600);

}

void loop()

{

digitalWrite(trigpin,HIGH);

digitalWrite(trigpin,LOW);

duration=pulseIn(echopin,HIGH);

distance1=(duration/2)/29.1;

{ Serial.print("distance :");

Serial.println(distance1 "cm" );

delay(1000);

}

// include the library code:

// initialize the library with the numbers of the interface pins

// set up the LCD's number of columns and rows:

lcd.begin(16, 2); // Print a message to the LCD.

lcd.setCursor(0,0);

lcd.print("distance is.."); // Print a message to the LCD.

lcd.setCursor(1,1);

lcd.print(distance1 "cm");

}