Smart Ultrasonic Distance Finder Using 3 Ultrasonic Sensors

Hey geeks, welcome back to Techatronic. Are you searching for a distance finder project using an ultrasonic sensor? if so then this article is for you. In this, we are going to learn how you can make your own smart ultrasonic distance finder using three ultrasonic sensors. For making this project we are using three HC-SR04 ultrasonic sensors and an Arduino UNO development board. Do you guys know how an ultrasonic sensor works with the Arduino? Well, we explain it in our previous articles. We are displaying the real-time values of the distance captured by the sensors on a 16×2 LCD. This project works similarly to the Ultrasonic Range Finder Using Arduino and LCD. If you like this project then also view more such cool projects on Arduino. Please make the circuit properly and then upload the given code.

Working of the Project

The project has three HC-SR04 ultrasonic sensors which can measure the distance in three different directions. If one of the sensors detects that the distance from the obstacle is less than the given value then the corresponding LED will glow. There are three LEDs, one for each sensor. The measured distance is displayed on a 16×2 LCD in centimeters. The ultrasonic sensors work on the principle of SONAR technology in which ultrasonic rays are transmitted and received to calculate the distance between the body and the obstacle. You can also view the values of the distance on the serial monitor screen. Open the serial monitor as shown below.  Also, check Smart Blind Stick made by us.

ultrasonic distance finder

Components Required

  • Arduino UNO
  • Three HC-SR04 ultrasonic sensors
  • Jumper wires
  • Breadboard
  • Three LEDs
  • USB cable for uploading the code
  • Resistors 220-ohm
  • 10K potentiometer
  • 16×2 LCD display

Circuit Diagram for the Project

ultrasonic distance finder

Arduino UNOUltrasonic Sensor 1
( +5V )VCC
D9 PinTrig Pin
D10 PinEcho Pin
Arduino UNOUltrasonic Sensor 2
( +5V ) VCC
D7 PinTrig Pin
D8 PinEcho Pin
Arduino UNOUltrasonic Sensor 3
( +5V ) VCC
D5 PinTrig Pin
D6 PinEcho Pin
Arduino UNO16*2 LCD10K Potentiometer
GND VSS (Ground)Terminal 1
+5VVDD ( +5V )Terminal 3
 VEE ( Contrast )Terminal 2
A0 PinRS ( Register Select ) 
GNDRW ( Read\Write ) 
A1 PinE ( Enable ) 
A2 PinD4 
A3 PinD5 
A4 PinD6 
A5 PinD7 
Arduino LED RLED GLED B220 Ohm Resistor
D12 PinAnode Terminal   
D11 Pin Anode Terminal  
D3 Pin  Anode Terminal 
GND   Terminal 1
 Cathode TerminalCathode TerminalCathode TerminalTerminal 2

Connect the VCC and GND pins of all three sensors with the 5-volts and GND pins of the Arduino. Attach the TRIG and ECHO pins of the third ultrasonic sensor with the digital-5 and digital-6 pins of the Arduino. Join the TRIG and ECHO pins of the second ultrasonic sensor to the digital-7 and digital-8 pins of the Arduino. Connect the TRIG and ECHO pins of the first ultrasonic sensor with the digital-9 and digital-10 pins of the Arduino. Join the positive legs of all the three LEDs with the digital-3, digital-11, and digital-12 pins of the Arduino and the negative legs with the GND pin of Arduino through a 220-ohm resistor. Connect the LCD pins with the Arduino as shown above or take help from our article on Interfacing of a 16×2 LCD with Arduino.

Code for the Project

NOTE: Please upload the code given below to the Arduino. You have to install <LiquidCrystal.h> library first. Check how to install a zip library to the Arduino.

 #include "LiquidCrystal.h"  
 LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);  
 const int trigPin1 = 9;  
 const int echoPin1 = 10;  
 const int trigPin2 = 5;  
 const int echoPin2 = 6;  
 const int trigPin3 = 7;  
 const int echoPin3 = 8;  
 long duration1;  
 long duration2;  
 long duration3;  
 int distanceCm1, distanceInch1;  
 int distanceCm2, distanceInch2;  
 int distanceCm3, distanceInch3;  
 void setup() {  
 pinMode(trigPin1, OUTPUT);  
 pinMode(echoPin1, INPUT);  
 pinMode(trigPin2, OUTPUT);  
 pinMode(echoPin2, INPUT);  
 pinMode(trigPin3, OUTPUT);  
 pinMode(echoPin3, INPUT);  
 void loop()  
 digitalWrite(trigPin1, LOW);  
 digitalWrite(trigPin1, HIGH);  
 digitalWrite(trigPin1, LOW);  
 duration1 = pulseIn(echoPin1, HIGH);  
 digitalWrite(trigPin2, LOW);  
 digitalWrite(trigPin2, HIGH);  
 digitalWrite(trigPin2, LOW);  
 duration2 = pulseIn(echoPin2, HIGH);  
 digitalWrite(trigPin3, LOW);  
 digitalWrite(trigPin3, HIGH);  
 digitalWrite(trigPin3, LOW);  
 duration3 = pulseIn(echoPin3, HIGH);  
 distanceCm1= duration1*0.034/2;  
 distanceInch1 = duration1*0.0133/2;  
 distanceCm2= duration2*0.034/2;  
 distanceInch2 = duration2*0.0133/2;  
 distanceCm3= duration3*0.034/2;  
 distanceInch3 = duration3*0.0133/2;  
 Serial.print("Distance1: ");  
  lcd.print("Ultrasonic1 ");  
 Serial.print("Distance2: ");  
  lcd.print("U2 ");  
 Serial.print("Distance3: ");  
  lcd.print("U3 ");  
 if(distanceCm1 <15)  
   digitalWrite(3,HIGH); // LED ON  
 if(distanceCm1 >15)  
   digitalWrite(3,LOW);  // LED OFF  
 if(distanceCm2 <15)  
   digitalWrite(12,HIGH); // LED ON  
 if(distanceCm2 >15)  
   digitalWrite(12,LOW); // LED OFF  
 if(distanceCm3 <15)  
   digitalWrite(11,HIGH); // LED ON  
 if(distanceCm3 >15)   
   digitalWrite(11,LOW); // LED OFF  

We hope that you understand the project completely and please try to make it now on your own. Use the comments section below to inform us about the errors you encountered if any. Also, check out more tutorials on Arduino and Raspberry Pi made by us.


Spread the love, Share this post with friends

One thought on “Smart Ultrasonic Distance Finder Using 3 Ultrasonic Sensors

Leave a Reply

Your email address will not be published.