This ultrasonic distance alert system uses an HC-SR04 sensor to detect how close objects are and provides real-time feedback through LEDs, a buzzer, and an LCD display. The Arduino Uno continuously measures distance and categorizes it into zones: far (blue LED), approaching (yellow LED), or too close (red LED with alarm tone).
The guide includes a complete wiring diagram, parts list with recommended suppliers, and step-by-step assembly instructions. Builders will also receive the full Arduino firmware that handles sensor readings, zone detection logic, and multi-output alerts. This project is ideal for learning about ultrasonic sensing, Arduino I2C communication, and building practical proximity warning systems.
Wiring diagram

Gather all the parts
Assemble it in 3 steps
1. Wire the three LEDs with USB unplugged
Connect D2, D3 and D4 each through its own 220 ohm resistor to the long leg of the red, yellow or green, and blue or white LED, respectively. Connect each short leg to Uno GND.
2. Connect the sensor and screen
Connect both VCC pins to Uno 5V and both GND pins to Uno GND. Connect sensor TRIG to D9 and ECHO to D10. Connect LCD SDA to A4 and SCL to A5. Follow the printed pin labels.
3. Connect the passive piezo
Connect the signal lead to D5 and the ground lead to Uno GND. Check all power and ground wires before plugging in USB.
Review all connections
1. Connections between "r1" and "Arduino"
2. Connections between "red" and "Arduino"
3. Connections between "r2" and "Arduino"
4. Connections between "yellow" and "Arduino"
5. Connections between "r3" and "Arduino"
6. Connections between "blue" and "Arduino"
7. Connections between "piezo" and "Arduino"
8. Connections between "sonar" and "Arduino"
9. Connections between "lcd" and "Arduino"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
hd44780_I2Cexp lcd;
const int RED = 2, YELLOW = 3, BLUE = 4, BUZZER = 5;
const int TRIG = 9, ECHO = 10;
enum Zone { NO_ECHO, FAR, TOO_CLOSE, CLOSER, BETWEEN };
int previousZone = -1;
bool lcdReady;
void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(BUZZER, OUTPUT);
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
digitalWrite(TRIG, LOW);
lcdReady = (lcd.begin(20, 4) == 0);
}
void loop() {
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
unsigned long echoTime = pulseIn(ECHO, HIGH, 30000UL);
float distance = echoTime / 58.0;
Zone zone;
if (echoTime == 0) zone = NO_ECHO;
else if (distance >= 20) zone = FAR;
else if (distance <= 10) zone = TOO_CLOSE;
else if (distance <= 15) zone = CLOSER;
else zone = BETWEEN;
if (zone != previousZone) {
previousZone = zone;
digitalWrite(RED, zone == FAR);
digitalWrite(YELLOW, zone == CLOSER);
digitalWrite(BLUE, zone == TOO_CLOSE);
if (zone == TOO_CLOSE) tone(BUZZER, 2000);
else noTone(BUZZER);
if (lcdReady) {
lcd.clear();
lcd.setCursor(0, 0);
switch (zone) {
case FAR: lcd.print(F("The Distance is far")); break;
case TOO_CLOSE:
lcd.print(F("The OBJECT is"));
lcd.setCursor(0, 1);
lcd.print(F("TOO CLOSE"));
break;
case CLOSER: lcd.print(F("Object is Closer")); break;
case BETWEEN: lcd.print(F("Between 15 and 20 cm")); break;
case NO_ECHO: lcd.print(F("No echo")); break;
}
}
}
delay(100);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




