DIY Projects

Distance Measurement Using Ultrasonic Sensor with Arduino UNO

Statement of the Problem

In this article, we are going to see how to interface the Ultrasonic Sensor with Arduino and Monitor the distance measured by the Ultrasonics sensor using an LCD.  Various threshold levels of the distance are also measured and it will be indicated by the LED connected to the Arduino.

This article helps the reader to understand the interfacing of the Ultrasonic Sensor with Arduino. The Ultrasonic Sensor is a type of digital sensor, that emits a sound wave at a frequency higher than humans can hear, ultrasonic sensor’s function. To receive and transmit ultrasonic sound, the sensor’s transducer functions as a mic. As with many other ultrasonic sensors, ours sends a pulse and receives an echo using a single transducer.

Schematic Of Interfacing Ultrasonic Sensor And Lcd With Arduino

Connection Diagram Of Arduino With Ultrasonic And Lcd

Code For Interfacing Ultrasonic and LED With Arduino


LiquidCrystallcd(7, 6, 5, 4, 3, 2);







float INCHES;

float LED;


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

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);

  pinMode(13, OUTPUT);


  pinMode(ECHO, INPUT);


  lcd.begin(16, 2);

  lcd.print(“IN CM    :”);


  lcd.print(“IN INCHES:”);



  digitalWrite(TRIGGER, HIGH);


  digitalWrite(TRIGGER, LOW);




  // LED Indication

    if(TOTAL_DISTANCE <25){

    digitalWrite(11, HIGH);

    digitalWrite(12, LOW);

    digitalWrite(13, LOW);



    digitalWrite(11, LOW);

    digitalWrite(12, HIGH);

    digitalWrite(13, LOW);



    digitalWrite(11, LOW);

    digitalWrite(12, LOW);

    digitalWrite(13, HIGH);


  //Display Section 

  lcd.setCursor(11, 0);


  lcd.setCursor(11, 1);




  lcd.print(” “);


  lcd.print(” “);


Circuit Explanation

The above circuit consists of Arduino UNO, LCD Screen, Ultrasonic sensor, and LED. The major part of this article is about interfacing Arduino with the Ultrasonic sensor, the following content explains how to interface the sensor with Arduino and Various parts of the Project.


led explanation of the Arduino.

LCD Screen Interfacing

Ultrasonic Sensor

Ultrasonic rangefinders work based on timing how long it takes for a signal to travel from a transmitter to a receiver.

Proximity sensors are made of ultrasonic sensors. Ultrasonic sensors are less susceptible to interference from smoke, gases, and other airborne particles in proximity sensing applications than infrared (IR) sensors.Ultrasonic frequencies are those that are higher than our human hearing threshold. These are higher than 20k Hertz frequencies.


  • Supply voltage +5 V; 
  • Consumption in silent mode 2 mA; 
  • Consumption at work of 15 mA; 
  • Range of measurements – 2 to 400 cm; 
  • Effective measuring angle 15°; 
  • The dimensions are 45×20×15 mm.

An electronic device known as an ultrasonic sensor uses ultrasonic waves to measure an object’s distance from it and then transforms the sound wave reflection into electrical signals.

Ultrasonic Sensor Pinout Details

Compared to audible sound, ultrasound travels faster. The two primary parts of an ultrasonic sensor are a transmitter and a receiver.

Working Principle of Ultrasonic Sensor

The module emits an ultrasonic sound through its transmitter. If an object is in front of the ultrasonic sensor, this sound will be reflected. The receiver in the same module hears the sound that is reflected. A wave propagating at a 30° angle carries an ultrasonic transmission.

To achieve optimal accuracy, the angles measured should be at least 15°. Here, the distance to the desired object cannot be determined because of outside objects that lie within this measurement angle.

Ultrasonic sound travel time and speed measurements are used to calculate the distance.

Measured Distance = Time of Signal Travel x Speed of sound/ 2

The trigger pin must be triggered as high as possible for at least 10us to produce the ultrasonic sound. The module will then begin transmitting 8 ultrasonic burst ultrasounds at a frequency of 40 kHz. The Echo pin receiver will detect it, calculate the output time, and determine the distance.

Code Explanation

Interfacing the Arduino with an Ultrasonic Sensor and LCD Four sections

  1. The LCD header file with the corresponding pin connected to the Arduino is declared in the first section. Since LCD interfacing was employed in the project.
  1. The Second Section deals with the declaration of variable and define the pin forthe Ultrasonic Sensor. There are four pins on the ultrasonic sensor: VCC, Trigger, Echo, and Ground. Each pin of the Ultrasonic sensor is connected to the corresponding pin of the Arduino Uno board. 
  1. The ECHO Pin of the Ultrasonic sensor is connected to PIN 9 of Arduino. Similarly, the TRIGGER pin of the ultrasonic sensor to a PIN of 10.
  1. The DELAYTIME is used for setting the LCD and the PULSE_TRIGGER is used for sending pulse delay to the Trigger signal
  1. The DURATION, DISTANCE, INCHES,and LED variables are used for various calculations and display purposes in the program
  1. The third section deals with the hardware interface to the Arduino board such as LCD, LED, and ultrasonic Sensor. The void setup() with pinMode declaration for the LED output, Ultrasonic Sensor output, and LCD configuration.
  1. The next section deals with the task that Arduino going to perform. In this article, the Arduino sends a pulse to the Ultrasonic sensor continuously and receives the signal to the Arduino through an echo pin. The time taken was measured by pulseIn function and stored in the variable DURATION. 
  2. The value stored in the DURATION and converted into CM with the constant 0.01716. Similarly, the converter into INCHES with a constant of 0.3937.
  1. The below code is used to display the various ranges of distance using LED indicator. 
  1. The Fourth section is the final stage of the article, the Display section. The display section displays the result in the LCD. The various variables calculated by the Arduino will be sent to the LCD using the following code. The SetCursor function is used for the starting position and printfunction is used for displaying the variable on the LCD screen


The following images show the various stages of distance detected by the Ultrasonic sensor and display the result on an LCD screen. At the same time, the range detection is indicated by the LED. 

Detection Range Between 50 To 75 cm

Detection Range Between 25 To 50 cm

Detection Range Below 25 cm

By doing the above exercise the reader can BE able to interface the Ultrasonic Sensor and LCD with Arduino UNO

Embarking on the Ultrasonic Sensor and LCD journey with Arduino was incredible. From connecting wires to seeing distance magically displayed, it felt like diving into a tech adventure. This hands-on learning sparked curiosity for more Arduino magic!

Sundareswaran Iyalunaidu

With over 24 years of dedicated experience, I am a seasoned professional specializing in the commissioning, maintenance, and installation of Electrical, Instrumentation and Control systems. My expertise extends across a spectrum of industries, including Power stations, Oil and Gas, Aluminium, Utilities, Steel and Continuous process industries. Tweet me @sundareshinfohe

Related Articles

Back to top button

Adblock Detected

We Noticed You're Using an Ad Blocker Hi there! We understand that ads can be annoying, but they help support our website and allow us to continue providing you with high-quality content. Please consider whitelisting our site or disabling your ad blocker while you visit. Your support means a lot to us! Thank you for understanding!