Introduction: LCD Distance Measurement Using Arduino

And after posting up a few robotic tutorials, I decided to move in more detail about sensors. To start of with I choose an ultrasonic sensor and an Arduino as the micro-controller.

This Instructable is purely for thosewho are getting started with Arduino and an Ultrasonic sensor. In this instructable I'm going to show you, How to make a distance measuring device, using an Arduino and an Ultrasonic sensor, the distance value will be displayed on an LCD screen.

I have tried to keep this instructable as simple as possible, so everyone will be able to keep up.

So lets get started ...

Step 1: Getting Started

The following knowledge are required for better understanding of this project :-

Arduino uno :-

Arduino is a pocket size computer that are used to control to control the physical world which cannot be performed by your desktop.It takes input from your input device such as sensors,switches and many more accordingly it controls the output device such as motors....etc

The other application of Arduino is :

- Programmable light displays that respond to music or human interaction

- Robots that use information from sensors to navigate or perform other tasks

- Unique, customizable controllers and interfaces for music, gaming, and more

- Connecting real world objects to the Internet (twitter is especially popular)

- Anything interactive- Automating and prototyping

Ultrasonic sensor :

The very main application of sensor is measuring distance of an obstacle. It will work in any lighting conditions, thus it finds a wide space in night vision sensors. In this instructables I have used it to detect obstacles it has four pins (VCC , Trig , Echo , Gnd) and there connection have been shown in the further explanation. The best example for its application is in the car's assisting parking system, where car exceeds a minimum distance towards the obstacle it alerts you.

So enough of theory lets get into construction business.

Step 2: TOOLS REQUIRED :

The list of components for the project is quite simple, all you need to replicate the project is -

  • Arduino UNO.
  • Breadboard.
  • Jumper Wires.
  • Ultrasonic sensor.
  • 16x2 LCD.

Once you have all of the components its time to get started. No soldering skills required as the complete project is assembled on a breadboard.

Step 3: BUILDING ELECTRONICS :-

The connection to the ultrasonic sensor and the Arduino goes as follows :

    Ultrasonic sensor connection :

    • VCC pin - 5V pin of Arduino
    • GND pin - Ground pin of Arduino
    • TRIG pin - Digital pin 12 of Arduino
    • ECHO pin - Digital pin 13 of Arduino

      LCD 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
      • 10K resistor:
      • ends to +5V and ground

      After getting the hardware ready its time to test it, so lets upload the code to the Arduino.

      Step 4: CODING TIME

      Time to upload the code, the code or program can be found in the attachments, download it or copy it and paste it in the Arduino IDE. The Arduino IDE can be found in the downloads section of the Arduino Home Page.

      If you are running windows you need to install the drivers which can be found in the root of the Arduino IDE directory, feel free to modify the program or change it as you like.

      #include <liquidcrystal.h>//Load Liquid Crystal Library
      
      LiquidCrystal LCD(11,10,9,2,3,4,5);  //Create Liquid Crystal Object called LCD</liquidcrystal.h>
      
      #define trigPin 13 //Sensor Echo pin connected to Arduino pin 13
      #define echoPin 12 //Sensor Trip pin connected to Arduino pin 
      
      void setup() 
      {  
        pinMode(trigPin, OUTPUT);
        pinMode(echoPin, INPUT);
        
        LCD.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD
        LCD.setCursor(0,0);  //Set LCD cursor to upper left corner, column 0, row 0
        LCD.print("Target Distance:");  //Print Message on First Row
      }
      
      void loop() {
        long duration, distance;
        digitalWrite(trigPin, LOW);
        delayMicroseconds(2);
        digitalWrite(trigPin, HIGH);
        delayMicroseconds(10);
        digitalWrite(trigPin, LOW);
        duration = pulseIn(echoPin, HIGH);
        distance = (duration/2) / 29.1;
      
        LCD.setCursor(0,1);  //Set cursor to first column of second row
        LCD.print("                "); //Print blanks to clear the row
        LCD.setCursor(0,1);   //Set Cursor again to first column of second row
        LCD.print(distance); //Print measured distance
        LCD.print(" cm");  //Print your units.
        delay(250); //pause to let things settle
      }
      

      If you face any problems feel free to PM me and I will be glad to help you out.