Make a Kitchen Timer With a MakerBit

This project explores how a kitchen timer works -- by making one!

A long time ago, most useful devices were mechanical. Kids could take things apart to see the parts inside and study how they move.

Modern electronic gadgets like a kitchen timer are different. The parts are too tiny to see, and they do not move. Change the strategy. Instead of taking it apart to see how it works, put one together!

This lesson guides you through the three, basic parts of a digital timer:

  1. components,
  2. connections,
  3. code.

The device will have buttons to set a time and start a countdown.

It will display the time remaining and give signals when the countdown is complete.

Signals may include a message on the display, a flashing light, or media such as a pre-recorded song.

Imagine a timer that blows a bugle call!

Students who complete all of the activities in this project will be able to do several things.

  • Assemble electronic components into an interactive device.
  • Write event-based code to interact with user inputs and commands.
  • Write code to measure time accurately.
  • Write code to change a real-world display based on changes in time.
  • Incorporate media devices to produce sounds based on changes in time.
  • Explain how computation enables the timer to work.

Step 1: Gather the Components

The MakerBit+R Starter Kit from 1010 Technologies. Most of the components you will need for this project are provided in the Starter Kit. They include:

  • The BBC micro:bit micro-controller
  • MakerBit+R development platform
  • USB cable to connect the micro:bit MakerBit to a computer.
  • 9-volt battery and battery connector for the MakerBit
  • Touch points, point holders, and LEDs, with ribbon cables connecting to the MakerBit
  • Grove connectors for the LCD display and the mp3 player. These connectors have a white plug on one end and four individual sockets on the other end.

Additional items.

The following components are not included with the MakerBit Starter Kit but may be purchased separately from MakerBit.com, Amazon, and many other outlets.

LCD display that works with I2C, like this one.

Optional mp3 player and speaker, like this set.

A small cardboard box, or piece of cardboard.

Step 2: Make the Connections

The MakerBit provides connections for a number of different components that your code can control.

Each of the following series of Steps explains how to hook up one of the components to the MakerBit.

There is also a photo for each component, showing how it hooks up.

Locate the micro:bit and the MakerBit+R devices in the Starter Kit. Plug the micro:bit into the MakerBit as shown in the photos.

Step 3: LCD Display

Locate the I2C socket on the MakerBit+R. Look at it closely. It has four tiny pins. They each have a label:

  • GND,
  • +5V,
  • SDA, and
  • SCL.

Each one of the pins has to connect to a pin on the LCD display that has the same label.

Note that on the LCD, the pin that corresponds to +5V might be labeled VCC.

Push a white Grove plug into the I2C socket on the MakerBit+R. Notice the color of the wire that lines up with the GND pin. It is usually a black wire.

Push the other end of that wire onto the GND pin of the LCD.

Do the same for the remaining three wires.

Stop and look at the connections for a moment. Make sure that each wire goes between the pair of pins that share the same label.

Cut a hole in your cardboard or box the size of the LCD screen. Mount the LCD behind the cardboard (inside the box) with electrical insulating tape.

Step 4: MP3 Player and Speaker

Plug a Grove plug into the Analog socket on the MakerBit+R. This socket has four, tiny pins labeled GND, +3.3V, A1, and A0. Push the other ends of the wires onto the MP3 player so that each wire connects two pins that match up this way:

MakerBit <> MP3

GND <> GND

+3.3V <> VCC

A1 <> TX

A0 <> RX

Connect an amplified speaker to the MP3 player using the headphone jack. Your code can use the MP3 player to play a pre-recorded audio track when the countdown is finished.

The speaker supplied by MakerBit.com has a rechargeable internal battery and an on-off switch. Check to be sure the battery is charged and the switch is on when you want it to play your tune.

Step 5: Touch Sensors

Look at the light gray socket on the MakerBit+R. It contains a dozen pins labeled T5 through T16.

Locate the ribbon cable in the Starter Kit that has the light gray plug shaped to fit the socket. The wires on the other end of the ribbon cable have separate, black or white sockets.

Locate the red wire on the side of the cable that goes closest to the T5 side of the socket.

This project uses that red wire and the four wires next to it: brown, black, white, and gray in color.

Find the touchpoints and the point holders in the Starter Kit.

Push the touch sensors into the sockets on the five wires that you identified in the previous step.

The wires and touch sensors will match up with the timer functions this way:

Red wire = T5 sensor = Start/Stop the timer

Brown wire = T6 sensor = Add hours

Black wire = T7 sensor = Add minutes

White wire = T8 sensor = Add seconds

Gray wire = T9 sensor = Clear the timer

A bit of cardboard may help to hold the touchpoints apart in a neat row. Better yet, mount them on a box. The point holders can help to hold the touchpoints tightly. You might need to trim the length of the point holder if your cardboard is thick. MakerBit.com offers a tutorial about mounting the touchpoints at this link.

After mounting the touch sensors onto a box or cardboard, label each one with the function it performs.

The project uses the touchpoints as sensors. The code calls them touch sensors. Touchpoints and touch sensors are two names for the same thing, so this lesson will use both names.

The actual device that senses touch is built into the MakerBit. The touchpoints are simply earring posts like the ones sold in craft supply stores.

The MakerBit senses when someone touches a touchpoint. It makes earrings function as sensors. The MakerBit tells your code which sensor was touched. This is called a touch sensor event.

The code can respond touch sensor events with special blocks, called event handlers.

When you look at the code example provided with this lesson, see if you can recognize the event handlers for the touch events.

Step 6: LED

The MakerBit+R Starter Kit provides ribbon cables with LEDs already installed. These are really easy to use.

Select the cable with the red LEDs.

Next, locate the large, black socket on the MakerBit+R that is closest to the blue socket, This black socket has pins labeled P11 through P16.

Push the black plug of the ribbon cable into this socket.

Examine the edges of the ribbon cable. Locate the side that has a brown wire on the outside.

This brown wire goes to the LED controlled by pin number P16. Your code will use this LED to signal when the countdown ends.

Make a small hole in your cardboard or box to fit the LED. Push the LED through from the back then secure it with some tape.

You might need to peel the brown+red pair of wires lightly away from the side of the ribbon cable until you loosen enough of the wire to be flexible.

Step 7: External Battery

Prepare the battery and battery connector. The battery can make your timer portable!

You can plug the 9-volt battery into the round, external power socket on the MakerBit to power the timer when it is not connected to your computer.

LCD display and the MP3 player actually need the higher voltage provided by the battery.

Try plugging in the battery to see if it activates lights on the MakerBit and the micro:bit.

Step 8: Put the Timer in a Box

A re-purposed cardboard box can make a nice housing for the timer.

It might need a bit of glue, some construction paper, and a little imagination.

The picture shows everything placed inside a box.

Step 9: Put a Bugle Call on the MP3 Player

There is a very nice collection of Army bugle calls available online at this link.

The author downloaded an MP3 audio file of a bugle playing “Mess Call”, which lets soldiers know the food is ready. It seemed like a good choice for a kitchen timer.

The MP3 kit illustrated for this project was available as an optional purchase from MakerBit.com. The kit includes the MP3 player, a microSD memory card, a USB adapter for the memory card, an amplified speaker, and a charging cord for the speaker.

Locate the microSD card and insert it into the USB adapter. Plug this into the computer. Create a folder named “04”. That’s zero-four. Open the folder.

Save the MP3 file you want the timer to play in this folder. Change the file name so it begins with a 3-digit number. For example, “001_MessCall.mp3”.

Eject the memory card and adapter from the computer. Remove the memory card from the adapter. Insert the card into the MP3 player. Push it into the receiver until it clicks into place and stays.

The code for the timer can select and play the desired file based on the folder number and the file number. In this example, it would be folder #4 and file #1.

You can play many, different MP3 audio files in your timer by saving them on the microSD card this way: in 2-digit-numbered folders having file names that start with 3-digit numbers.

Step 10: Grab the Code

You will use MakeCode to grab the code and put it into your micro:bit.

MakeCode is browser-based and available online for free. They designed it specially for the micro:bit. It works with many modern web browsers that run on ChromeBooks, Macs, Windows, and even some Linux computers.

Click this link to open MakeCode in your browser.

The actual code for this project will be brought in automatically for you to work with.

Your screen should look like the picture shown below.

Step 11: Upload the Code to Your Micro:bit

The pictures below have numbers in the corners to guide you through the process.

  1. Connect the micro:bit to your computer with the USB cable.
  2. Check your computer’s file system to see that the MICROBIT appears in your list of storage devices. The photo with this article is how it looks on a Chromebook.
  3. Click the Save button in MakeCode. The photo shows an arrow pointing to the button.
  4. Your computer will ask where you want to save the program. Navigate to the MICROBIT storage device and open it. Click the Save button.
  5. A light on the micro:bit will flash rapidly while the code uploads. Messages may appear on your computer screen telling you about progress. When the upload is complete, eject the MICROBIT device from your file system. Then unplug the USB cable.
  6. Plug the battery into the MakerBit. Enjoy your timer!

By the way, you can choose to save the code to your computer, then upload it by dragging a copy of the file onto the micro:bit.

The advantage of the extra step is that you can import the code file back into MakeCode from your computer but not from the micro:bit.

Step 12: Study the Code

Open MakeCode in a browser with the Timer code loaded, as in Step 10.

Place the mouse pointer of the computer on a code block and let it rest there briefly.

A little message will pop up giving information about the block.

Can you follow the sequence of events? Hint: it starts in the “on start” block. Then it jumps to the block named “clearTheTimer”. After that it jumps to the block named “forever”. What happens after that?

Try touching buttons on the timer while you study the code.

