Introduction: Alarm Clock Using Atmega-328 and RTC
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.
- 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.
Step 1: Parts List
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)
6. FT232RL FTDI Breakout Board 5v or USB TO TTL Serial Adapter ( To program atmega328 )
8. Slide Switch (x2)
9. Push Button Switch
10. 16MHz Crystal Oscillators
11. 0.1uf Capacitors (x4)
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
21. Nylon Spacers
23. Power Jack
24. Power supply 7v-12v
25. CR2032 Button cell
• Soldering iron
• Wire Cutters
• Wire strippers
• Rotary Tool
• Screw Drivers
• Hot Glue Gun (optional)
Step 2: Breadboard It (connections)
• 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.
• (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.
Step 3: Solder Main Components
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.
Step 4: Solder Connections
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)
Step 5: Enclosure Cutting
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 .
Step 6: Upload Code
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.
Step 7: Setting the Clock
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.
Step 8: Setting the Alarm
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)
Step 9: Testing
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.
Participated in the