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

Arduino Nano-Based Proximity Alert System with Ultrasonic Sensor, Buzzer, and Vibration Motor

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Proximity Alert System with Ultrasonic Sensor, Buzzer, and Vibration Motor

Circuit Documentation

Summary

This circuit is designed to measure distance using an HC-SR04 Ultrasonic Sensor and provide feedback through a buzzer and a vibration motor. The system is controlled by an Arduino Nano microcontroller. The circuit is powered by a 9V battery and includes a rocker switch for turning the system on and off.

Component List

  1. Arduino Nano

    • Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  2. Buzzer

    • Description: An electronic device that produces a sound when a voltage is applied.
    • Pins: POSITIVE, NEGATIVE
  3. HC-SR04 Ultrasonic Sensor

    • Description: A sensor used to measure distance by using ultrasonic waves.
    • Pins: VCC, TRIG, ECHO, GND
  4. Rocker Switch

    • Description: A switch that can be toggled between two positions to open or close a circuit.
    • Pins: 1, 2
  5. Vibration Motor

    • Description: A small motor that provides vibration feedback.
    • Pins: +, -
  6. 9V Battery

    • Description: A standard 9V battery used to power the circuit.
    • Pins: -, +

Wiring Details

Arduino Nano

Buzzer

HC-SR04 Ultrasonic Sensor

Rocker Switch

Vibration Motor

9V Battery

Code Documentation

Arduino Nano Code

#define TRIG_PIN 9
#define ECHO_PIN 8
#define BUZZER_PIN 6
#define VIBRATION_PIN 5

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(VIBRATION_PIN, OUTPUT);
}

void loop() {
  long duration, distance;
  
  // Trigger the ultrasonic sensor
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  
  // Measure the distance
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1; // Convert to cm
  
  if (distance <= 50 && distance > 20) {
    digitalWrite(BUZZER_PIN, HIGH); // Activate buzzer
    digitalWrite(VIBRATION_PIN, LOW); // Keep vibration motor off
  } else if (distance <= 20) {
    digitalWrite(BUZZER_PIN, HIGH); // Activate buzzer
    digitalWrite(VIBRATION_PIN, HIGH); // Activate vibration motor
    delay(100); // Run motor for 100ms
    digitalWrite(VIBRATION_PIN, LOW); // Deactivate vibration motor
  } else {
    digitalWrite(BUZZER_PIN, LOW); // Deactivate buzzer
    digitalWrite(VIBRATION_PIN, LOW); // Deactivate vibration motor
  }
  
  delay(100); // Small delay for stability
}

This code sets up the pins for the ultrasonic sensor, buzzer, and vibration motor. It continuously measures the distance using the ultrasonic sensor and activates the buzzer and vibration motor based on the measured distance.