Which parts of the code seem to activate when you touch a button? Why? Can you predict what the button will do, by looking at the code?

Learning to read is an essential part of learning to write. Students learning to write code can benefit by reading code that other people wrote.

A good way to test your knowledge of coding might be to change something in the code for your timer.

Predict how your change will affect the way the timer works. Then upload the changed code to the micro:bit and see what happens!

You will probably make mistakes. That is OK. Everybody does. Nearly every coding project goes through a phase called debugging, which basically means finding and fixing errors.

You can always start over with code that you know will work. Just click the link in Step 10 to download the code again.

Step 13: Frequently-asked Questions

Why is the code separated into parts?

Each part handles only one task.

Code for each task is written only one time.

The parts have descriptive names to help humans read the code.

The timer activates a code part by name when it needs to do the task that code part performs. This is known as “calling” a “procedure.”

How does computation enable the timer to work?

The timer uses computation three different ways.

Add time when the user touches a touchpoint to set the timer. Subtract time after the user touches a touchpoint to start the timer. Convert the number of seconds into hours, minutes, and seconds for display. The “forever” procedure uses subtraction to measure time in two ways.

Check the micro:bit to tell when one second has passed. Subtract 1 from the countdown after each second passes, until the countdown reaches zero. The “addSeconds” procedure uses addition to increase the countdown after the user presses one of the touchpins for hours, minutes, or seconds.

The “showTimeRemaining” procedure uses integer division to transform the countdown into a time display that is easier for a human to understand.

What are some other coding techniques used in the code?

Descriptive variable names help humans to understand how the code manages certain facts.

A variable is simply a name attached to a fact that the micro:bit stores in its memory.

The facts enable the timer to keep track of what the user wants it to do.

A procedure can change the value attached to a variable. The new value may be used in a different procedure.

Logic blocks evaluate true-or-false facts. This is how the timer can determine the right action based on the facts.

A true-or-false fact can be the result of comparing two numbers. Are the numbers equal? Is one number greater than the other? Or less?

The code also can attach an actual value of true or false to a variable.

A procedure can change the value of a true-or-false variable to change how another procedure will work. That is how the T5 event handler in this code turns off the alarm in the procedure named soundTheAlarm.

Logic blocks can be simple: if a value or comparison is true, then do something; otherwise, do nothing.

Logic blocks can be complex: if a value or comparison is true, then do one thing; else (meaning otherwise), do a different thing.

Logic blocks can have other logic blocks “nested” inside them.

Sometimes it takes a series of several logic blocks in a row to evaluate a fact and choose the right action.

Why does the “forever” block use the number 995?

The code uses 995 to tell when one second of time has passed.

The micro:bit automatically increases a variable named "running time" approximately 1,000 times per second. It’s not exactly 1,000, but close.

An experiment with the actual micro:bit used to build this example found it was closer to 995, on average.

This code goes with the observed average. It waits for the running time value to increase by 995 before starting through the logic blocks to subtract one second from the countdown.

How would you design an experiment to discover how fast your micro:bit updates the running time variable? How long a time would you have to run the experiment to feel confident in your discovery?

You are the engineer of your timer. This means you are the only one who can decide whether changing 995 to a different value would make your timer more accurate.

How could the timer be modified to do something different by changing only the code?

Keeping the assembled components the same, a few changes to the code could transform the timer into a different product.

Stopwatch

The “Start-Stop” touch sensor would work as expected. The “Clear” touch sensor would, also.

The touch sensors for hours, minutes, and seconds would not be needed.

The “forever” procedure would change to count up, rather than down.

An advanced modification would be to measure and display time in increments of 1/10th of a second.

Desk Clock

The “Start-Stop” touch sensor would act as a “Set” button.

The touch sensors for hours, minutes, and seconds would work as expected without any change.

The “forever” procedure would need to count up, rather than down.

Also, the “forever” procedure would need a computation for “rolling over to zero” at midnight.

The “Clear” touch sensor would not be needed. However, it could be given a new function.

An advanced modification might be to use that touch sensor as a mode-selection control. Switch between 24-hour, military-style display and conventional, 12-hour display with a.m. and p.m. added to the display.

Alarm Clock

In this case the “Clear” touch sensor might be changed to an “Alarm” control.

More variables might be needed to keep track of new facts, such as what time to sound the alarm, and whether the user has enabled or disabled the alarm.

It would be interesting to see how different students might approach this modification in different ways.

Control The World

More sensors could be added through the MakerBit to let the clock detect events such as motion, a noise, or a door opening and closing.

The clock could decide to sound an alarm if the events are detected during certain periods of time.

Similarly, the clock could be used to enable or disable external devices based on time. One example might be an electronic door lock connected to a pin on the MakerBit.

Share

    Recommendations

    • 1 Hour Challenge

      1 Hour Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Fandom Contest

      Fandom Contest

    Discussions