// Define the LDR pin
int LDR_Pin = A0;
// Define the buzzer pin
int Buzzer_Pin = 8;
int LED = 9;
// Define the threshold value for the LDR
int Threshold_Value = 500;
void setup() {
// Start serial communication
Serial.begin(9600);
// Set the buzzer pin as an output
pinMode(Buzzer_Pin, OUTPUT);
pinMode(LED,OUTPUT);
}
void loop() {
// Read the LDR value
int LDR_Value = analogRead(LDR_Pin);
// Print the LDR value to the serial monitor
Serial.println(LDR_Value);
// Check if the LDR value is above the threshold
if (LDR_Value > Threshold_Value) {
// Sound the buzzer
digitalWrite(Buzzer_Pin, HIGH);
} else {
// Turn off the buzzer
digitalWrite(Buzzer_Pin, LOW);
delay(100);
digitalWrite(LED,HIGH);
delay(50);
digitalWrite(LED,LOW);
delay(50);
}
}