Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

For more information on how Google's third-party cookies operate and handle your data, see: Google Privacy Policy

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

No cookies to display.

Les PounderCountdown Timer

About the Author

Les is a maker and trainer who has worked with the Raspberry Pi Foundation and the BBC to deliver computing training.

@biglesp bigl.es

Timers are handy, they can time a boiled egg to perfection, help us take group photos, and be used to help rockets to launch. We shall make our own timer using a micro:bit, some crocodile clips and a speaker/headphones.

You will need to connect the headphones to the micro:bit as per this image.

Connecting Headphones to the micro:bit

For this project, we shall be using the Makecode Editor from makecode.microbit.org and we should already be comfortable copying code to our micro:bit.

Step 1 - Working with Input

On button A pressed code

From the Input, menu drag the “on button A pressed” block into the coding area.

Any code inside the block will be run when button A is pressed.

Step 2 - Create a variable

Creating a Variable called time

In the Variables, menu click on “Make a Variable” and call it “time” We shall use this variable to store the duration of our countdown.

Step 3 - Using the variable

Using the variable within the code

From the Variables menu drag “set item to 0” block to the coding area.

Click on the arrow next to “item” and change to “time” then change 0 to 10.

Step 4 - Creating a loop and a test

Creating a while loop to check that time is greater than 3

We use a while true loop from loops and from Logic we connect a _ > _ block. Then from Variables, we drag time and place it in the left space and type 3 in the right space.

Step 5 - Showing and hearing the countdown

From the Basic menu, we use Show Number and use our time variable as the number. Then from Music, we use Play Tone and choose middle C to indicate a countdown is running.

Step 6 - Countdown and pause

Making the timer countdown and pause

Each time the countdown runs, it needs to pause for 1 second (pause (ms) from Basic) and then change the value of our time variable by -1.

Step 7 - Final 3!

Once the countdown reaches 3, we use another loop, and for 3 loops we change the tone to a higher note, to indicate that there is not much time left.

Step 8 - End on a high note!

Ending on a high note

With the countdown reaching 0 we trigger a loop that will repeat 4 times. Each time it goes around, it will play a high G note really quickly. Just like an alarm clock!

Step 9 - Putting it together

Putting it all together

Here is all of the code for this project.

We have learnt how to use loops, conditional tests, input, and make music with the micro:bit!

That’s it, now download the code to your micro:bit and when it has finished, press the A button to start the countdown!

Well done you have made your own countdown timer! Can you change the timer to time a boiled egg?