Circuit Diagram:
Ultrasonic Proximity Alert System with Arduino UNO
Hardware Wire Bus Distribution Index
Connect your HC-SR04 ultrasonic rangefinder module, indicators, and safety warning buzzer to the board pins matching this configuration layout:
| Component Interface Pin | Target Controller Location | Signal System Purpose |
|---|---|---|
| HC-SR04 VCC | 5V Power Rail Pin | +5V Main Ultrasonic Module Logic & Sensor Power |
| HC-SR04 TRIG | Digital Pin 9 | Output Trigger Line for sending high-frequency sonic bursts |
| HC-SR04 ECHO | Digital Pin 10 | Input Tracking Line for receiving reflection return flight duration |
| HC-SR04 GND | GND Pin Terminal | Common Circuit Ground Reference |
| Green LED Anode (+) | Digital Pin 5 | Clear Path Status Indicator Light |
| Red LED Anode (+) | Digital Pin 6 | Proximity Intrusion Threat Warning Light |
| Piezo Buzzer (+) | Digital Pin 7 | Acoustic Alarm Output Alert Driver Path |
| LED/Buzzer Cathodes (-) | GND Terminal Ports | Ground Returns (LED lines must utilize matching current resistors) |
⚠️ Telemetry Edge Safeguards: High-frequency sound waves can return a
0 measurement if the wave escapes reflection boundaries or strikes soft dampening profiles. The firmware explicitly checks for this case to filter structural noise before changing hardware status flags.
System Brief Explanation
- Range-to-Time Transformation: The microcontroller commands the sensor to trigger a 10-microsecond sonic flash. It calculates the flight time down to centimeters using the sound speed constant (
0.0343 cm/Β΅s) divided across the round-trip boundary path. - Dynamic Safety Boundaries: If an obstruction enters the half-range hazard parameter (
≤ 200 cm), the application logic kills the green indicators and instantly switches on the warning buzzer and red hazard line to prevent proximity breaches.
Source Firmware Application
Review the primary C++ code file container block below. The control utilities are hosted inside the top panel frame for instant deployment copying:
π ultrasonic_alert.ino
Arduino C++
// Define pin numbers
const int trigPin = 9;
const int echoPin = 10;
const int greenLedPin = 5; // New Green LED Pin
const int redLedPin = 6; // New Red LED Pin
const int buzzerPin = 7; // New Buzzer Pin
// Define variables
long duration;
int distance;
// Define safety threshold (half of max 400cm range)
const int safetyThreshold = 200;
void setup() {
// Set pin modes for ultrasonic sensor
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// Set pin modes for new alert hardware
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Initialize serial communication
Serial.begin(9600);
Serial.println("Ultrasonic Distance Sensor with Alerts Initialized!");
}
void loop() {
// Clear the trigPin by pulling it LOW
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Trigger the sensor by sending a 10-microsecond HIGH pulse
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin; returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculate the distance in centimeters
distance = duration * 0.0343 / 2;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Check if something is in the half-range zone
// Note: pulseIn can return 0 if out of range, so we ensure distance > 0
if (distance > 0 && distance <= safetyThreshold) {
// ALERT CONDITION: Object is close!
digitalWrite(redLedPin, HIGH); // Turn ON Red LED
digitalWrite(greenLedPin, LOW); // Turn OFF Green LED
digitalWrite(buzzerPin, HIGH); // Turn ON Buzzer
} else {
// NORMAL CONDITION: Path is clear
digitalWrite(redLedPin, LOW); // Turn OFF Red LED
digitalWrite(greenLedPin, HIGH); // Turn ON Green LED
digitalWrite(buzzerPin, LOW); // Turn OFF Buzzer
}
// Wait half a second before the next reading
delay(500);
}
Project Video Demonstration
Observe how the sensor maps proximity transitions, reports flight tracking metrics, and changes safety array markers live:

Comments
Post a Comment