Thursday, March 28, 2024

Multifunction Rechargeable Clock

Microcontroller code

The code for the ATMEGA8 microcontroller is written in BASIC language using the BASCOM-AVR compiler from MCS electronics. Initiating the code, we allocate default values to the eeprom from location 1 to 4.

The eeprom is basically used to hold the user settable alarm values. Starting from first location holds the alarm hours, then alarm minutes, then alarm PM and at last the alarm flag which indicates whether alarm is ON or not.

Then we declare some subroutines to clear seven segment displays, reading RTC chip, display value setting, etc. After this, we configure the ADC to run in single mode with auto prescaler and using internal 2.56v reference. We configure the directions of input-output ports and initialize them. The I2c pins are configured and initialized.

Then we initialize timer0 for multiplexing the seven segment display, timer1 for handling alarm duration and timer2 for blinking the segments while the clock is in “Settings” mode.

After this we declare and initialize certain variables for ADC calculations, time seeking, etc. Doing all that, now we initialize the I2c pins, read the eeprom contents for alarm values and initiate an infinite loop where the RTC chip is read and displays are updated continuously.

- Advertisement -

Also in the same infinite loop, the user inputs are acknowledged and associated event are initiated like setting alarm ON/OFF, displaying date-time, etc. Also, the current time is compared against the alarm variables and alarm is initiated when the time is matched.

It is important to note here that while burning the hex file “solarclock.hex” to the microcontroller, the eeprom file “solarclock.eep” must also be programmed to the microcontroller.

Using the clock

The clock can be charged from solar power as well as mains power. A 10-12v, 7 watt rated solar panel should be installed on top of the roof in such a direction so that it can receive enough power throughout the day. The connections from the solar panel should be carefully routed to the clock charging terminals keeping in mind the correct polarity. Although solar power is more than enough to provide continuous power to the clock forever, and the clock can last for more than 60 hours on single charge. But during peak times when solar power is not available like in cloudy days or night, user can charge the clock using mains power.

- Advertisement -

The solar panel is automatically cut-off while charging through mains power. This way the clock will never ever run out of power. The mains load switch can be used to cut-off all the load from the battery. The two 3 x 1watt LED modules can be individually switched ON according to the needs. And using the USB jack, user can charge all possible USB applications thus the project also functions as a solar powered USB charger. The charging status is indicated by LED1 in the power unit, where glowing LED means the battery is being charged. The power unit circuit has the feature to automatically shut-off the load when the battery voltage reaches the state of discharge.

The clock will automatically switch ON after switching ON the mains load switch. The user interface of the clock is designed in such a way that only three buttons are used to set the various parameters like current time, hours, date-time, etc and to display the current date-time, set alarm, room temperature, etc. It is to note here that the “PLUS” button can be used to increment the values in “Settings” mode. Also pressing it once during normal time display mode, first displays the room temperature and then the set alarm values. After that, it reverts back to normal time display with an acknowledgement beep.

Similarly the “MINUS” button can be used to decrement the values in “Settings” mode. Also pressing it once during normal time display mode, first displays the current date on left and current month on right, and then the current year. After that, it reverts back to normal time display with an acknowledgement beep. To switch ON/OFF the alarm, simply press the “MINUS” button for more than 1 second, and if the display indicates “AL-0” means alarm is turned OFF while “AL-1” means alarm is turned ON.

To set the various parameters of the clock, pressing “SET” button once will bring it into settings menu. In the settings menu, “PLUS” and “MINUS” keys are used to increment and decrement the current value respectively and the corresponding pair of seven segment displays will start blinking. Pressing the “SET” button again will bring the clock into next parameter setting mode and so on until the normal time is displayed. On pressing the “SET” button once, the following seven setting are noticed which can be changed by the user:

1. SET CURRENT HOURS
( AM/PM can be set by overflowing/underflowing the hours)

2. SET CURRENT MINUTES
(After setting the current hours and minutes; “SET” is displayed on the display)

3. SET MONTH

4. SET DATE

5. SET YEAR
(After setting month, date and year; “SET” is displayed on the display)

6. SET alarm hours
( AM/PM can be set by overflowing/underflowing the hours)

7. SET alarm minutes
(After setting alarm hours and minutes; “SET” is displayed on the display)

To switch off the running alarm anytime, any of the three buttons can be pressed once. Green color on the RGB LED indicates AM, blue indicates PM and red indicates that date is displayed.

Download source code: CLICK HERE


7 COMMENTS

SHARE YOUR THOUGHTS & COMMENTS

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Calculators