£199.99 £139.99 for one year of Unlimited learning. Offer ends on 14 November 2022 at 23:59 (UTC). T&Cs apply

Find out more
Challenge 1 – Detect input, create output
Skip main navigation

Challenge 1 – Detect input, create output

Let's get straight in and create our first physical computing challenge

Let’s start by detecting an input created by a person, then create an output based on that input. You’ve seen a simple example of this in the previous week where the step counter was being displayed on the micro:bit’s screen after a person pressed one of the micro:bit buttons. That was taking an input (the button press) and creating an output (the number on the micro:bit’s screen).

In this challenge, we’re going to use the micro:bit’s pins to detect touch, and play a sound through a speaker that we attach. We’ll code two different pins on the micro:bit to each play a different sound.


You can code and test this challenge using the simulator. If you have a micro:bit you’ll have also need – 3 x clips – a speaker with its own power source or a pair of headphones – something conductive like tinfoil or fruit

In the UK, we call clips crocodile clips. In the US, they are called alligator clips!

Pins on the micro:bit

Watch the video below to learn more about the micro:bit’s pins

This is an additional video, hosted on YouTube.

Setup the Speaker

###Code Test the speaker is working by putting some test code in the block On button A press. If you have a speaker on your computer that you’re coding with, you can test your code by pressing the A button on the simulator. Use the simulator to find your favourite melody!


+Connect the speaker to the micro:bit using two clips. +Add one clip to GND and +the other to Pin 0

The speaker only works connected to Pin 0. Connect the clips to the speaker jack, one at the bottom, one at the top.

Speaker setupSpeaker setup
(Click to expand)


To play the test sound, press button A. Watch the video in the next step for a demonstration.

Add your own keys

You can extend the pins on the micro:bit using clips. Attach a clip to Pin 1 and Pin 2.

You can attach a conductive item to the end of the clips then touch them: in the next step I use fruit and also tinfoil.

Below is the final setup with the keys and the speaker attached. And the code I used to create my musical piano.

Final setupFinal setup
(Click to expand)

To play your keyboard you need to hold Pin 1 or 2 and GND to play your sound.

In the next step you will watch a video that shows this challenge in action.

This article is from the free online

Build a Physical Computing Prototype

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education