Sunday, August 29, 2021

Programmable Timer Using an ATtiny45

I've been wanting to be build a simple timer ever since I got my amateur radio license a few years back.  FCC regulations state that your call sign must be transmitted at the start and end of each transmission and at least once every ten minutes during a call.  My original idea was to use a simple 555 timer to drive a binary counter which would activate an LED upon timeout.  I toyed around with it for a couple of years and had a circuit sketched out but never followed through with it for various reasons.  Fast forward to 2021 when I came across a project someone had created using an ATtiny85 microcontroller.  I'd never heard about these devices before but immediately thought it would be a perfect solution for my timer.

The ATtiny series of chips are 8-bit microcontrollers that fit within an 8-pin DIP footprint.  The ATtiny45 is the one I decided upon using. It has 4096 bytes of flash memory for holding a small program, 256 bytes of EEPROM, 5 useable I/O pins, interrupt capability, etc., etc.  In other words, a very powerful little device contained in a very small package. Another nice feature is its ability to work down to 2.7v.  This allowed me to use a single, 3v coin cell battery as my power source.

Because of its capabilities I decided to expand on my original idea of having a fixed timing function.  The result is a timer that can be programmed from 1 to 255 minutes while driving 2 LEDS.  The countdown function begins when the "timer" button is momentarily pressed.  A green LED then comes on briefly at the top of every minute to indicate countdown activity.  When the elapsed time gets down to 30 seconds the green LED starts flashing on and off.  If, during the countdown period the "timer" button is pushed again, the countdown event starts over.  Otherwise, upon timeout, the red LED comes on.

To set the time, the "timer" button is pushed and held in.  The green LED will then flash on and off representing the number of minutes to countdown for future timing events.  When the button is released, the minute value is then stored in nonvolatile memory (EEPROM) for future reference.

The entire program only occupies 802 bytes of memory.  One other nice feature I included was a clever power on/delayed off circuit I discovered on a YouTube video (Power On Off Shutdown).  It uses a momentary pushbutton, and two MOSFET transistors (along with the ATtiny45).  Push the button once and power is immediately applied to the chip.  Push it again and power is removed after a short delay to allow for processing of any internal housekeeping tasks.  In my case, when I detect a power down request, I flash the red LED twice as an acknowledgement then shut down.

I used EasyEDA software for laying out the circuit board and had the board manufactured by JLCPCB. The board arrived in about a week.  I built the enclosure from pine which I hollowed out to hold and secure the battery.


The "brains" of the timer