Introduction: IoT Analog Clock

This project was meant to be submitted for the IoT contest but was delayed due to excessive shipping times on some of the components. The project doesn't necessarily need to have IoT capabilities but does it make it easier for those who have trouble seeing the time as the night goes on, this issue could be resolved by setting a higher ambient light setting in the code though. The clock is different in that it only has one hand, which in this configuration means that it only represents minutes. However with changes to the code it can represent any set of time you like. The current code moves a stepper motor 1 step every ~1.4 minutes, which might make you think that it will easily lose time, however since the stepper motor does not step 0.5 degrees per step (which would represent 1 minute on a normal clock) this ratio actually brings a very good approximation of the current time, to put it simply there is more error in the gear system inside the stepper motor than in the actual timing. The code also turns on 4 LEDs at a fairly low brightness (about 20%) between the hours of 10PM and 6AM. The lighting can also be controlled by the user through their phone with the settings of "High, Med, Low, and Off", which works as expected except during the ambient lighting hours, where off defaults to the ambient lighting.

Step 1: Tools and Materials


Soldering Iron and Solder

Hot Glue Gun w/ Glue sticks

Hobby Knife or Box Cutter

3D Printer and Filament (If you do not have access to one elsewhere)

Wire Cutters/Strippers


Foam Board

Shadow Box

NodeMCU ESP-8266

28BYJ-48 Stepper Motor w/ ULN2003 Driver Board

22AWG Hook-up Wire

LEDs (Atleast 4, any color is fine)

Protoboard or Small Breadboard

USB Charging Cable

USB Charging Brick or Battery with USB Ports

Step 2: Let's Look at the Circuit!

Basic Breakdown:

D0 >>> LED1 Power

D1>>> LED2 Power

D2>>> LED3 Power

D3>>> LED4 Power

3V3>>> Stepper Motor Power

GND>>> Stepper Motor Ground

D5>>> Stepper Motor IN1

D6>>> Stepper Motor IN2

D7>>> Stepper Motor IN3

D8>>> Stepper Motor IN4

All Grounds besides those listed return to a common ground on a breadboard or proto-board. This would mean all the LED ground wires return to the same row on a breadboard with one extra wire leading back to any GND pin on the ESP8266. If using a protoboard, all the ground wires should be soldered together in some way with an extra wire leading back to GND on the ESP8266.

Step 3: Assembling the Clock

Part 1: The Foam

The first step of this process is to cut out the foam so that it fits firmly inside the shadow box. For my shadow box this meant cutting out a square of foam that was 8-7/8" x 8-7/8" in size. This will most likely differ for your shadow box. Take care in cutting clean edges on the foam as this part will be visible to anyone who sees the clock. If you are not confident in your skills to get it right on the first cut, cut it at least an 1/8" larger than it should be in both the X and Y directions, as it is not easy cut off very thin pieces of foam, when i tried to cut out thin pieces of foam it only led to larger pieces starting to break off so be very careful and take your time.

Part 2: Feature Location

The key to this project is layout, the better your starting square of foam, the easier it gets to do the rest of the project. To begin marking out where things will go you first must pick the "presentation side" of the foam, whatever side you pick as the "presentation side" you will do the layout work on the opposing side. You want to begin by marking the center, if you have a vernier caliper handy, this is going to be incredibly easy. Set the caliper to 4-7/16" (4.4375) and run the sharp point of the rigid jaw along the foam as you glide the moving jaw along the side of the foam square. Pick a perpendicular side and repeat, this will be the center of the clock. Feature location will be harder with a ruler, especially if you didn't cut straight on the edges of the foam square. You will want to draw a line that is 4-7/16" away from the edge of the foam square and do the same with a perpendicular side. You should have a intersection which will be the hole the stepper motor pokes through.

Part 3: Stepper Motor Hole

At the intersection of the lines from the "Feature Location" step, you will want to place a hole that is 5mm in diameter. If you don't have a closely sized drill bit, you can try to use a straw to poke through the hole as some straws are very close in diameter to the stepper motor axle. Check that the diameters are similar before using the straw method. Once the hole has been placed, you will have to carve out a small recess for the small protrusion from the face of the stepper motor. It is a small island that protrudes from the face of the motor and is concentric with the stepper motor axle, the island is 9mm in diameter. You do not have to carve deeply as the foam is very impressionable anyway. The face of the stepper motor should be flush to the layout side of the foam.

Part 4: Gluing The Motor

At this point all of the hard work is done. You can begin hot gluing the stepper motor to the layout side of the board at the provided tabs on the motor. Make sure the motor remains flush to the board as the glue dries, because if it isn't, the hand of the clock will not move parallel to the face of the presentation side.

Part 5: Gluing The Clock Face and The Corner Pieces

