ESP8266: Internet connected baby nightlight for less than $10

ESP32 Development Board WiFi+Bluetooth Ultra-Low Power Consumption Dual Cores ESP-32 ESP-32S Board
Integrated antenna and RF balun, power amplifier, low-noise amplifiers, filters, and power management module. The entire solution takes up the least amount of printed circuit board area. This board is used with 2.4 GHz dual-mode Wi-Fi and Bluetooth chips by TSMC 40nm low power technology, power and RF properties best, which is safe, reliable, and scalable to a variety of applications.

A while ago a wanted to build one of those nightlights for my daughter that tell her when to sleep and when to call for the parents: an orange light behind a sun depicts the day, a blue light behind a moon the night. My first attempt was based on a Spark Core which is a bit pricy (~$40) to just connect to the internet to synchronise the time.
Playing with the ESP8266 I needed an actual project to use it and the nightlight came in handy. It uses both GPIO pins available on the ESP8266-ESP01 and calls google.com to synchronise the time every 30 minutes as soon as the device is connected to the access point. I currently still need an Arduino but just as power source and debugging tool. So the actual components are:

  • plastic box (from food delivery)
  • black paper as mask
  • sun and moon downloaded and printed from the internet
  • cardboard from a cereal box to shield the LEDs
  • 2 LEDs (orange and blue)
  • a mini bread board
  • an ESP8266
  • 2 resistors
  • some jumper wires

Prepare the ESP8266

First you need to put the LUA firmware from nodemcu on the ESP8266. I described in this post how it is done. Once this is done you can use the Esplorer to transfer lua files to the ESP8266.

Check out the code and adapt it

Checkout the two lua files from here and adapt them to your needs. Especially your access point and credentials need to be set in the init.lua file. If you’re not living in the GMT+1 timezone you’ll also need to adapt your offset in the nightlight.lua script. In the current version the day/night phases can only be set within the code, but this might change in the future. There is a lightweight webserver available for the lua firmware which might allow setting the time through a web browser.

Transfer the files to the ESP8266

The current version of the firmware crashes and restarts the unit if you try to call the dofile function for a non-existing file. Since the init.lua scripts calls the nightlight.lua script transfer them in the appropriate order (first nightlight, then init). Note: I had some cases where the module would connect to the AP and receive an IP but would further fail to call the google server to get the time. This only happened after clean updates of the firmware and disappeared after a short while.

Sources

Posted by squix78

2 comments

  1. Hi Daniel,

    what is the deeper sense of this light?
    Is it for conditioning a baby when it has to sleep?
    If yes, has it worked?
    Regards
    Thomas

    • I have a commercial version of this and for us it was just a way to let them know when it was time to get up and stop them form getting up at 4 in the morning. The very first night they stayed in bed until the sun was shown and after two years it still works and they still stay in bed until the sun comes up.

Leave a Reply