// Pin Definitions
#define LIGHT_SENSOR_PIN 34 // Analog pin connected to the light sensor
#define LED_PIN 2 // Pin for the LED
void setup() {
// Initialize serial communication for debugging
Serial.begin(115200);
// Set pin mode for LED
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// Read light sensor value
int lightLevel = analogRead(LIGHT_SENSOR_PIN);
// Print the light level to the serial monitor for debugging
Serial.print("Light Level: ");
Serial.println(lightLevel);
// Threshold value for darkness detection (adjust based on sensor readings)
int lightThreshold = 500; // Example threshold value
// Check if it's dark
if (lightLevel < lightThreshold) {
// Turn on the LED
digitalWrite(LED_PIN, HIGH);
Serial.println("Il fait nuit, LED allumée");
} else {
// Turn off the LED
digitalWrite(LED_PIN, LOW);
Serial.println("Il fait jour, LED éteinte");
}
// Delay before the next reading
delay(1000);
}