At this point you will want to place the clock hand on the stepper motor axle, and make sure you have the clock as level as possible on a table. Then carefully place the clock face around the hand of the clock, it's placement is done completely by estimation. Move the hand around the inside of the clock face and keep adjusting clock face so that the hand does not touch it at any point. The hand of the clock was made to be .015" smaller in diameter than the inside of the clock face, this is equivalent to the thickness of 4 sheets of paper stacked on top of each other, so as long as the hand doesn't touch the clock face and looks reasonably equal in distance from the clock face as it rotates around then you have found the correct center of the clock, I located this spot by marking very lightly in pencil up against the outside edge of the clock face. The next priority will be making sure the 12 O'Clock position is parallel to the left and right side of the foam square. This is again done by estimation, once it is located to your liking, you very lightly locate it with a pencil. Now, place a dab of hot glue on the backside of the clock face at the 12 O'Clock position and place the clock face in the location you previously laid out. Once the glue is fully set, press lightly on the 12 O'Clock position and lift the 6 O'Clock position so that you can glue underneath it. For the remaining positions, be careful in lifting the clock face and place glue under those positions as well. The clock face should be flush to the surface of the foam board and positioned correctly.

The corner pieces should be attached to the foam board as shown in the picture for this step, that is, to the presentation side of the board and in the exact corners. Be careful to make sure the orientation of the piece points toward the center of the clock. When gluing this piece I used the help of a block to hold the corner piece above the glass inside the shadow box and butted the block up against an inside corner of the box and made sure the corner piece was butted up against the corner as well, I then placed hot glue on the backside of the corner piece and pressed the foam square inside the shadow box, which ensured the corner piece was glued to the exact corner of the foam board, make sure the glue sets before removing the foam board from the shadow box and repeat for all the corner pieces, making sure to cut off the corners of the foam board that are now hidden behind the plastic pieces. This will allow the wires from the LEDs to snake to the backside of the board.

Part 6: Final Gluing and Wiring

The legs should be cut rather short on the LEDs to make sure they fit inside the shadow without bending, I cut the legs of the LEDs to a length of about 3/8" which worked perfectly with the flexible 22AWG wire. Solder a red and black wire to the power and ground of each LED respectively, making sure the wire is long enough to reach from that LED's corner to the ESP8266. Once the wires are soldered to the LED, hot glue the LED into place from the "hidden corner" side of the LED. Make sure to glue over the connections to prevent shorts and that the glue makes contact with both the LED and the plastic corner. Repeat this with each corner. The position of all the other wiring is not really important as it isn't seen by anyone. So long as it is securely placed, it will be fine.

Part 7: Cut a Notch For the Cord

If you have chosen to power the clock with a USB phone charging bank, the wire will have to exit out the back of the clock, which require cutting a small notch in a bottom corner of the backing board of the shadow box. Depending on the box you acquired it may just be light cardboard or it could be MDF like mine. If it's a lighter material you can just cut through it and get on to the code, if it's a heavier material like MDF you may need to use something like a coping saw or similar tool to cut off the corner of the backing board. Try not to cut the notch overly large as the bigger the notch is, the more the cable will swing freely and the more likely it will be unplug at the ESP8266.

Step 4: The Code

The basics of the code are that it will connect to your network, host a HTML webpage (Which you can totally change, optimize, etc). The clock will work as you would expect it to, keeping time starting from the point it is turned on. Which leads to a interesting note, due to many factors such as the stepper motor not knowing its position, the loops operating based on count of the steps and not position, etc. The clock runs on the assumption that it began at 12AM. The ambient lighting in this system runs on this assumption as well. For those who are night owls, this will be no issue as you will probably be awake anyway and just need to remember to plug it in at 12AM. For those who cannot see themselves turning the clock on at this time, you can adjust the variable "one_hour" to equal a step number representing the current time. which may be tricky so it's best to do it at a change between hours such as 4:00 or 5:00. There are 42.66 steps per hour. 1024 steps per day. Basically multiply the current hour times 42.66 and you will get the number "one_hour" will need to be set to in order to adjust to the time you are starting it at.

Step 5: Final Notes

If you hope to customize the HTML/CSS placed inside the code, remember to design it for the platform you hope to use or be better at figuring out the tag than I was. With the current code you will most likely have to scroll sideways in order to change the light settings on your phone, which wasn't too much of a problem for me as I don't mess with the light settings too often, but for those who want to change the light settings more frequently and may get annoyed by the scrolling you can adjust the positioning of the elements in the CSS.

The stepper motor operates in full step mode for this program as using the half step resolution for this stepper motor did not provide any finer resolution for telling the time than the full step resolution. When trying to implement the half-stepping mode of the motor, the code got more messy than it needed to be for an application such as this. If you would like to attempt to implement half stepping, you will need to follow this order instead of the "Forward" function:

  1. High, Low, Low, Low
  2. High, High, Low, Low
  3. Low, High, Low, Low
  4. Low, High, High, Low
  5. Low, Low, High, Low
  6. Low, Low, High, High
  7. Low, Low, Low, High
  8. High, Low, Low, High

Lastly, your clock will look slightly different from mine as I mistakenly tried to copy a regular clock with 4 divisions between hours, but in this instance that would represent 12 minutes per division. I have provided the file for a clock with 3 divisions, so that each division represents 15 minutes, which would make more sense.

Happy Making!


About This Instructable




Bio: I am currently a Mechanical Engineering student, with 4 years experience in building Battlebots in the 15lb weight class. I enjoy creating projects that challenge ... More »
More by CaptCupcake:IoT Analog ClockUsing 3D Printing to Make a Custom Work StoolHow to Build an Electric Battlebot Using Batteries
Add instructable to: