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

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now