Introduction: WiFi Atomic Binary Clock With ESP8266
I used an ESP8266 (NodeMCU v3 variant) to make a very simple WiFi-enabled binary clock which gets its time from the US NIST atomic clocks as a birthday gift for my daughter. The clock shows hours and minutes separately in binary. (I don't like the idea of BCD as found on some binary clocks.) I made the case from a plastic prescription medication bottle.
- NodeMCU v3 ESP8266 development board (about $3.50 from AliExpress)
- Ten 220 ohm resistors
- Six small green LEDs
- Four medium yellow LEDs
- Plastic medication bottle
- Metal or wooden ring as spacer
- Computer for programming firmware.
This was my first Arduino-like project, hence beyond my comfort-zone.
Step 1: Electronics
The clock needs ten GPIOs (or some further electronics to address ten LEDs). After some experimentation, I chose 16, 5, 4, 2, 14, 12, 13, 15, 3 and 1. Of these, 16, 5, 4, 2, 14 and 12 are used for the minutes and 13, 15, 3 and 1 for the hours (least significant bit first). On the NodeMCU v3 board, the ten GPIOs are labeled, respectively, D0, D1, D2, D4, D5, D6, D7, D8, RX and TX.
Information online suggests that the ESP8266 can sink 20 mA at each GPIO. For both yellow and green LEDs, a 220 ohm resistor did the trick to limit current. The wiring for the project is very simple:
- GPIO to 220 ohm resistor
- other lead of resistor to cathode (-, flat) side of LED
- other lead of (anode, +, curved) of LED to 3V on development board.
Repeat 10 times.
I used two pieces of proto board. On one I installed a female header for the development board (all the pins we need are on one side of the board). (I made the header by cutting a 16-pin DIP socket into two 8-pin sockets) and the resistors. I then ran wires to a second proto board which had the LEDs. The reason for the arrangement was to fit inside the case.
Step 2: Firmware and Configuration
- Set up Arduino and 8266 board package. These instructions are nice, but make sure you select the NodeMCU v1 board.
- Download my sketch from here. It's adapted from Ben Buxton's base-10 atomic clock.
- Install any USB driver needed for your development board.
- Plug board into computer's USB port and upload sketch.
Now it's time to configure the clock. Turn it on (e.g., plugged into a USB charger). Instead of the time, you'll get some in-and-out LED animation (you'll understand when you see it). During it, press the development board's GPIO 0 button (it may be labeled Flash). The clock will then set up a WiFI access point. Connect your computer to the access point and point your browser to 192.168.4.1 (usually). The clock will in fact be flashing the IP address at you in the ten LEDs. It will do so as follows: the highest two bits will show the octet number (00, 01, 10 or 11), and the remaining eight bits will show the octet value. You can now configure the SSID and password for your WiFi, and set your time-zone. The clock can also automatically compensate for daylight-savings as long as your daylight-savings follows US date rules.
Then unplug the clock, and if all goes well, you'll get animations, and then the time in binary as it connects to your WiFi and fetches the time from the internet.
To configure the clock in the future, just go to its IP address (if you press the GPIO 0 button, it will show you the IP address, using the same format as above).
The clock can also be used as a WiFi-controlled ten LED light if you have a use for that. The API is explained here.
Step 3: Case
You probably won't want to imitate my case exactly, as you're unlikely to have the same size medicine bottle as I did.
First, the clock tube. Drill holes spaced the same way as your LEDs. I used scrap protoboard to index the holes I was drilling. Drill carefully not to crack the plastic.
I found that using a bit of foam (which came with the development board) could make the electronics fit snugly in the bottle, with the LEDs pressing against the holes.
I then cut two trapezoidal legs for the ends of the bottle. The one at the closed end I screwed to the bottle. The one at the open end I made a groove in for the bottle lip (using a paddle bit and then a rotary tool). I then drilled a hole in the open end leg for the USB cable to fit through, and, after painting, glued a spacer ring on the inside to keep electronics from sliding.
I cut two round pieces of wood to join the legs, and finished everything in a glossy black (acrylic black paint plus varnish).
Once it's assembled, one can adjust the tilt angle of the clock.
We have a be nice policy.
Please be positive and constructive.