Tags:
Last month was my eldest sons second birthday, and like all kids of that age, one of his favourite things to do is copy what he sees myself and my partner doing: cooking.
I'd decided I wanted to make him a tiny kitchen of his own, something I've done several years ago for my niece, in wood, with an interactive component powered by an Arduino.
Building the Kitchen Frame
Whenever I'm building anything even slightly complicated (more than about 4 pieces!) with wood, I like to sketch out a rough idea on paper to use as a guide while I build.
The drawing shows a couple of shelves at the back that I ended up not implementing. The first kitchen that I made my niece did have these, but unfortunately my son absolutely adores climbing on everything he shouldn't, so I felt that giving him a climbing frame indoors might not be the best idea!
The frame itself is basically a box with 5 sides, and the front left open for 2 doors. Normally I would have attached the inner supports by screwing from the inside out to hide them, but in this case I wanted to make a feature of the screws, so I used brass surface screw cups to make the exterior screws look nicer.
I attached the doors using a couple of flush hinges for each one, and a magnetic cupboard catch to keep the doors closed when shut. The oven door part is slightly smaller to make room for the clock display and button panel.
The final woodworking looked like this:
After that, it was just a lick of paint, adding in the electronics (which I'll explain in a bit) and it was finished:
I did the front over display panel and the hob with clear perspex spray painted black on the underside to give a nice shine.
The Electronics
The Arduino side of things is where it gets slightly more complicated. I connected up a 2-digit 7-segment display which was triggered by a green push button switch which completes a circuit only when pressed down. As a final touch I added Piezoelectric speaker of the sort you might expect to see inside an older computer, which would trigger a sound once the clock cycle had completed.
Mapping out the LED display took a little bit of time, as I couldn't find a specification sheet for my exact one, so I mapped each pin out one by one by touching various pins to ground and power until stuff lit up. A very scientific approach!
The end result with speaker attached, once screwed down to the mounting board inside the wooden frame was this:
The button itself was affixed to the front perspex display, and the LED display fits inside a hole cut into the wooden backing of it, showing through an unpainted part of the perspex.
The Code
I added the whole C++ kitchen code to a GitHub repository. The code is pretty simple, with about half of it being taken up by various config and the rest with the application logic.
Setup
Children have short attention spans, so the clock countdown needed to be short. I decided on a 10 second countdown, which would need the numbers 10 through 0 (11 digits in total). The first variable config block at the top does this:
unsigned char digits[11][8] = {
{4, 5, 6, 8, 12, 13, 13, 13}, // 0
{6, 12, 12, 12, 12, 12, 12, 12}, // 1
{5, 6, 7, 8, 13, 0, 0, 0}, // 2
{5, 6, 7, 12, 13, 0, 0, 0}, // 3
{4, 6, 7, 12, 0, 0, 0, 0}, // 4
{5, 4, 7, 12, 13, 0, 0, 0}, // 5
{5, 4, 7, 8, 12, 13, 0, 0}, // 6
{5, 6, 12, 0, 0, 0, 0, 0}, // 7
{4, 5, 6, 7, 8, 12, 13, 0}, // 8
{4, 5, 6, 7, 12, 0, 0, 0}, // 9
{2, 3, 4, 5, 6, 8, 12, 13} // 10
};
This sets up an array of 11 "digits", each of which contains the addresses of 8 pins to turn on. This is because the number "10" requires 8 individual LEDs to be given power. Because C++ requires that all the array elements match equally, I just duplicated the final digit pin address where a number required less LEDs to be powered on.
There are cleaner ways of doing this, but I was concerned about the limited memory I had on the Arduino, as I want to implement more features on this in the future.
Next up I configure the button input pin address, some clock variables, as well as the buzzer settings and pin address:
unsigned long lastTime = 0;
unsigned short int clockDelay = 1000;
char currentDigit = 10;
bool countdownOn = false;
unsigned char countdownButtonPin = 11;
unsigned char buzzerPin = 9;
unsigned short buzzerDuration = 500;
unsigned short buzzerFrequency = 2000;
unsigned short hobLightsPin = A0;
The Logic
In order to allow the push button to function correctly without blocking the main execution of the code, I opted to not use any delay()
calls. delay()
is a blocking call and not recommended.
Instead I went with a checking loop, which polls the push button pin on every iteration of the loop()
. This makes it far easier to implement other inputs in the future.
On each iteration, I look I check to see if the push button made a circuit. If it does, I set the countdownOn
variable to true
and let the loop()
continue running.
Then, I check to see if the current time is later than the last recorded time, and if the difference is more than a predefined delay:
unsigned long currentTime = millis();
if(currentTime - lastTime >= clockDelay) {
...
}
If it is, I clear all the digits on the display (because we either need to show a new number or have a blank display anyway and there are no drawbacks to sending no current on pins) and then check the countdownOn
variable. If it's true
, I output the current number value with outputDigit()
and then decrement that number ready for the next loop. If that ever falls below 0
, the countdown has completed, so I set countdownOn
to false
and trigger a call out to the speaker.
The outputDigit()
function just takes in whatever number I've passed it before, and turns on all the pins from the digits
array defined at the top of the code file. It uses a simple for
loop to achieve this:
void outputDigit(int number)
{
for(unsigned char i=0; i<8; i++)
{
digitalWrite(digits[number][i], HIGH);
}
}
The Future
I had planned for more features in this kitchen originally, but time escaped me. I built it with future improvements in mind though. I want to add more lighting inside the oven, and hobs that light from button triggers. The only thing limiting me is the number of output pins on an Arduino Uno!
Comments