Using Distance Sensor with 16x2 LCD Display
In here I am going to show you how to make print distance using distance Sensor.
So we have to need distance sensor.
And LCD display with I2C module
Thank you
Project Overview
This project demonstrates how to measure distance using an ultrasonic sensor and display the results in real-time on a 16x2 Character LCD. By using an I2C interface for the LCD, we significantly reduce the number of wires required, making the project cleaner and easier to build.
Hardware Components
- Arduino UNO: The brain of the project.
- HC-SR04 Ultrasonic Sensor: Uses sonar to determine the distance to an object.
- 16x2 LCD with I2C Module: Displays the distance data. The I2C module (PCF8574) allows the LCD to be controlled using only 2 data pins (SDA and SCL).
How It Works
- Distance Sensing: The HC-SR04 sensor works by sending an ultrasonic pulse (Trig pin) and measuring the time it takes for the echo to bounce back (Echo pin). The Arduino calculates the distance using the speed of sound formula:
Distance = (Time * 0.034) / 2. - I2C Communication: Instead of using 6-10 digital pins to control the LCD, the I2C backpack communicates with the Arduino over the I2C bus. This requires the
LiquidCrystal_I2Clibrary. - Display Logic: The Arduino continuously updates the LCD with the latest distance value. If the object moves, the numbers on the screen change instantly.
Wiring and Setup
- LCD I2C: VCC to 5V, GND to GND, SDA to A4 (on Uno), SCL to A5 (on Uno).
- HC-SR04: VCC to 5V, GND to GND, Trig to Pin 9, Echo to Pin 10.
- I2C Address: Most I2C LCDs use the address
0x27or0x3F. If your screen is blank, you may need to adjust the contrast potentiometer on the back of the I2C module.