The Analog Clock Box

by JohnThinger in Circuits > Arduino

1441 Views, 4 Favorites, 0 Comments

The Analog Clock Box

The Analog Clock Box

Your kid is not able to read an old-fashined analog clock? Your students are confused with that evil European 24 hour time format? Then this box might be a good and simple motivator!

Open the lid, put some sweets or chocolate inside and push any button. The servo-motor will lock the box, and the display will show a clock set to a random time. Furthermore, it shows four times in digital hh:mm notation. Hit the button below the right answer, and you and another time will be presented. Repeat this process with correct answers (literally)three times - and *taadaa* the servo will unlock the lid and hence give access to the sweets.

The provided code is pretty simple - feel free to increase the number of required correct answers - or to replace the entire clock thing by other brain teasers.

Supplies

  • 1x Leonardo-compatible "Pro Micro" Board with 8 MHz ATMEGA32U4 CPU @ 3.3 V (sometimes sold as "Arduino Pro Micro", just make sure that it is NOT an Arduino Nano or Arduino Micro which have the 328p CPU and run at 5 V
  • 1x KMR 1.8" TFT Display (like the one shown here)
  • 1x Perfboard with 24x18 holes (70 x 50 mm)
  • 1x Battery Holder with Switch for 4x 1,5 V AA batteries, approx. 69 x 65 x 19 mm, like this one
  • 1x LD1117v33 Voltage Regulator in TO-220 case like this one
  • 1x 100 nF Ceramic Capacitor
  • 2x 10 µF...100 µF Electrolytic Capacitor
  • 1x 40 Pin Female Dupont Hearder
  • 1x 1N4001 Diode
  • 4x Microswitches
  • 1x SG90 servo motor
  • 1x Piezo Butter (~ D 14 mm, H 7 mm)
  • 6x M2x8 Screw
  • 4x M3x8 Screw
  • 4x M4x30 Screw
  • 6x M2 Nut
  • 4x M3 Nut
  • 4x M4 Nut
  • Some 0.15...0.25 mm2 Cable
  • 3D Printer with some PLA filament (or, alternatively, a 3D printing service)

The Circuit

Circuit.jpg
Perfboard_01.jpg
Perfboard_02.jpg

In the provided diagrams and pictures, the perfboard is always shown from front and back. Please keep in mind that the view from front to back is mirrored this way.

The front side is the one which will accommodate the display. The Pro Micro goes to the back. Consequently, the header for the display is only on the front side (and soldered on the back side) and the headers for the Pro Micro are on the back side (and soldered on the front side). Thus, the headers shown with the dotted blue lines are only meant for orientation. I propose the following sequence for soldering:

  1. Cut one 3 pin header, one 8 pin header and two 12 pin headers from the 40 pin female Dupont header rail.
  2. Solder the 8 pin header to the front, all the other headers to the back as shown in the diagrams and in the first photo. (Do not get confused by the 4 pin header marked with a red dotted arrow. This was an approach of a socket for the piezo buzzer which is skipped at a later stage as the housing became to big - please just do not add it).
  3. Add the cables as shown in the diagrams, then all the other elements as shown in the picture.
  4. After soldering is finished, push the Pro Micro and the display into their headers.
Please note:
  • The slightly darker brown color in the diagram marks solder bridges.
  • Instead of the barrel jack shown in the diagram, these red and black lines must be connected to the battery pack. It is best to place a small screw terminal here as shown in the pictures.
  • Do not forget the heatsink on the voltage regulator. I bent the whole regulator with the heatsink by 90°. The original heatsink caused some collision here. This is why the pictures show that the heatsink was cut a bit using a metal saw.
  • The electrolytic capacitor at the 3 pin header (which will host the servo motor) is a bit of an overkill as the servo is not driven directly by the Pro Micro nor does it have any load - it just rotates a simple flap. However, adding a 50µF...100µF capacitor here could stabilize the circuit, so it should be added.
  • The diode is another overkill: Officially, the SG90 has a voltage range of 4.8...6 V, and it should "tolerate" a "somewhat" higher voltage "temporarily". The interpretation of these terms, however, heavily depends on the brand of SG90 you will buy. In my first try, I have connected my servo to 4 fresh AA batteries which added up around 7 V. The motor did not really move, but it smelled funny after some seconds... and then died silently. That is why I have thrown in the diode as a minimal way of voltage reducer.




Programming

Arduino_IDE.png

Start the Arduino IDE and load the attached Analog_Clock_Box.ino file. Make sure to select the "Sparkfun Pro Micro" board as shown in the picture.

If this option does not show up, please install the supporting drives and IDE addons as described here. As an additional fact, this site informs us that the RAW pin easily accepts up to 12V, so we could skip the external voltage regulator and connect the display directly to the Pro Micro. There are, however, different (cheaper) clones of the Pro Micro out there and some of them are very limited output current capabilities, so the display may run unstable. Thus, you may try to avoid the external voltage regulator and its capacitors by connecting 6V to the RAW pin, not to VCC pin as in the diagram!

Once the board is set, connect the circuit via USB, then compile and download the program.

The display should now show the clock and the possible options. Here are some details about the code:

  • The following line at the beginning of the code controls how many subsequent correct answers are needed before the servo will flip by 90° and thus release the lid.
#define MAX_ANSWERS 3
  • The lines 20 to 28 define the pins used for driving the display, the buzzer and the servo. They should remain unchanged as this is the configuration that corresponds to the wiring on the perfboard.
  • Line 58 initializes the random number generator with the value read from the A3 pin - which is unconnected and thus should generate a random number itself. This way, the CPU should generate different questions every time it starts.
  • The lines 65 to 71 define the colors used in the display. Change the RGB values to adapt it to your style.
  • Line 74 initializes the display. It might be the case that all colors appear awfully wrong on your device since there are different 1.8" displays with (slightly) different driver chips on the market. If the display looks strange, try to change "INITR_BLACKTAB" to "INITR_GREENTAB" or "INITR_REDTAB" here.
  • The lines 79 to 87 play a four-tone intro sequence on the buzzer after power-on.
  • Line 89 calls createTimesAndPaintClock() which does what it says: it generates a random time, paints the clock and displays three wrong and one correct option.
  • The lines 91 and 92 will drive the servo to 0 degrees which should be the position where the flap is up and hence the lid is closed.
  • The loop() function waits for any button to be pressed. A correct answer will be honored by a positive sound, a wrong answer will force a negative sound. In either way a new question is generated in line 169.
    After three correct answers in a row, line 149 will flip the servo to 90 degrees, opening the lid. Now, the system waits in line 150 for any button to be pressed again. If that happens, the lid is expected to be in closed position again, and the servo will flip its flap now to the locked position again. After that, the entire "game" will begin from start again.
The was a small bug in the original software when I made the video, so after giving three correct answers it still displayed "2/3". This is corrected in the attached .ino file... ...but not in the video.

Printing

Printed_Parts.jpg

Print all attached STL files once. The settings are not of much relevance here; I have printed everything with a rough layer height of 0.3 mm using PLA. main box and the lid are the biggest parts. They can be easily substituted by other constructions, i.e. by a ready-made plastic or wood box with a sliding lid - as long as you can screw-mount the other parts to it and manage to cut the slot for the servo-flap in the lid.

Hint: Do not use white material for the front if your build plate is not absolutely clean.This is the reason for the brown/black stains that are visible in the video.

Assembly

Assembly.jpg
Assembly_001.jpg
Assembly_002.jpg

Assembling the single parts can be done in different ways. I propose the following sequence:

  1. Take the perfboard and screw it to the Perfboard Fixture using 4 M2x8 screws (or M2x10/12) and 4 M2 nuts.
  2. Push the cable from the battery pack through the hole on the left side of the Main Box (from outside to inside). Then, push it through the front hole of the Main Box (from inside to outside). Now, connect it to the terminal on the Perboard. Please check the orientation of the cables for correct polarity!
  3. Put the bigger flap that is shipped with the SG90 Servo on its axle. Guide the cable through the front hole of the Main Box (from inside to outside, and connect it to the perfboard. Please switch on the perfboard now and check that is placed upwards (= locked position) before fixing the flap screw. Afterwards, mount the motor on the left side of the Main Box using 2 M2x8 screws and 2 M2 nuts.
  4. Take the printed Buttons and check whether they slide smoothly through the four holes on the front of the Electronics Case. If they are not running smoothly, sand them as long as they move without noticeable resistance.
  5. Hold the Electronics Case in one hand with the front facing downwards. Push the Buttons through their holes and place the Perfboard with the Perfboard Fixture on top. Now, place Perfboard Support above the fixture. You can now push 4 M4x30 screws through the outside holes of the Electronics case, the Perfboard Fixture and the Perfboard Support (as shown with the first screw in one of the photos).
  6. Put this stack on a table and place the Main Box on top. Use 4 M4 nuts to fix it.
  7. Screw-mount the Battery Case - Upper to the Main Box using 2 M3x8 screws and 2 M3 nuts. Push-in the battery box (...which is not shown in the pictures...). Finally add the Battery Case - Lower and fix it with the remaining 2 M3x8 screws and 2 M3 nuts. Make sure the switch of the battery box fits the slot on the Battery Case - Lower part.

Done! But wait... something is missing: the lid! So please go on with the next step.

Operation

Clocks copy.jpg

After power-on, a short welcome sound will presented as you can hear from the video. At a first run, you must now answer the "clock question" three times yourself. The number of correct given answers is displayed on the top right. If you press the correct button, the "digital" time above the button will be marked green and the piezo makes a "positive" sound. If the answer is wrong, it will be marked red while the correct answer will be marked green, and the piezo will make a "negative" sound. In the case. the counter will reset - there must be three correct answers in a row to open the box. Once these three correct answers are given, the servo will "flip its flap", and thus it will unlock the box. Open the lid, fill in some "motivator" (candy or similar), and move the lid to the closed position. The slot must be over the flap now. Push any button, and the flap will flip again, locking the box.

Done. Now it is time to hand it over to the "target person"! Have fun!

In the end, I would like to admit that this attempt might not be the most effective one for teaching the clock, because you could probably do much better "direct" teaching during the time you spend making the box. However, this tutorial might be a good starting point for any customized "secret boxes".