veilleuse-automatique.ino
The onboard light sensor (LDR) decides alone: when night falls the LED lights as a warm night-light. Calibrate the threshold by watching serial values, room by room.
Hardware required
An Arduino Esplora (ATmega32U4, 5 V) with its onboard sensors: joystick, 4 buttons, slider, RGB LED, buzzer, light, temperature, sound and accelerometer. None.
Wiring
Nothing to wire.
How it works
readLightSensor returns 0-1023; below the threshold the RGB LED goes dim amber, otherwise off. In the Arduino IDE, select « Arduino Esplora »; add the « Esplora » library from the Library Manager to reach the onboard sensors.
Going further
Add a fade-in (loop on writeRGB) or a timed shutoff via the joystick button.
veilleuse-automatique.ino
// Capteur de lumiere embarque (LDR) -> veilleuse automatique.
#include <Esplora.h>
const int SEUIL = 200; // a regler au moniteur serie
void setup() {
Serial.begin(9600);
}
void loop() {
int lumiere = Esplora.readLightSensor(); // 0 (nuit) .. 1023 (plein jour)
Serial.println(lumiere);
if (lumiere < SEUIL) {
Esplora.writeRGB(60, 30, 0); // halo chaud
} else {
Esplora.writeRGB(0, 0, 0);
}
delay(200);
}