const int ldrPin = A0; // LDR connected to analog pin A0
const int buzzerPin = 11; // Buzzer connected to digital pin 8
int threshold = 500; // Light threshold value (adjust as needed)
void setup() {
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600); // Start serial monitor
}
void loop() {
int ldrValue = analogRead(ldrPin);
Serial.println(ldrValue); // Debug: See light values
if (ldrValue < threshold) {
digitalWrite(buzzerPin, HIGH); // Turn on buzzer in dark
} else {
digitalWrite(buzzerPin, LOW); // Turn off buzzer in light
}
delay(200); // Short delay to stabilize readings
}
Good day! I just want to offer you a big thumbs up for your excellent information you have got here on this post. Ill be coming back to your blog for more soon.