Alarm Clock Using Atmega-328 and RTC

by tharindurc in Circuits > Clocks

16658 Views, 57 Favorites, 0 Comments

Alarm Clock Using Atmega-328 and RTC

562f24ea4936d424380001ed.jpeg
562f275350e1b6c1fd0001e8.jpeg
Hi everyone! This is my first instructable! After reading hundreds of instructables, I decided to make one myself.

Clock is one of the most essential house hold things. There are various types of clocks like good old Pendulum clocks, Analog clocks and the now trending modern Digital clocks.

Digital clocks has many advantages over the analog clocks like the Accuracy in time, easy reading of time when compared to analog, visibility even in darkness and so on...

Here a Alarm clock is presented which is built using simple Atmega-328 microcontroller and DS-1307 RTC which is a time keeper which keeps the time even when there is a power failure.

Features:

- Remember the time after a power failure.

- Sound an alarm at a predetermined time, without having to be "armed" each day.

The program is written to ring the alarm each day at 5.00 am (this can easily be changed in the code). Once the alarm is cancelled by pressing the cancel button it re-arms itself an hour later, ready for tomorrow.

- Keep ringing for 5 minutes until you get out of bed to cancel it.

The program rings for 5 minutes (the time is configurable) to make sure you wake up. By physically locating the clock some distance from the bed you ensure that you have to get out of bed to shut it up.

- Flash a LED to help locate the "cancel" button in the dark.

The LED next to the button flashes brightly to help you find it in your sleepy state.

- Be able to cancel the alarm function during holidays.

A slider switch lets you disable the alarm during holidays.

- Handle Daylight Saving Time easily.

Another slider switch adds an hour to the time as read from the clock chip. Thus you simply slide it across at the start of Daylight Saving Time, and back again at the end.

- Dim the display at night.

Between the hours of 9 pm and 6 am the digits on the display are dimmed (by reducing the duty cycle of the pulse-width-modulation). This makes them unobtrusive when you are trying to sleep.

-Only sound on Monday to Friday (school/work days).

The code can determine the day of the week from the clock chip, and thus only sound the alarm on weekdays. This saves the problem of turning the alarm off on the weekend, and forgetting to turn it back on on Sunday night.

Parts List

56220d504936d4e5da000f60.jpeg
5622110445bceb580400095e.jpeg
56220e0745bceb5804000951.jpeg
562f11cc15be4d14a6000055.jpeg
56220cb34fbadec0430011a1.jpeg
5627216615be4d491d0013c5.jpeg
5620764467400cf062000351.jpeg
5621048a67400c489e000239.jpeg
56207aa215be4d7528000d7b.jpeg
56220ee22e7fb67d550007ec.jpeg
5620734767400c489e0000e7.jpeg






1. Atmega 328p
2. 4-Digit 7-Segment LED Display ( Common Anode kyx-5461bx)(Data sheet available in third step)
3. 28 Pin IC Socket
4. DS1307 RTC ( real time clock)
5. LM7805
6. FT232RL FTDI Breakout Board 5v or USB TO TTL Serial Adapter ( To program atmega328 )
7. Buzzer
8. Slide Switch (x2)
9. Push Button Switch
10. 16MHz Crystal Oscillators
11. 0.1uf Capacitors (x4)
12. LED's
13. 1uf Capacitor
14. 22pF Capacitor
15. 270 ohm Resistors (x12)
16. 10k ohm Resistor
17. 220 ohm Resistor
18. Female Header Pins
19. Male Header Pins
20. Perfboard
21. Nylon Spacers
22. Enclosure
23. Power Jack
24. Power supply 7v-12v
25. CR2032 Button cell
26. wires


Tools:



• Soldering iron
• Wires
• Wire Cutters
• Wire strippers
• Rotary Tool
• Screw Drivers
• Solder
• Hot Glue Gun (optional)
• Multimeter


Breadboard It (connections)

Alarm_clock_schematicb.png
fritizing.jpg
Atmega168PinMap2.png
4_dight_7-segment_common_anode-3.jpg
lm7805circuit-1.png
IMAG0030.jpg
LD-5461AS.png
IMAG0071.jpg
IMAG0072.jpg


• Lets take a step back and just make the circuit on a breadboard. I'm going to assume you can read a schematic, but if you can't,click here for a reference. Also I have attached Fritzing circuit diagram if your not familiar with circuit symbols .


I've used a Arduino uno for bread board testing , instead of the atmega 328 chip.

Connections :



• (270 OHM) in the 7 segment led connection list means a 270 ohm resistor must be connected in series with the led pins,this will ensure the led digits will only light up at the same brightness level.

• Day light saving (DST) switch to - DIGITAL PIN 11 (PB3)
• Alarm On/Off switch to - DIGITAL PIN 3 (PD3)
• Alarm Cancel push button switch to - DIGITAL PIN 2 (PD2)
• Buzzer to - DIGITAL PIN 1O (PB2) & DIGITAL PIN 9 (PB1)
• Indicator LED to - DIGITAL PIN 8 (PB0)





