Arduino Maker Series Under 1000: Ultrasonic Distance Measurer with LCD Display
Arduino Maker Series Under 1000: Ultrasonic Distance Measurer with LCD Display
Welcome to the Arduino Maker Series Under 1000! 📏 Today, we are building a practical and fun project: an Ultrasonic Distance Measurer that displays distance on an I2C LCD. This project is ideal for beginners and makers looking to learn about ultrasonic sensors, LCDs, Arduino programming, and basic electronics.
Table of Contents
- Introduction
- Required Hardware
- Arduino IDE Setup
- Wiring the Components
- Arduino Code
- How It Works
- Testing Your Project
- Advanced Modifications
- Common Issues and Troubleshooting
- Learning Insights
- Conclusion
1. Introduction
In this project, we will use the HC-SR04 ultrasonic sensor to measure the distance of objects in centimeters. The measured distance is displayed on a 16x2 I2C LCD. Optionally, we can add a buzzer to alert if an object comes too close. By the end of this project, you will understand:
- How ultrasonic sensors measure distance using sound waves
- How to display data on an I2C LCD
- Arduino programming basics including pulse timing and conditional statements
- Basic troubleshooting and debugging techniques
2. Required Hardware
- Arduino Uno (or compatible) – ~₹500
- HC-SR04 Ultrasonic Sensor – ₹150
- 16x2 I2C LCD Module – ₹200
- Jumper wires & Breadboard – ₹100
- Optional: Buzzer for alerts – ₹50
- 5V Power Supply / USB – ₹100
3. Arduino IDE Setup
- Install the latest Arduino IDE from the official website.
- Connect the Arduino Uno to your PC using a USB cable.
- Go to Tools > Board and select Arduino Uno.
- Go to Tools > Port and select the correct COM port.
- Install the LiquidCrystal_I2C library via Library Manager if not already installed.
4. Wiring the Components
Follow the steps below to wire your components correctly. Accurate wiring is crucial for sensor accuracy and LCD display:
- HC-SR04 Ultrasonic Sensor: VCC → 5V, GND → GND, Trig → D9, Echo → D10
- 16x2 I2C LCD: VCC → 5V, GND → GND, SDA → A4, SCL → A5
- Buzzer (Optional): Positive → D7, GND → GND
Make sure to use a breadboard for secure connections. Double-check SDA and SCL lines, as swapping them can prevent the LCD from initializing.
5. Arduino Code
Upload this code to your Arduino. This code measures distance using the ultrasonic sensor, displays it on the LCD, and optionally triggers a buzzer when objects are too close:
#include#include const int trigPin = 9; const int echoPin = 10; const int buzzer = 7; // Optional LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust I2C address if needed void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(buzzer, OUTPUT); lcd.init(); lcd.backlight(); } void loop() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin, HIGH); long distance = duration * 0.034 / 2; // Distance in cm lcd.setCursor(0,0); lcd.print("Distance: "); // Clear old value lcd.setCursor(10,0); lcd.print(distance); lcd.print("cm"); // Optional buzzer alert if(distance < 10){ digitalWrite(buzzer, HIGH); lcd.setCursor(0,1); lcd.print("Too Close! "); } else { digitalWrite(buzzer, LOW); lcd.setCursor(0,1); lcd.print(" "); // Clear second line } delay(500); }
6. How It Works
The HC-SR04 ultrasonic sensor emits sound waves at 40kHz when the trig pin is set HIGH for 10 microseconds. These waves travel until they hit an object and reflect back. The echo pin goes HIGH for the duration of the return trip. Arduino calculates the distance using the formula:
distance (cm) = duration * 0.034 / 2
The LCD displays this distance in real-time. If the distance is below a safety threshold (10 cm in this code), a buzzer alerts the user. This is useful for proximity alerts or simple obstacle detection systems.
7. Testing Your Project
- Upload the code to your Arduino.
- Open the Serial Monitor to confirm the sensor is reading values (optional).
- Observe the LCD displaying the distance of objects in front of the sensor.
- Place an object closer than 10 cm to test the buzzer alert.
- Move objects at different distances and verify that readings are accurate and responsive.
8. Advanced Modifications
- Add multiple ultrasonic sensors for 360° obstacle detection in robotics.
- Send distance data to a mobile app or web dashboard via Wi-Fi using ESP8266 or wifi boards.
- Use OLED displays with graphics for more advanced visualization.
- Combine with servo motors to create a smart parking assistant.
- Implement sound alerts with variable frequency based on distance (closer = faster beeping).
9. Common Issues and Troubleshooting
- Distance always reads 0 or max: Check wiring of Trig and Echo pins.
- LCD not displaying: Verify SDA/SCL connections and correct I2C address.
- Incorrect distance: Keep sensor perpendicular to the object and avoid soft/angled surfaces.
- Buzzer always ON or never ON: Verify threshold value and wiring.
- Serial monitor not showing values: Ensure correct COM port and baud rate (9600).
10. Learning Insights
- Hands-on experience with ultrasonic distance measurement.
- Learn to interface I2C devices like LCDs with Arduino.
- Understand pulse timing and distance calculation in real-world units.
- Develop troubleshooting and debugging skills for sensors and displays.
- Learn basic alert systems with buzzer or LED notifications.
11. Conclusion
This is a fun and educational project in the Arduino Maker Series Under 1000. Your Ultrasonic Distance Measurer with LCD is now ready! It’s practical, low-cost, and perfect for beginners and hobbyists. You can extend this project into robotic cars, parking sensors, or smart home alert systems.
By Kaushal Haladi
Comments
Post a Comment