This circuit is a motion detection system using an Arduino UNO, a PIR sensor, a 5V relay, a piezo buzzer, and a 9V battery. The PIR sensor detects motion and sends a signal to the Arduino, which then activates the relay to power the piezo buzzer, producing an audible alert.
Arduino UNO
PIR Sensor
5V Relay
Piezo Buzzer
9V Battery
/*
* Motion Detector
* This Arduino sketch uses a PIR sensor to detect motion. When motion is
* detected, it activates a relay which in turn powers a piezo buzzer.
*/
// Pin definitions
const int pirPin = 7; // PIR sensor signal pin
const int relayPin = 8; // Relay control pin
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize PIR sensor pin as input
pinMode(pirPin, INPUT);
// Initialize relay pin as output
pinMode(relayPin, OUTPUT);
// Ensure relay is off initially
digitalWrite(relayPin, LOW);
}
void loop() {
// Read PIR sensor value
int pirValue = digitalRead(pirPin);
// If motion is detected
if (pirValue == HIGH) {
// Turn on relay
digitalWrite(relayPin, HIGH);
// Print motion detected message
Serial.println("Motion detected!");
} else {
// Turn off relay
digitalWrite(relayPin, LOW);
}
// Small delay to avoid bouncing
delay(100);
}
This code initializes the PIR sensor and relay pins, continuously checks for motion, and activates the relay to power the piezo buzzer when motion is detected.