Calde, Flores is a distance monitoring system that uses an ultrasonic sensor to detect how far an object is from the device, then displays the measurement on an LCD screen and indicates the distance range with colored LEDs and audio feedback. The system triggers a buzzer and lights up different LEDs based on whether an object is far (green), medium (yellow), or close (red).
This guide provides a complete parts list, wiring diagram, and step-by-step assembly instructions for building the project on an Arduino Uno. The included firmware handles sensor readings, LCD display updates, and LED/buzzer control logic. Builders will learn how to integrate an I2C LCD display, work with ultrasonic distance sensing, and coordinate multiple output indicators.
Wiring diagram

Gather all the parts
Assemble it in 5 steps
1. Prepare the parts with USB unplugged
Use the Uno R3, HC-SR04, 20x4 I2C LCD, passive piezo buzzer, red/yellow/blue LEDs, and three 330 ohm quarter-watt resistors. Green can replace yellow and white can replace blue. Use jumper wires for the connections.
- Unplug USB before changing wires. Every LED needs its own resistor or it and the Uno output can be damaged.
2. Connect the distance sensor
Connect VCC to Uno 5V and GND to Uno GND. Connect TRIG to D7 (measurement trigger), and ECHO to D8 (distance timing). Read the printed pin labels, not the apparent left-to-right position.
3. Connect the LCD
Connect VCC to 5V, GND to GND, SDA to A4 (data), and SCL to A5 (clock). The firmware automatically finds the I2C backpack address and pin mapping.
- If the backlight lights but text is invisible, gently turn the small contrast adjustment on the back of the LCD.
4. Connect the three indicator lights
Connect D2 through r_red to the red LED long leg (anode). Connect D3 through r_yellow to the yellow LED long leg. Connect D4 through r_blue to the blue LED long leg. All three short legs (cathodes, flat edge of the case) go to GND. Each resistor is 330 ohms and can face either way.
5. Connect the piezo and check the circuit
Connect the passive piezo signal lead to D9 and its other lead to GND. All GND connections share Uno ground. Check that no 5V wire touches GND before plugging in USB. Test using a broad flat object at 25, 13, and 8 cm.
- This design uses a small passive piezo, not a high-current siren or magnetic buzzer.
- The sensor works over approximately 2-400 cm. Missing or invalid echoes turn all lights and the buzzer off; this is not a safety-rated alarm.
Review all connections
1. Connections between "sonar" and "Arduino"
2. Connections between "lcd" and "Arduino"
3. Connections between "buzzer" and "Arduino"
4. Connections between "r_red" and "Arduino"
5. Connections between "red" and "Arduino"
6. Connections between "r_yellow" and "Arduino"
7. Connections between "yellow" and "Arduino"
8. Connections between "r_blue" and "Arduino"
9. Connections between "blue" and "Arduino"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
const uint8_t RED = 2, YELLOW = 3, BLUE = 4;
const uint8_t TRIG = 7, ECHO = 8, BUZZER = 9;
hd44780_I2Cexp lcd;
bool lcdReady = false;
char previous[4][21] = {};
int previousState = -1;
void row(uint8_t index, const char *text) {
char padded[21];
memset(padded, ' ', 20);
padded[20] = '\0';
size_t length = strlen(text);
if (length > 20) length = 20;
memcpy(padded, text, length);
if (strcmp(previous[index], padded) != 0) {
if (lcdReady) {
lcd.setCursor(0, index);
lcd.print(padded);
}
strcpy(previous[index], padded);
}
}
void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(BUZZER, OUTPUT);
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
digitalWrite(TRIG, LOW);
Serial.begin(9600);
Wire.begin();
lcdReady = (lcd.begin(20, 4) == 0);
if (!lcdReady) Serial.println(F("LCD not detected: check wiring and contrast."));
row(0, "Distance monitor");
}
void loop() {
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
unsigned long duration = pulseIn(ECHO, HIGH, 30000UL);
float cm = duration / 58.0f;
bool valid = duration != 0 && cm >= 2.0f && cm <= 400.0f;
int state = !valid ? 0 : (cm >= 20.0f ? 1 : (cm <= 10.0f ? 3 : 2));
if (state != previousState) {
digitalWrite(RED, state == 1);
digitalWrite(YELLOW, state == 2);
digitalWrite(BLUE, state == 3);
if (state == 3) tone(BUZZER, 4000);
else noTone(BUZZER);
previousState = state;
}
char distanceText[21];
if (valid) {
char number[10];
dtostrf(cm, 5, 1, number);
snprintf(distanceText, sizeof(distanceText), "Distance: %s cm", number);
} else strcpy(distanceText, "Distance: no echo");
row(1, distanceText);
if (state == 1) {
row(2, "The Distance is far"); row(3, "");
} else if (state == 2) {
row(2, "Object is Closer"); row(3, "");
} else if (state == 3) {
row(2, "The OBJECT is"); row(3, "TOO CLOSE");
} else {
row(2, "No valid reading"); row(3, "Check target/sensor");
}
Serial.println(distanceText);
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.




