In this project I plan to design and build a kitchen timer. We don’t have one in our kitchen and it feels like the perfect project for a hot August weekend. I’m writing this blog post while I’m building the device, hopefully this will make it more interesting as I’m sure I’ll come up against some problems and this will document solutions that I find.
The basic requirement is a device that allows a countdown timer to be set, for a certain number of minutes and seconds, after which the device audibly and visually alerts that the countdown is complete.
Stage 1 – Brainstorming ideas
Firstly – let’s brainstorm the key components that we know will be used in our device.
Clock – a display showing visually how many minutes/seconds are left in the countdown
On/Off switch – a switch that turns power to the device on and off
Several buttons to set mode / start and stop timer
Speaker – for an audible alarm at the end of the countdown
Lights – for a visual alarm at the end of the countdown and to show the mode status
Battery pack – to power the device as it needs to be portable
Project box – the device needs to be contained inside a small box which can survive in a kitchen setting
This will be my first portable device. I have some Lithium ion polymer batteries and charging modules, so I can use them along with a step-up convertor to get a steady 5 volts for my microcontroller. All my previous devices needed to be connected to a USB socket, so this will be an exciting step forward for me.
Stage 2 – Determining user actions
Next – let’s list the actions that the user will want to execute when interfacing with our device. Once we know these we can determine what physical controls our device needs.
Power on – give power to the device, start it up
Power off – cut power to the device, turn it off
Start timer – begin our countdown timer
Pause timer – pause our countdown timer
Reset timer – set the timer to 0
Increase countdown mins – adjust the countdown timer on the device
Increase countdown seconds – adjust the countdown timer on the device
Decrease countdown mins – adjust the countdown timer on the device
Decrease countdown seconds – adjust the countdown timer on the device
Stage 3 – Mapping controls to actions
Now – let’s decide how our physical controls can initiate those actions.
Power on – turn power switch to the right
Power off – turn power switch to the left
Start timer – press a button
Pause timer – press a button
Reset timer – hold down a button
Increase countdown mins – rotary encoder turn right
Increase countdown seconds – rotary encoder turn right
Decrease countdown mins – rotary encoder turn left
Decrease countdown seconds – rotary encoder turn left
When creating an MVP (minimum viable product) we should try to limit the number of physical items as much as we possibly can. Every additional button will make our device more complex to build, and increase the risk of problems occuring.
I will be using an Arduino Nano compatible device. I’m sure many kitchen timers out there don’t use microcontrollers as powerful as the ATmega328 on an Arduino Nano board, for sure it’s overkill, but from a hobbyist’s point of view it’s much cheaper and sensible to use a $3 Nano than attempt to use several more specific ICs and transistors along with a custom PCB.
Basically, yes if you were to design a device for mass production you would not base it on an Arduino Nano. For a hobby project with limited production numbers this is the way to go.
Stage 4 – Planning the code
Now let’s write some pseudo-code to figure out what we need to do on the ATmega328 processor.
- Reset state to set timer – when you turn the device on, it should be ready to set-up
- Reset state for ‘what we are editing’ – we will start by editing minutes
- Set pins to input/output where required – ready to send or receive messages
Initialise any additional libraries we will use – we will use 3rd party libraries to speed up development
If the rotary encoder button is pressed – change what we are editing – from the minutes to the seconds and back
- If the rotary encoder is rotated – change the number we have for minutes/seconds – up or down depending on the direction the encoder was turned
- If the button is pressed change our state from setting the countdown timer start time to running the countdown, if we are in countdown mode, pause the countdown
- If the reset button is pressed, return us to the set timer mode with the countdown we started from
- If we are in the countdown mode – reduce the time if a second has passed.
- If we are in the countdown mode – If the time runs out, then make an audible sound and set state to end
- If we are in the end state keep making a noise until the device is reset
The question here is, how many buttons do we need. We could make do with one button, with the device resetting if the user holds the button down for several seconds. As I want to limit the amount of physical items for this MVP version, I will stick to one button.
Stage 5 – Building a prototype
The next step is to create a prototype, on which we can write the software and confirm that we are capable of developing such a device, before constructing too much in the way of hardware. We can see how the device functions and if we need to make further hardware adjustments.
As you can see I have constructed a prototype on a breadboard. I’m using a smaller display and a different type of button. Before doing any actual construction of the device it is critical to know that it will work. It’s much easier to add/remove buttons/components now than do it with the device half built!
I built the prototype one component at a time, and I highly recommend this course of action. Firstly I connected up my 4-digit display and ensured that I could set whatever value I wanted. I used this third party library that I found on the Internet – https://github.com/AKJ7/TM1637 – now there is part of me that wanted to get the datasheet for the display and build my own code to set digit values, but then I reminded myself that this weekend is about building a kitchen timer not about writing a TM1637 library.
Using a library to simplify using a component is a great time saver, although it does feel somewhat like cheating to me. Though in reality I guess I just have to accept that as the famous saying goes, “I can see further because I’m standing on the shoulders of giants”. Libraries such as this one allow us to plug in our display and be up and running a couple of minutes later with just a couple of lines of code. This makes the coding part of the project a bit easier than it would be without using a library containing functions to easily manipulate the display module.
You might have noticed that I am now talking in the past tense. Building the prototype was enough work without updating this post in real time. The prototype is now working very nicely.
After connecting the display I connected a speaker module that I got in a collection of ‘Arduino sensors’. The default ‘tone()’ function in the Arduino libraries is fairly quiet and so I went on an Internet search to find a way to make more noise. I discovered the toneAC library – https://github.com/teckel12/arduino-toneac – this library has you connecting the speaker to two IO pins on the Arduino rather than one IO pin and ground. The great thing about this library is that it allows you to make much louder sounds with the same speakers.
With both the ToneAC library and the TM1637 library I uploaded a sample script to my Nano to test the functionality, this was much faster than adding library code to my countdown timer program then testing to see if the library was to my liking.
The button and LED components are very straightforward to use and I was able to take code from my earlier projects. Buttons are simple once you’ve figured out a decent way to ‘debounce’ them. This is a phenomena where by a button is pressed but due to the way the button completes the circuit at the moment on impact there is typically a bit of fluttering of pressed/not pressed for a few milliseconds. If you don’t deal with this properly then your program will take readings that suggest that the button has been pressed about 10 times for every time it is actually pressed.
All that my ‘de-bouncing’ code does is remembers when we last changed the button state and wait 50 milliseconds until treating any other state change as a legit change.
Getting to this point has taken a whole afternoon. Tomorrow I will return and build the device itself inside the project box.
Here is a video of the current state of the device – as you can see there are some issues – for one I am ending the timer when the second goes down to 0 when I should wait one more second. Also currently it’s a fixed 15 second countdown timer, which isn’t very useful beyond heating up tortillas. That’s because I haven’t added the code to read the rotary encoder values yet.
Day 2 – Building the kitchen timer device
I have just completed the code for reading the rotary encoder. It’s very straightforward and I would recommend following a tutorial online if you don’t know how they work. They let us determine which direction the knob is being rotated. We take one direction to represent an increase, and the other direction to be a decrease.
With that done the source code is now pretty much complete – here is what I came up with. (I have uploaded this to Github as well)
Building the device itself represents some different challenges from building the breadboard prototype. Primarily the need to convert a plastic box into a shell for an electrical device.
Stage 6 – The battery backpack
To power our kitchen timer we’re going to use a rechargable battery. This will free our device from needing to be plugged in. As a kitchen timer this will mean it can be moved around at will and placed where it will be most useful.
The batteries that I have though provide 3.7 volts, whereas the Arduino Nano needs a stable 5 volt input if powered directly. Not only is 3.7 volts not enough, as the battery loses charge that voltage will change. So we need to use a ‘step-up’ convertor, which takes a variable low voltage and boosts it up to the desired amount.
I happened to have a module that takes a voltage of between about 1 and 4 volts and boosts it up to anything between 2 and 20 volts. I used a small screwdriver to adjust the output voltage to the 5 volts that we will need for this project.
The countdown timer will need an on-off switch. As this will be connected to the feed from the battery, I’ve realised that it makes sense to have all the battery components located on the bottom part of the project box that I have. It splits in half nicely and then clicks back together.
The on-off switch will need to poke through a hole in the top of the box. This hole is rectangular in size.
As you can see my method for creating hole in the project box is to stick some masking tape down first, then draw the shape of the hole that is needed. I then drill holes at the edges of the rectangle and use a box-cutter to remove what remains of the plastic. This isn’t an exact science and I want to improve my technique, as the resulting hole wasn’t exactly perfect.
The battery is connected to a charging module which has a micro USB socket. This also needs to peep out of the project box. I did the same as with the on-off switch and cut out a rectangle on the left hand side of the box.
I then used a hot-glue gun to apply a generous amount of hot glue to both items. If you haven’t got a hot-glue gun I highly recommend getting one, they are fantastic for quickly connecting components that don’t have useful holes for screws and stand-offs. It’s not the perfect solution but in my experience the components are held strongly enough for hobby projects such as this one.
Below is the completed ‘battery pack’ bottom compartment of the kitchen timer. The battery is held down with tape in case I need to remove it and replace it. The component on the right is the step-up/boost convertor which takes what we get from the battery and increases the voltage to 5v. The raised red and white cables are ready to be attached to the rest of the project.
Stage 7 – building the front section
With half the project complete and nicely outputting a stable 5v we can move onto building the front section. This of course will house the countdown timer, our button, our rotary encoder and the RGB LED light.
As with the back of the timer I used masking tape to measure the hole for my 4-digit display. It was a pain to cut out, I drilled many holes then attempted to gouge out the rest of the plastic. I need to come up with a better technique for this. In the end I managed to get it the right size for the display to pop through. The holes for the speaker and LED were much easier. On the top of the device I then drilled two more holes, one on the left for my main control button, and then one on the right for my rotary encoder.
As you can see in the photo. I then connected the components to my Arduino Nano (top, connected to the USB cable). Before long the number of wires was beginning to get out of hand. This is why I cannot stress enough, limit the amount of components in your project, if you don’t this is the moment when you suddenly find yourself in a jungle of cables and things starting to fall apart.
As it was I managed to get everything connected and the device working. As you can see I used a small bit of protoboard with a set of female dupont connectors soldered to it (top, to the right of the Nano) to collect my ground pins, as the Arduino doesn’t have enough ground pins for all the components. For anything but the simplest of projects you will probably need to do something similar. For me this solution works better than trying to solder multiple wires together.
As you can see above, the mess of wires was beginning to get out of hand.
All that was left to do was to connect the battery backpack to the front of the device, then get the box to close. I attached the positive wire from the battery to the 5V input on the Arduino Nano, then the ground wire from the battery to one of the ground pins. The two sides clicked nicely together, leaving me with the finished article. A quick test showed that all was working correctly. Yes it looks slightly ghetto, but it works! and is as sturdy as a tank.
Here’s a video of the final device in use demonstrated by my wife. A week after construction I’ve heard the alarm go off at least 7 or 8 times, so it’s clearly getting used a fair bit!
Ideas for improvements
Unfortunately I realised a few hours after completing the project that the LED wasn’t being lit. I think perhaps when I glued it down to the shell a wire came loose. I could take it apart and reconnect the LED but honestly it isn’t needed for the device to be useful, so I have decided to leave it be.
I think to improve the device I would have the countdown timer mounted further back – so that the ugly white top of the display didn’t stick out. I plan to paint that, but for now it’s a bit of an eye sore.
Modifying the device to keep tabs on multiple timers would be pretty easy – so that’s an idea for version 2. Additionally I am considering using one of the ESP8266 boards which have built in wi-fi – I could then run a web server and allow users to check on the timers remotely, and also pause/set the timers remotely. This would of course potentially use a lot more power, so that’s something to consider there.
As for simple improvements – I like the idea of a 5 minute warning sound – that advises you that you have 5 minutes left on the countdown. Also I had the idea of adding a vibration module, in case the device needed to give a tactile alarm rather than an audible one. Though of course in its current size and form it’s not like you would have it in your pocket, so being able to vibrate is of little use.
I’m very pleased with this project. It was completed from start to finish in around 10 hours over a weekend. Since it was completed the timer has been used several times, it’s always great when you build something and it’s actually used in real life!
I hope you found this post interesting, please let me know if you decide to build one yourself, I’d be very interested to see photos of timers people have built.
The the source code for this project can be found on Github.