// Pin connected to the LDR (light sensor)
const int LDR_PIN = A0;
// Pin connected to the relay
const int RELAY_PIN = A1;
void setup() {
Serial.begin(9600); // Initialize Serial communication
pinMode(LDR_PIN, INPUT); // Set the LDR_PIN as INPUT
pinMode(RELAY_PIN, OUTPUT); // Set the relay pin as OUTPUT
}
void loop() {
int lightIntensity = digitalRead(LDR_PIN); // Read the output from the LDR
Serial.print("Light Intensity: ");
Serial.println(lightIntensity);
// Control the relay based on the light intensity
if (lightIntensity == 1) {
digitalWrite(RELAY_PIN, HIGH); // Turn on the relay if light intensity is high level
} else {
digitalWrite(RELAY_PIN, LOW); // Turn off the relay if light intensity is low level
}
delay(1000); // Wait for 1 second before measuring the light intensity again
}