Skip to content

Christoph-D/esp8266-wakelight

Repository files navigation

esp8266-wakelight

An alarm clock with light instead of sound, simulating a sunrise, with NTP time synchronization, and with programmable alarm times for each day of the week.

This code works on the esp8266 wifi module with the nodemcu firmware. It was successfully tested on an ESP-01 and an ESP-12E.

Web Interface

Click on this image to the web interface in action:

screenshot

For no good reason, the interface is partly in Japanese (月曜日 is "Monday", etc.).

The "Toggle" button toggles the time zone between CET and CEST. Setting different time zones amounts to changing the offsets in src/time.lua.

Eventually daylight saving time (DST) should toggle automatically based on the time zone, but this would require keeping track of the date, which is not implemented yet. The wakelight remembers the status of daylight saving time after power loss, as well as the alarm times.

Hardware

Any esp8266 module will do, even the cheap ESP-01 ($1-$2 on aliexpress). First you need to flash it with a recent nodemcu firmware. Don't use prebuilt firmwares, those are far too old and won't work. Either compile your own or use http://nodemcu-build.com/ to get a recent firmware. You need to enable at least the following modules: file, gpio, net, node, rtcmem, rtctime, sntp, tmr, uart, wifi, ws2812.

The LEDs must be WS2812B modules. You can change the number of LEDs in globals.lua. The default for NUM_LEDS is 144, which is the number of LEDs on a common high density 1m strip. For increased brightness, you can connect multiple strips in parallel without changing NUM_LEDS, or concatenate them and increase NUM_LEDS (I would recommend the former because the timing of these LEDs strains the ESP chip). I would say that two 1m strips (144 LED/m), a total of 288 LEDs, are the minimum for adequate brightness. Unfortunately the WS2812B LEDs are not very efficient compared to modern LED bulbs.

Please be aware that driving the LEDs requires quite a lot of power (>25W for 144 LEDs). A 5V cellphone charger or a computer USB port will not work.

The LEDs must be connected to pin 4 of the ESP chip. The ws2812 module in nodemcu only works on the serial transmitter pin, which happens to be pin 4.

You may also need a level shifter between the LEDs and the ESP because the ESP is 3.3V but the WS2812B LEDs are 5V. In my case it also worked without a level shifter, but adding one reduced glitches on the LED strips.

OTA Upload

The wakelight accepts over-the-air updates of lua files from the script ota_upload.sh. There is currently no authentication.

Schematic

schematic

The schematic uses the ESP components from https://github.com/jdunmire/kicad-ESP8266 .

Because I could not readily find a level shifter component in kicad, I omitted that part in the schematic. The actual hardware has a TXS0108E between pin 4 of the ESP chip and the WS2812B LED input.

Mood Light

There is also a very simple mood light feature that you can enable/disable manually from the web interface. This is mostly an experiment and serves no purpose. Currently implemented is red, green and white light. Edit the file src/mood.lua if you would like to implement more complex lighting scenarios.