*COMMON ANODE LED OR COMMON CATHODE LED CAN BE USED*. IF YOU ARE USING A COMMON CATHODE YOU NEED TO ALTER THE CODE CHECK STEP 05.

Once you finish breadboarding we can begin making out alarm clock.

Solder Main Components

5624f25515be4d491d000521.jpeg
5624e3bf45bceb3cfa00016e.jpeg
5624e3fe937ddb0c04000d29.jpeg
5624e4b7937ddb0c04000d2f.jpeg
IMAG0056.jpg
IMAG0088_1.jpg
Let's begin by soldering our main components to our perfboard. Before you solder, make sure to leave enough room other parts and wire.Using a IC socket is much better than directly soldering the ic , because it is easier to remove the IC if it has been damaged. I like to use masking tape to hold the components in place while soldering . i am using header pins to connect 7seg led , rtc module and FTDI breakout board or USB TO TTL Serial Adapter (USED TO PROGRAM THE IC) to the perf board.

Solder Connections

IMAG0089_1.jpg
562721e7937ddb4603000c67.jpeg
562721f215be4d1f730007e8.jpeg
5627220445bceb4151000232.jpeg
IMAG0081_1.jpg
562722194fbadecd4400077d.jpeg
IMAG0083_1.jpg
Using the attached schematic (see step 2) connect the 7SEG LED,RTC module , Programmer header pins, Buzzer, Crystal oscillator ,Indicator LED, Power regulator and Switches to the appropriate Arduino pins. In case you have difficulties reading a schematic, i have attached a note file of connections in step 2 and a fritzing diagram.

LED to atmega328 connections are white

Ground connections are black

Vcc connections are red

FTDI and RTC connections are silver ( solder lines)


Enclosure Cutting

562a2e0f2e7fb622e1000021.jpeg
562c4f7e15be4d89b5000b17.jpeg
562c4ded15be4d89b5000b0a.jpeg
IMAG0108.jpg
562a35cd50e1b67c7300036d.jpeg
IMAG0099.jpg
562a358550e1b697f7000b67.jpeg
IMAG0113.jpg
562c4e162e7fb65244000d99.jpeg
562a346b4936d48757000081.jpeg
562f1a734fbadeb2fe0001d3.jpeg
562c4e6a937ddb5c1a000a63.jpeg
562c4d394936d487570004e7.jpeg
IMAG0112.jpg
IMAG0105.jpg
I always cover the enclosures with decorators tape to protect it while drilling and cutting it. It also helps the marking procedure as it is a lot easier to mark on the tape than on the plastic.

Just make sure your components will fit before this step.

My cuts are are not the best , but hot glue will do the job of holding the pieces inside the enclosure .

Upload Code

Arduino_Logo.svg_.png
CODE.png
led change.png
Uploading:

Connect an FTDI cable to the board. The exact board type to choose in the Arduino IDE depends on what bootloader you have flashed onto your chip (if any). In my case I had the uno bootloader, but some might come supplied with the Duemilanove loader, or none at all , if yours does not have a bootloader click here to learn how to burn the uno bootloader to the chip using a arduino uno.

please refer to this link to learn how to install FTDI drivers .

If you have a COMMON-CATHODE LED, just change the constant COMMON_ANODE to be FALSE rather than TRUE in the sketch.(check the picture).

My ftdi programmer got bricked so i used USB TO TTL Serial Adapter instead they both work in the same way but ttl programmer is less like to get bricked . unless you are using board that does not have a counterfeit ftdi chip.

when uploading to the board remove the led then plug it back again.

Setting the Clock

timer-hi.png
setting the clock.png
If your clock chip has not been set correctly, install the battery first, then set ADJUST_TIME in the sketch to True, recompile and quickly upload it.That will set the time in the clock to the compile time.

Then change ADJUST_TIME to False , recompile and re-upload. If you don't do that every time you power on the board the time will be reset back to the last compile time.

Setting the Alarm

images.jpg
alarm change.png
To change the alarm simply change the part show in the picture to your preferred alarm time. The alarm time in the code is shown 24 hour format. But the displayed time is in 12 hour format .

what days for the alarm to ring can be changed in the code .(false = alarm off) (true = alarm on)

Testing

562f1e9050e1b6e1430003fc.jpeg
562f1c4d45bceb59d50003e6.jpeg
562f1ce350e1b6e1430003f8.jpeg
VIDEO0014_0000006712_1-01.jpeg
On power-up the clock should show "-AL-" for 2 seconds, followed by the currently-set alarm time (to confirm what you had it set to).

If the alarm switch is OFF it will then show "OFF". After that it should show the current time, with one of the decimal points blinking every 1/2 second.If the alarm is on the LEFT HAND decimal point will light up.

If the time is 12 midday or later the RIGHT HAND decimal point (PM) will light up.

Between 9 pm and 6 am the display will automatically dim.

You can test the alarm, if the alarm switch is in the "on" position, by pressing the Cancel button. That forces an alarm test. This lets you check that the buzzer is working, and its volume. Press the Cancel button again to cancel it.