As we know, the display brightness on Wise Clock 4 can be changed between 5 levels, by pressing the "Plus" button. To adjust the brightness automatically, based on the light conditions, we need to add a light-sensitive sensor of some sort, and the most common is the LDR (light-dependent resistor).
Any of the countless articles and tutorials on Arduino + LDR will teach how to connect the LDR to an analog pin, using a voltage divider. For Wise Clock 4, the LDR is connected between A0 (pin 40 of the processor) and ground, with a 10k resistor between A0 and Vcc, as shown below:
GND|----[ LDR ]---A0---[10k resistor]----+Vcc
// use an LDR (connected to A0) to automatically adjust
// (every 5 seconds) screen brightness to ambient light;
and implemented in this new function:
// adjust brightness every 5 seconds;
if (millis() - lastCheck > 5000)
int ldrValue = analogRead(0); // A0
byte brightLevel = map(ldrValue, 0, 1023, MAX_BRIGHTNESS, 0);
if (nBrightness != brightLevel)
nBrightness = brightLevel;
lastCheck = millis();
called from the main loop (TheClock.ino):
unsigned long ms = millis();
if ((long)(ms - wiseClock.nextRun) >= 0)
It really doesn't get much simpler than this.
I also considered other hardware solutions (and actually bought the parts):
- analog light sensor PT19- I2C light sensor TSL2561
but I did not follow through after I saw how effective (and so much cheaper) the LDR is.