// LDR Sensor, LED, Buzzer, and Relay Control Triger 5 v LED,
// Adjust the threshold value as needed
const int sensorPin = A0; // Motion sensor input pin
const int ledPin = 13; // LED output pin (built-in LED)
const int buzzerPin = 8; // Buzzer output pin
const int relayPin = 3; // Relay control pin
int threshold = 500; // Set your desired LDR threshold value
void setup() {
pinMode(sensorPin, INPUT); // Set LDR pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(buzzerPin, OUTPUT);// Set buzzer pin as output
pinMode(relayPin, OUTPUT); // Set relay pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = analogRead(sensorPin); // Read LDR value
Serial.print("LDR Value: ");
Serial.println(sensorValue); // Print LDR value to serial monitor
// Check LDR value against threshold
if (sensorValue > threshold) {
digitalWrite(ledPin, HIGH); // Turn on LED
tone(buzzerPin, 1000); // Activate buzzer
digitalWrite(relayPin, HIGH);// Turn on relay (activate lamp, for example)
} else {
digitalWrite(ledPin, LOW); // Turn off LED
noTone(buzzerPin); // Stop buzzer
digitalWrite(relayPin, LOW); // Turn off relay (deactivate lamp)
}
delay(1000); // Wait for a second
}
// Motion Sensor, LED, Buzzer, and Relay Control,GOOD lUCK ,Eng Odeh Alamrow