// Define the pins for the light sensor and LED
const int lightSensorPin = 34; // Analog input pin A2
const int ledPin = 2; // GPIO pin 2
void setup() {
// Initialize the serial communication for debugging
Serial.begin(9600);
// Set the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the value from the light sensor
int lightValue = analogRead(lightSensorPin);
// Print the light value to the serial monitor for debugging
Serial.print("Light value: ");
Serial.println(lightValue);
// Check if it's dark outside
if (lightValue < 500) {
// Turn on the LED
digitalWrite(ledPin, HIGH);
Serial.println("It's dark outside. Turning on the light.");
}
else {
// Turn off the LED
digitalWrite(ledPin, LOW);
Serial.println("It's light outside. Turning off the light.");
}
// Wait for a moment before checking the light again
delay(1000);
}