Community project

Ultrasonic Distance Alert System

Photo of Ultrasonic Distance Alert System
Generated with AI

Killy de la Cruz

Published November 23, 2026

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

Wiring diagram for Ultrasonic Distance Alert System
Loading diagram…

Gather all the parts

QtyComponent
1

LED

Red

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

LED

Yellow or Green

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

LED

Blue or White

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

HC-SR04

HC-SR04 ultrasonic distance sensor module with separate 40 kHz transmitter and receiver transducers, measuring 2 to 400 cm. A 10 us pulse on TRIG starts a measurement and ECHO stays high for the echo's round-trip time. This HC-SR04+ board runs from 3.3 V or 5 V.

1

Piezo Buzzer

Small passive piezo buzzer (TDK PS1240) for beeps, tones and alerts. It has no built-in oscillator, so drive one lead with a 3-30 V square wave from a microcontroller pin using tone() or PWM and connect the other lead to ground. It is loudest around 4 kHz and works from about 2 to 10 kHz; driving both leads in antiphase roughly doubles the volume.

1

I2C 20x4 Arduino LCD Display Module

20x4 character LCD with I2C interface, white text on blue backlight, adjustable contrast. Operates at 5V or 3.3V; reduces pin usage to 2 lines (SDA/SCL).

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"

Functionr1Arduino
digitalP1GPIO 2

2. Connections between "red" and "Arduino"

FunctionredArduino
digitalANODE → Resistor P2EXT
groundGNDGND

3. Connections between "r2" and "Arduino"

Functionr2Arduino
digitalP1GPIO 3

4. Connections between "yellow" and "Arduino"

FunctionyellowArduino
digitalANODE → Resistor P2EXT
groundGNDGND

5. Connections between "r3" and "Arduino"

Functionr3Arduino
digitalP1GPIO 4

6. Connections between "blue" and "Arduino"

FunctionblueArduino
digitalANODE → Resistor P2EXT
groundGNDGND

7. Connections between "piezo" and "Arduino"

FunctionpiezoArduino
pwmSIGGPIO 5
groundGNDGND

8. Connections between "sonar" and "Arduino"

FunctionsonarArduino
digitalTRIGGPIO 9
digitalECHOGPIO 10
powerVCC5V
groundGNDGND

9. Connections between "lcd" and "Arduino"

FunctionlcdArduino
powerVCC5V
groundGNDGND
i2cSDAGPIO 18
i2cSCLGPIO 19

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.

Open in Schematik