Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Ultrasonic Distance Sensor with Alert Buzzer and LED Indicator

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Ultrasonic Distance Sensor with Alert Buzzer and LED Indicator

Circuit Documentation

Summary

This circuit is designed to utilize an Arduino UNO microcontroller to interface with an HC-SR04 Ultrasonic Sensor for distance measurement. When an object is detected within a predefined threshold of 10 cm, the circuit activates a buzzer and lights up an LED. The purpose of this setup is to provide a simple proximity alert system.

Component List

Arduino UNO

Buzzer

HC-SR04 Ultrasonic Sensor

LED: Two Pin (red)

Wiring Details

Arduino UNO

Buzzer

HC-SR04 Ultrasonic Sensor

LED: Two Pin (red)

Documented Code

/*
 * This Arduino Sketch uses an HC-SR04 Ultrasonic Sensor to measure distance.
 * If an object is detected within 10 cm, a buzzer sounds and an LED lights up.
 */

#define TRIG_PIN 9
#define ECHO_PIN 10
#define BUZZER_PIN 11
#define LED_PIN 11
#define DISTANCE_THRESHOLD 10 // Distance threshold in cm

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  long duration, distance;
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1;
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  if (distance < DISTANCE_THRESHOLD) {
    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED_PIN, LOW);
  }
  delay(500);
}

The code is written for the Arduino UNO and is responsible for controlling the HC-SR04 Ultrasonic Sensor, the buzzer, and the LED. It sets up the necessary pins as input or output, performs distance measurement in the loop function, and activates the buzzer and LED when the distance threshold condition is met. Serial communication is also established for monitoring the distance measurements.