It could have a variety of uses, in this use, it just needs to count down from a preset number of minutes to zero, and sound a bleeper.
I could go out and buy something for little money, but where's the fun in that?
I'm also interested in Arduino sleep modes, so it'll be interesting to play about with that too, to increase battery life.
The sketch can be found at https://github.com/andydoswell/Timer
I've also included the library for driving the TM1637 display, which is by Bram Harmsen
and can also be downloaded from https://github.com/bremme/arduino-tm1637
Let's have a quick look at the hardware...
A momentary push button is connected to D2. A BC337 (or almost any general purpose NPN transistor) is connected to A3, which is used to switch power on by grounding the GND pin of the TM1637 "light tube" 7-segment LED display. DIO and CLK of the TM1637 are connected to pins 10 and 11. The output of the pot is connected to A0, and the "hot" end connected to D13. Power by way of 3 AA cells, is supplied to the VCC pin of a pro-mini. A piezo beeper is connected to D3.
How the sketch works...
In normal use, the microcontroller is asleep. It's woken up from it's slumber by an interrupt going low on D2. Power is then switched on to the display, by taking A3 high, which switches on T1, and connects the display GND pin. D13 is then taken high, which switches on power to the pot. The pot position is sampled by A0, and used to define the number of minutes the timer is required to run. After a few seconds, D13 goes low, saving us a few precious uA! The timer begins to count down, displaying the value in remaining minutes and seconds on the display. Once the timer gets to zero seconds remaining, the display flashes and the beeper sounds to alert the user the time has expired. Once this is complete, A3 goes low, disconnecting the display, and the micro goes back to sleep.
Power consumption is about 45mA when it's running... and a super-low 200uA when asleep. The batteries should have a good life.
I did remove the voltage regulator on the pro-mini, as initially I was going to use a 3.3V unit, and the regulator burns a few mAs even when the micro is asleep, but it's unnecessary. There's no difference in the microcontroller, so why bother? Just feed our 4.5V into VCC... Despite the light-tube stating it needs 5v, it seems happy right down to 3.3.
At the moment this project meets my requirements for use. I'm going to build a new ultra-violet light exposure box shortly, and I'll modify this to drive a relay to automatically control exposure time.