Appliance Timer with Nokia Display
This project is a follow on to the appliance timer
I built a few yers ago. Its claim to fame is the ability to turn
something on and off at dusk and dawn, using a table of on/off times
customized for your latitude and time zone. The user
interface is very simple, using a single rotary encoder, and a display
that can show up to 6 lines for setup. Timers are cheap but in
addition to numerous problems, can't do what this one does. For my list
of complaints see the previous project linked above.
This
project has two independent timers. Timer 1 uses the dawn/dusk tables.
Timer 2 is a conventional timer that may be programmed for one on and
off time, and day of week.
I needed another timer with the dawn/dusk feature. My main issue with the appliance timer was the display. The KTM-S1201 was cheap but can only display one line and the alphabetics are crude and there's no backlight. I happened to have a spare Nokia 5110, which I used in my Nokia Clock project,
so I decided to use it for this project. I'm not sure this display is
still available, but it's not too hard to rework a project to use a
different display, which was the main thrust of this project.

The project uses an ATmega88PA running at 3.3V, since the Nokia dsplay is limited to 3.3V. The real time clock is a NJU6355 which I have used before. It has a coin cell battery for back up; in this case I used a common CR2032.
The
only control is
a rotary encoder/pushbutton. Once set up, the unit displays the time in
12 hour format. Turning the knob either way turns the attached
appliance on and
off. Pushing the button puts you in setup mode, where a menu is
displayed and managed by twisting the knob and pushing the button. You
can set the on time, off time, set the clock, and so on.


The rotary encoder is a EC11-1B-18T. It is very similar to the CTS series 290 rotary encoder. More information on this part can be found on my rotary encoder
page. The relay is a standard 5VDC unit with SPDT contacts, although
SPST is all that is needed. I used a 5VDC switching type wall wart
power supply, which I extracted from its case and placed on my circuit
board (bottom); however there's no reason that the external wall wart could not
be used instead. 5 Volts drives the relay, and the rest of the project runs off of 3.3V.
There are two operating modes, Run and Setup. When powered up the display shows the time
in HH MM DD (12 hour) format and the unit is in Run mode. If you twist the knob,
the appliance/load switches on and off, as a manual override. If you push
the button, the program goes into Setup mode and displays the main menu Twisting the knob moves up and down on the menu.
Pressing the button selects the menu item for further processing. The
menu items are:
� Run - pressing the button returns you to run mode.
� Set Clock - You must do
this once to set the RTC. With each push of the button you can set
year. month, day, day of week, hour and minute. After the final button push the time is set
with zero seconds.
� Timer 1 - This option takes you to another menu where you can turn timer 1 on or off.
� Timer 2 - This goes to a dialog where you turn timer 2 on or off, and set the start and stop times and day of week.
� Clk Test - This
puts the NJU6355
into its "Frequency Checking test mode" where it
outputs its clock signal on the DATA pin. This is very handy for
testing the frequency of the RTC, which should be very close
to 128 kHz. There is more information here. There is no return from this mode except to power cycle the unit.
Although
the clock time is displayed in 12 hour format, internally all
hours are in 24 hour format and the clock time and timer 2 must be programmed
correspondingly. Note that the day of week is 1 for Sunday, 2 for
Monday, etc., and when programming timer 2, 0 means "all days". This is
handy if you only want the timer to activate on a specific day of the
week.
Look for the preprogram tables in function set_current_programmed_on_off_times(), module main.c.
There are four tables, ucOntimeHH, ucOntimeMM, ucOfftimeHH, and
ucOfftimeMM. Each table contains 52 entries, one for each week of the
year. Unless you live in Toronto, Ontario, the times in the tables are
not suitable for you and must be changed. I used the US Naval Observatory data services
to generate a chart of sunrise and sunset times for an entire year for
my location. I then used each 7th entry in the chart for my on and off
times table, with a small adjustment. I wanted the timer to turn on 10
to 15 minutes before sunset, and off 10 to 15 minutes after sunrise.
Keep in mind that the times do change a bit in the course of a week,
and overcast days appear to have less daylight than clear days. All
the times are in Standard Time; elsewhere the program checks
for Daylight Time and adjusts the hour as required. The program is
coded for Eastern Time; for other time zones a few more tweaks are
required in the code. You will then have to rebuild the project.
I used AVR Studio 7.0 and WinAVR GCC,
both freely available. Create a project with my .c and .h files. Select
ATMega88PA as the processor and build.
The
program stores important runtime state variables in EEPROM, so that if powered
off for any reason, it will come back on in the same state. The RTC
remembers the date and time, as long as the battery is good, which
should be quite a few years.
When
setting the clock you set the date as well as the
time, so the RTC knows the date. (The project does not display the
date, but needs to know the date to do its thing.) I use the date
to calculate when Daylight Savings Time (DST)
kickes in and out, in order to adjust the preprogram table
times so the relay turns on at the desired time. Later I realized
I could use that information to automatically adjust the clock so it
did not have to be done manually twice a year. It is hard coded for
Eastern Time, North America. If you implement this project elsewhere,
look at the code in the calendar.c routine and make the necessary
adjustments. DST is a big Pain in the Ass and in my opinion serves no
useful purpose except to confuse and inconvenience people, but you have
to live with it.
Download C
source code for the timer
Back
to VE3LNY's AVR Project Page