An Arduino Timer
Posted on Fri Jun 03 2011
My wife uses an egg timer to ration the amount of time she spends doing various activities (such as spending time in front of a computer screen). The timer is the mechanical variety, with a pretty loud ticking and a wake-you-up-from-the-dead ringing when the time expires. I'm not sure about her, but I sure found that stressful, so I decided to see if I could find an alternative solution. I had a quick look on various on-line shops for electronic egg-timers, but they all advertise "very loud alarm sound", which was not exactly what I was after. Seeing as I had some spare time this week, I decided to make her a new timer, based on an arduino card.
As I only had a short amount of time available for this, I couldn't afford to order new components and wait for them to be delivered, so I had to use stuff that I already had around the house. Fortunately I have quite a collection of 'stuff', so I was able to find:
- an arduino duemillanove card,
- a DFRobot LCD shield, which also includes some handy buttons,
- a 2-cell LiPo battery, which should give it good lasting power,
- various bits and bobs (resistors, wire, a small piezo speaker).
Putting the hardware together was very easy: just plug the LCD shield into the arduino board, and attach the piezo speaker to ground and pin 11 via a 100 ohm resistor. The more interesting part was the software. I started by making a list of requirements:
- you should be able to enter the desired time using the input buttons;
- after it's started, it should count down and display the remaining time;
- when the remaining time reaches zero, it should use a very unobtrusive manner of notifying you.
I decided to use the LCD's backlight as a first notification. Once the countdown reaches zero, the backlight starts flashing for 10 seconds. After that a short tune is played on the speaker, which is repeated continuously until any button is pressed. Pressing any button again resets the timer to its start state and the user can enter a new time and press 'go'. The whole source code is attached to this page (see below), in case you find it useful.
As you can appreciate from the picture on the right, the current look and feel is not exactly attractive (or user friendly), so the next project will probably be to build a box for it.
You can download my code here. Note: since I wrote this, the LCD library I was using has been deprecated and is not used any more with recent versions of the Arduino IDE. This makes the code included here difficult to compile, so its main use is probably pedagogical.