const int LDRPin = A0; // LDR connected to analog pin A0
const int RelayPin = 2; // Relay control pin connected to digital pin 2
void setup() {
pinMode(RelayPin, OUTPUT); // Set relay pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int ldrValue = analogRead(LDRPin); // Read LDR value
Serial.print("LDR Value: ");
Serial.println(ldrValue);
// Adjust the threshold value according to your requirement
int threshold = 500; // Example threshold value
if (ldrValue < threshold) {
digitalWrite(RelayPin, HIGH); // Turn on relay if light intensity is low
} else {
digitalWrite(RelayPin, LOW); // Turn off relay if light intensity is high
}
delay(1000); // Delay for stability
}