// Smart Lamp System with Motion Detection and Security Bell
const int motionPin = 2; // Motion sensor input pin
const int ldrPin = A0; // LDR (Light Dependent Resistor) analog input pin
const int lampPin = 9; // Lamp control pin (relay, transistor, or LED)
const int buzzerPin = 10; // Buzzer control pin
void setup() {
pinMode(motionPin, INPUT);
pinMode(ldrPin, OUTPUT);
pinMode(lampPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
int motionValue = digitalRead(motionPin);
int ldrValue = analogRead(ldrPin);
// No motion, low light conditions
if (!motionValue && ldrValue < 300) {
digitalWrite(lampPin, LOW); // Turn off lamp
noTone(buzzerPin); // Silence the buzzer
}
// Motion detected, low light conditions
else if (motionValue && ldrValue < 300) {
digitalWrite(lampPin, HIGH); // Turn on lamp
tone(buzzerPin, 1000); // Activate buzzer
}
// No motion, sufficient light
else if (!motionValue && ldrValue >= 300) {
digitalWrite(lampPin, LOW); // Turn off lamp
noTone(buzzerPin); // Silence the buzzer
}
// Motion detected, sufficient light
else if (motionValue && ldrValue >= 300) {
digitalWrite(lampPin, HIGH); // Turn on lamp
tone(buzzerPin, 1000); // Activate buzzer
}
}