Micro:bit Physical computing guidesNo. 10: Push Buttons

​​Connecting a Push Button to a micro:bitInstructions on how to attach a Push Button to a BBC micro:bit.

What you will need

BBC micro:bit

Micro USB cable

Battery pack with 2 x AAA batteries

1 x Push Button

2 x Crocodile clip leads

Understanding push buttonsSmall push buttons can be used to add extra inputs to your micro:bit. Push buttons, like the ones on your micro:bit (labelled A & B), are said to be momentary as the button needs to be held down to close (or complete) the circuit.

The switch is activated by holding down (or pressing) the push button. This creates a bridge between the two sets of legs (connecting the 3 volts) and sends a HIGH signal (or 1) to the micro:bit.

Despite having four legs, a push button only has two connections (see image below). When the button is pressed, a connection is made between the two sets of legs (or pins).

Pull-down Resistor?Typically, when adding a push button to a circuit, we need to add a pull-down resistor to ensure that, when the button is not pressed, we get a constant LOW signal (or 0) reading. Conveniently, the micro:bit already has internal pull-up and pull-down resistors built-in which are automatically triggered when a digital input is read by the microbit meaning that we don’t need to add any extra resistors to our circuit.​For a simple explanation of why we need pull-up / pull-down resistors, click here: https://medium.freecodecamp.org/a-simple-explanation-of-pull-down-and-pull-up-resistors-660b308f116a.

Push button

Wiring instructions

Disconnect the micro:bit from your computer and disconnect the battery pack.

Using crocodile clips, connect leg A of the push button to GND, and leg C to Pin 0 on the BBC micro:bit.

​​Programming your Push ButtonCopy the code below:

Note: You can also use the 'on pin pressed' block to activate your code: