DIY Arduino Binary Alarm Clock

720

4

2

Introduction: DIY Arduino Binary Alarm Clock

About: Speedcuber and DIYer

It's the classic binary clock again! But this time with even more additional function! In this instructable, I'll show you how to build a binary alarm clock with Arduino that can show you not only time, but date, month, even with timer and alarm functions which can also be used as bedside lamp! Without further ado let's get started!


Note: This project does not utilize a RTC module, so accuracy is depend on board you used. I've included a corrective mechanism that will correct time drift over certain period of time but you will need to experiment around to find the correct value for the period of time (More on this below), and even with corrective mechanism it will still drift over long time (when compared to without one). If anyone is interested feel free to implement the use of RTC module in this project.

Supplies

5mm LED (of any colour, I used 13 white LEDs with one RGB LED as indicator) --- 14 pcs

Arduino Nano (others may work) --- 1 pc

Micro-switch --- 1 pc

Small piece of aluminium foil

Mounting board (for enclosure, but feel free to design your own)

Piece of white paper (or any other colour)

Some plastic film (the one used as cover of book)

Bunch of wires

Buzzer --- 1pc

NPN transistor --- 1pc

Resistors 6k8 --- 14 pcs, 500R --- 1 pc, 20R (10Rx2) --- 1 pc, 4k7 --- 1pc

Power supply for the project (I used li-on battery)

5050 LED strip and a slide switch (optional)

Step 1: Connect the Circuit!

I'll divide this step into :

1) The buzzer part

2) The LED panel

3) The switch (push button)

4) LED strip

5) The capacitance sensor

6) Power supply

7) Connect all of them to Arduino

Most of the time, this is just a "follow the schematic" step. So check out the schematic above or even download and print it!

Step 2: Preparing the Buzzer Part

If you have used buzzer with Arduino before, you'll know that if we connect it directly to Arduino it won't be loud enough. So we need an amplifier. To construct the amplifier, we need a NPN transistor (basically any NPN will work, I used S9013 because I got it from old project), and some resistor to limit the current. To start off, first identify the collector, emitter and base of the transistor. A little bit of googling the datasheet will work for this. Then, solder the collector of the transistor to the negative terminal of buzzer. At the positive terminal of buzzer, we just solder a piece of wire to it so we can solder it to our Arduino later. After this, solder the 500R (or any similar value of resistor) resistor to the base of transistor and from the resistor, solder another piece of wire for future use. Finally, solder the two 10R resistor in series to the emitter of the transistor and connect another wire from the resistors.

Really, refer to schematic.

p/s: I still don't really know how to pick resistor for transistor at the time writing this. The value I used is selected empirically.

Step 3: Preparing the LED Panel

Plug the LEDs and resistor into the prototyping board accordingly and solder. That's it. Follow the schematic. In case you interested with the spacing I used, 3 holes apart for each columns, and two holes apart for each row (refer to picture). And the indicator LED? I plugged it randomly.

After soldering the LEDs and resistor to the board, connect all the positive terminals of LEDs together. Then, solder wires one by one to each of the resistor at the negative terminals of LEDs so we can solder them to Arduino later.

NOTE: You might get confused this step. Remember instead of connecting all ground together, we connect all positive terminal together and negative terminal to the individual pin on Arduino. Thus we are using the Arduino GPIO pin as ground, not Vcc. In case if you accidentally connect it backward, don't worry. You can modify all the HIGH to LOW and LOW to HIGH in the ledcontrol function.

Step 4: Preparing the Switch (pushbutton Actually)

For the switch (I'll call it switch because I used micro-switch, but you know it is pushbutton), we need a 4k7 pull-down resistor and of course, the switch itself. Ah, don't forget to prepare some wires. Start off by soldering the resistor and a piece of wire to the common ground (COM) of the micro-switch. Then, solder another piece of wire to the normally opened (NO) of the micro-switch. Finally, attach another wire to the resistor. Secure it with some hot glue.

Knowledge corner: Why we need a pull-down resistor?

"If you disconnect the digital I/O pin from everything, the LED may blink
erratically. This is because the input is "floating" - that is, it will randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resistor in the circuit." -- Source: Arduino webisite

Step 5: Preparing LED Strip

LED strip is for bed side lamp, which is optional. Just connect LED strip and slide switch together in series, nothing special.

Step 6: Preparing the Capacitance Sensor

Ok refer to the picture. Basically we are just going to attach the wire to a small piece of aluminium foil (because aluminium foil can't be soldered) then tape it on a small piece of mounting board. Kind reminder, make sure you don't completely tape the aluminium foil. Leave some of it exposed for direct contact.

Step 7: Preparing the Power Supply

Since I used li-on battery as power supply, I need a TP4056 module for charging and protection, and a boost converter to convert the voltage to 9v. If you decided to use 9V wall adapter, then you might need a DC jack, or just connect it directly. Note that the resistor value for the amplifier is design for 9V and if you want to use other voltage, you might need to change the resistor.

Step 8: Connecting Them to Arduino

Follow the schematic! Follow the schematic! Follow the schematic!

Don't connect the wrong pin or things will get weird.

Step 9: Enclosure

The dimension of my design is 6.5cm*6.5cm*8cm, so it is a little bit bulky. It consist of a front window for LED display and top window for the bedside lamp. For my design, refer to pictures.

Step 10: Programming Time!

Download my sketch below and upload to your Arduino. If you don't know how to do this, don't bother to do this project! Nah just kidding, here is a good tutorial on it: Upload sketch to arduino

Then open serial monitor, and you should see it output the current time. To set the time, here is how to do this.

To set hour: h,XX -- where xx is the current hour

To set minute: min,XX -- xx is the current minute

To set second: s,XX

To set date: d,XX

To set month: mon,XX

When the above comment is executed, it should return you the value you just set. (For example when you set hour with h,15 , it should return Hour: 15 in the serial monitor.

For the capacitance sensor, you might need to calibrate it before it will work. To do this, press the micro-switch twice, and look at the serial monitor. It should output a bunch of number. Now put your finger on the capacitance sensor, and see take note of the range of the number. Next, modify the variable "captrigger" . Let's say you get 20-30 when pressed, then set captrigger to 20.

The sketch use ADCTouch library, make sure you installed it.

Step 11: Corrective Mechanism

The period of time for corrective mechanism in my code is set to the one that is accurate for me. If the time is still not accurate, you need to change the value of the variable "corrdur"

The corrdur now default to 0 in latest update.

The value of corrdur means how many milliseconds does it take to slow down one second

To find out the value of corrdur, use the formula:

2000/(y-x)/x)

where x=actual duration of time elapsed and y=duration of time elapsed of the clock, both in second

To find the value of x and y, you need to do a little experiment.

Set the time of the clock to the actual time and record the initial time (actual initial time and clock initial time should be same). After a while (few hours), record the final actual time and clock final time.

x=actual final time-initial time and y=clock final time-initial time

Then change the value of corrdur in the code and reupload to the Arduino.

Then repeat the test and this time the formula changed to:

2000/((2/z)+(y-x/x))

Where x and y is same thing as before, while z is the current corrdur value.

Upload again and do the test over and over until it is precise enough for you.

In case if your clock is still speeding up even corrdur is set to 0 (means no corrective mechanism), you need to change the second++ to second-- in corrective mechanism part of the code (I commented it), set corrdur to 0, then find the no. of millisecond it take to speed up one second.

Step 12: How to Use All the Functions

You can change mode by pressing the micro-switch.

On the first mode, it simply display time. If the indicator light flash at 1 time per second, alarm is off. If 2 times per second, alarm is on. You can snooze the alarm for 10 minute in first mode by pressing the capacitance sensor.

On second mode, it display date. Pressing capacitance sensor do nothing.

On third mode, you can set timer. Pressing capacitance sensor will turn on the timer and you should see the indicator light started flashing. Capacitance sensor is also used to set timer time. The range of timer is 1 minute to 59 minute.

On fourth mode, you can set alarm hour using capacitance sensor

On fifth mode, you can set alarm minute using capacitance sensor.

On sixth mode, pressing the capacitance sensor will reset minute to 30 and second to 0 without changing hour. That's mean as long as your clock does not drift over 30 minute, you can recalibrate it using this mode.

Seventh mode is the do nothing mode in case if the capacitance sensor glitch out when charging.

Oh, to dismiss alarm, just press the micro-switch. (LATEST UPDATE TO INCLUDE ALARM SNOOZE)

Well, how about reading the clock? It's easy! Reading Binary Clock -- Wikihow You might feel weird at first, but you will get use to it!

Step 13: Conclusion

Why I started this project. Initially it is because I have a old digital watch that lying around and I want to turn it into an alarm clock. Unfortunately the old watch turn out to be broken. So I was like why not build one using Arduino? With a little bit of google search, I found this binary clock project without RTC on instructable by Cello62. However, it doesn't have the alarm clock feature I want, so I take the code and modify it myself. And the project is born. Moreover, I saw the clock contest running on instructable recently which gave me even more motivation to do this. Anyway, this is still my first project using Arduino, so bunch of possible improvements.

Future improvement:

1) Use RTC

2) Set alarm or time or timer wirelessly!

3) Whatever feature I think of

Step 14: Update: After One Week of Use

Aside from the obvious problem - time drift, the next one I would say is power consumption. First at all, I step the voltage up to 9v, which then will be stepped down by the linear regulator in Arduino. The linear regulator is very inefficient. The clock only last for ONE DAY. That's mean I have to recharge it every day. That's not the biggest deal until you realize that the entire system is only about 50% efficient. Given that my battery is 2000mAh, I would be able to calculate the power wasted every day.

Power wasted=(7.4Wh*10%)+(7.4Wh*90%*50%)=4.07Wh a day

That is 1.486kWh per year! That can be used to boil, uh, 283g of water (from 25 C until 100 C)? But anyway, I'm going to improve the efficiency of the clock. The way to do this is to not use the linear regulator at all. That means we have to adjust the boost converter to output 5V directly into the 5V pin on Arduino. Next, to minimize the power wasted even further, I have to remove the two on board LED (pin13 and power), as they will waste 0.95Wh per day. Unfortunately, I'm totally noob at SMD soldering so the only way for me to do this is cut the rail on the board. After this, I have to remove the emitter resistor on the buzzer and the bedside lamp (LED strip doesn't work at 5V). But does that mean you have to give up that amazing feature? No! You have two choice here: Use the normal 5mm LED diode, or use 5V LED strip. But for me, I already felt tired for doing this project for entire last week, so I decided to give up this feature. However, I used the switch originally for the light feature for switching on or off the clock panel to further saving energy, but end up the LED flashing when I switch it off. Bug become feature? I don't know (Anyone know please tell me below).

At the end of the modification, the clock now last for more than 2 days!

Next up I have a less serious problem with the clock. During charging, the capacitance sensor would go crazy, so I add another mode that do totally nothing.

As for time drift, since it is very inconvenient to plug in to computer everyday to reset it, I have added another mode which will set minute to 30 and second to 0. That's mean you could reset it on half past any hour!

Clocks Contest

Participated in the
Clocks Contest

Be the First to Share

    Recommendations

    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge
    • Rocks, Gems, and Stones Speed Challenge

      Rocks, Gems, and Stones Speed Challenge
    • Plastic Challenge

      Plastic Challenge

    2 Comments

    0
    smulgaonkar
    smulgaonkar

    1 year ago

    What an amazing idea! Well done, and thank you for sharing it

    0
    The_NooB
    The_NooB

    Reply 1 year ago

    Glad you like it!