Arduino Nano-Based Proximity Alert System with Ultrasonic Sensor, Buzzer, and Vibration Motor
View and Edit Project In Cirkit Designer
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
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
Buzzer
- Description: An electronic device that produces a sound when a voltage is applied.
- Pins: POSITIVE, NEGATIVE
HC-SR04 Ultrasonic Sensor
- Description: A sensor used to measure distance by using ultrasonic waves.
- Pins: VCC, TRIG, ECHO, GND
Rocker Switch
- Description: A switch that can be toggled between two positions to open or close a circuit.
- Pins: 1, 2
Vibration Motor
- Description: A small motor that provides vibration feedback.
- Pins: +, -
9V Battery
- Description: A standard 9V battery used to power the circuit.
- Pins: -, +
Wiring Details
Arduino Nano
GND is connected to:
- Buzzer (NEGATIVE)
- HC-SR04 Ultrasonic Sensor (GND)
- Vibration Motor (-)
- Rocker Switch (1)
VIN is connected to:
- HC-SR04 Ultrasonic Sensor (VCC)
- 9V Battery (+)
D5 is connected to:
- Vibration Motor (+)
D6 is connected to:
- Buzzer (POSITIVE)
D8 is connected to:
- HC-SR04 Ultrasonic Sensor (ECHO)
D9 is connected to:
- HC-SR04 Ultrasonic Sensor (TRIG)
Buzzer
NEGATIVE is connected to:
- Arduino Nano (GND)
POSITIVE is connected to:
- Arduino Nano (D6)
HC-SR04 Ultrasonic Sensor
VCC is connected to:
- Arduino Nano (VIN)
TRIG is connected to:
- Arduino Nano (D9)
ECHO is connected to:
- Arduino Nano (D8)
GND is connected to:
- Arduino Nano (GND)
Rocker Switch
1 is connected to:
- Arduino Nano (GND)
2 is connected to:
- 9V Battery (-)
Vibration Motor
+ is connected to:
- Arduino Nano (D5)
- is connected to:
- Arduino Nano (GND)
9V Battery
+ is connected to:
- Arduino Nano (VIN)
- is connected to:
- Rocker Switch (2)
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.