Table of Contents
Introduction
In this article, we will discuss how Ultrasonic Range Finder can be made using Arduino and 16X2 LCD display. If you are new in this field and want to know more about Arduino, please check out here.
Arduino is a development board that uses ATmega328p IC for its functioning. you can find many types of Arduino boards in the market but we use Arduino UNO for this project.
The ultrasonic sensor used for this project is HC SR04 which has four pins, two for power (VCC and GND) and the other two for output(TRIG and ECHO).
this project can be mention in the mini-project for ECE students. If you want to learn more cool and amazing projects on ultrasonic sensors then.
The distance between the sensor and obstacle is calculated and displayed on LCD. Learn how to make Ultrasonic Range Finder by just following the easy procedure as discussed below.
How Does it Work?
- The Ultrasonic Range Finder uses an ultrasonic sensor(HC SR04) to find the position of the obstacle with the use of Arduino and displays the measured distance on LCD.
- The ultrasonic sensor is based on the working of SONAR, it sends ultrasound signals and receives them back to identify if the forward path is clear or not.
- We use the I2C module here with the 16X2 LCD alphanumeric display and connect it with the Arduino.
- Whenever you put some obstacle in front of the ultrasonic sensor it measures the distance with the help of the Arduino code we provide to it and displays the distance on LCD.
- The value of distance changes according to the position of the obstacle and in this way, it will continue to work.
- All the details of the project are given below and you can follow them to make your own Ultrasonic Range Finder.
Also, check Arduino Radar Using Ultrasonic Sensor.
Components Required
- Arduino UNO
- Breadboard
- DC Adapter to Power the Arduino
- Jumper Wires
- USB cable for uploading code into Arduino UNO
- HC SR04 Ultrasonic Sensor
- 16X2 LCD Display
- I2C LCD Module
Circuit Diagram
Components Table
Arduino UNO | Ultrasonic Sensor |
( +5V ) | VCC |
GND | GND |
D9 Pin | Trig Pin |
D10 Pin | Echo Pin |
Arduino UNO | I2C Module |
( +5V ) | VCC |
GND | GND |
A4 Pin ( SDA ) | SDA Pin |
A5 Pin ( SCL ) | SCL Pin |
16*2 LCD Display | I2C Module |
16 Pin connect | 16 Pin connect |
Make the connections according to the given diagram using jumper wires.
- Connect the positive(VCC) 5 volts supply and ground from Arduino to the positive and negative rails of the breadboard.
- ultrasonic range finder project connection gave here. Connect Arduino digital pins number 9 and 10 to the Trig and Echo pins of the Ultrasonic sensor.
- SCL and SDA pins of the I2C module are connected to the analog 5 and 4 pins of Arduino.
- Attach the I2C module with the LCD as shown above.
- Connect the positive(VCC) of the ultrasonic sensor and I2C module to the positive rail on the breadboard and negative(GND) to the negative of the breadboard.
- After completing the circuit upload the given code to the Arduino and if any error occurs do inform us in the comment section.
Sponsor
We use NEXT PCB to make PCB in our all projects & Products.
NextPCB is a real manufacturer of PCB and PCB assembly in Global, which offers turnkey PCB manufacturing & assembly services.
NextPCB runs three factories specialized in PCB Prototype, PCB Mass Production, and PCB Assembly, equipped with AOI, X-Ray Testing & Multiple functional testing. So NextPCB could provide quick-turn service without a broker. And you could get high-quality PCB and PCB assembly at a competitive price.
You need to upload your design and your PCB will be ready in the easiest way.
Code of the Project
Upload the given code into the Arduino with the help of the Arduino ide application. You must need to install the libraries <LiquidCrystal_I2C.h> and <Wire.h>.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
void setup()
{
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
Serial.println("Distance: ");
Serial.println(distanceCm);
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance" on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print(" cm ");
}
Thanks for visiting, hope you understand the project well. Please do check out more Arduino tutorials.