The circuit hardware is practically the same as the one we used for the “calendar clock with PIC 16F873A”; we have added a switch, a resistor, a trimmer and a transistor connected to a buzzer which will sound the alarm.
The program engraved in the PIC serves to read seconds, minutes, hours, day and month of the year with the “two threads” bidirectional bus I2C, the data of the integrated circuit DS1307. The above mentioned circuit is a Real Time Clock, which starts counting the time from the moment we start it.
In other words, we adjust the hour, minutes, seconds and the data, we communicate it to DS1307, we start it, and from there the microcontroller PIC 16F873A reads the data that the integrated circuit DS1307 sends it each second. Here you have a datasheet of DS1307.
The battery connected between the terminal 3 and the negative terminal is a battery model CR2032 which makes sure that the clock goes on ticking even though the power supply of the circuit stops.
This battery should be made of lithium and we’ll change it, just to make sure, each 5 years approximately to guaranty that the clock keeps functioning it there is a power cut. DS1307 is highly stable and precise.
It’s precise because of the quartz connected to its terminals 1 and 2. We have measured the differences and they are about 10 seconds a month, or two minutes a year, which is not bad at all. The integrated circuit DS1307 has in its memory the years of this century until a year 2100, including the leap years, of course.
The switches S1 and S2 are used to adjust the clock. The adjustment is a simple one. First time when we turn on the circuit we will see the hour 00:00:00 and the data 1/1/2011. We press the switch S1 during one second approximately, marked as SET in the scheme, when we remove our finger we shall see the word SET on the screen and the cursor below the hours to adjust it.
We press S2 and we can advance the hours. Then we press S1 again and the cursor will be placed in minutes, we adjust it with the cursor S2 and we repeat the movements until we adjust everything.
After adjusting the year in the end, we press S1 again and send the data of our adjustment to DS1307, we shall see “OK” on a display, and from then on the clock will begin to count.
The alarm function we have added in this assembly works like this: if we press S3, we’ll see the screen “ALARM”, where we can adjust the hour of the alarm. The alarm is made for a wake-up call, that is, we can program it for the following day.
Once we press S3, a cursor will appear below the hours; by pressing S2, we can adjust the hour of the alarm. If we press S3 again, the cursor will be placed below the minutes and now we can set the minutes with S2; by pressing S3 for the third time, the cursor will be placed below the letters “OFF” and with S2 we can turn the alarm on or off.
Finally, pressing S3 once more we leave the alarm screen, saving it in the microcontroller and while exiting we’ll notice the letters “ALARM OK” on the screen. If we have set the alarm to “ON”, on the “clock” screen, on the lower right margin, we will notice letter “A” for the alarm, and that means that our alarm is activated.
If the “ALARM” is set on “OFF” we won’t see anything in the display’s lower right margin. When the clock comes to the alarm time, the exit in PIN 16 (RC5) of PIC 16F873A will be placed in the higher level (+5V) by intervals and this will make the buzzer start ringing repeatedly.
We have connected a resistor to the PIN 16 of PIC, and we have connected a transistor to resistor which will alert the buzzer and it works when we put a 5V voltage to its extreme ends (if you can’t find the 5V one, the 6V one will also do the trick). The 1K trimmer serves to lower the buzzer’s volume, if it’s too high.
To turn off the alarm, a letter “A” of the alarm situated in the lower right margin will disappear and the alarm function will remain “OFF”.
If we haven’t pressed S2, the alarm will sound during one minute and then it’ll turn off, but the alarm will sound again tomorrow at the same time and the “A” will continuously appear on the lower right margin. An important function that we have added is a “memory” of the hour and the state of the alarm in the case of the power cut.
If the circuit turns off because of the power cut, the hour won’t be modified when we turn on the circuit again with the battery placed between the PIN 3 of DS1307 and the ground of the circuit, and the alarm hour will also be remembered since it’s saved in non-volatile memory of the PIC 16F873A.
The electric scheme is quite simple. It is composed of the microcontroller with its associated components, 4Mhz quartz with its 22 pF capacitors, a 10K resistor between the PIN 1 and the positive pole of the power, two switches connected to the two entrances RC2, RC3, RC4, and the 4 bits data bus to manage the display.
The 16F873A connection with the DS1307 integrated circuit is made by an I2c bus with the RC6 and RC7 ports from microcontrollers to the pins 5 and 6 of the integrated circuit DS1307.
It will be visualised on a LCD display 2x16 (as long as it is a display with the Hitachi controller HD44780 or compatible one, with the datasheet of a Hitachi controller HD44780).
The LCD display contrast (V0) is made by the 10K adjustable resistor R2 with its extreme ends connected respectively to a positive and negative pole. Our screen has a back light, so the LED or LED-s which illuminate it is regulated by a variable resistance R3 (470 ohms).
The resistance R4 protects the LED-s and prevent that they consume more energy than necessary, which could lead to their imminent destruction.
We have completed our alarm clock with the temperature sensor, based on the digital probe DS18B20, if you need more information on this probe, have a look at our in/out thermometer with PIC 16F9873A.
The mentioned probe will provide us the room temperature in Celsius with a tenth of a degree centigrade precision. The visualisation of the temperature is placed in the upper right part of LCD display.
The circuit is empowered with 5 volts of direct current and its consumption won’t be over 100mA with the LCD display light turned on; therefore, the power source, which will remain on for 24 hours a day, 365 days a year should provide us with 5V and 200 mA.
According to the datasheet DS1307 the body of quartz crystal is to be connected to the ground and its terminal as close as possible to the pins 1 and 2 of DS1307, as you can see in the photo.
Detail of the date, hour and temperature (the alarm is activated).
Detail of the set screen of the alarm.
The file to download is compressed, to extract it, you should enter a password: www.kemisa.es
The .hex code is a program that you have to engrave in the microcontroller 16F873A, which is necessary for the circuit to function.
If you do not know how to program microcontrollers click here.
If you don´t know how to make a printed circuit boards click here.