Push Button

A small push button can be used to provide an external input into your circuits.

Push Button Diagram and Photograph

This is a small, SMD-mount tactile switch identical to the ones on your microbit. These switches are normally open (or NO) and so must be pushed to close the circuit. It said to be momentary as it must be held to close.

Electronics

One of the button’s pins is connected to 3V. The corresponding pin to pin0 of the microbit. When the button is pressed, pin0 reads True or 1.

Push Button Diagram and Photograph

Code

Display a tick if button attached to `PIN0` is pressed
from microbit import *

while True:
    # if pin1.read_digital() == 1
    if pin1.read_digital():
        display.show(Image.YES)
    else:
        display.show(Image.NO)
    sleep(10)

Experiment

Pull-down Resistor?

The microbit has internal pull-up and pull-down resistors. When a digital input is read by the microbit, the pull-down resistors are turned on so there is no need for an external one.

This behaviour can be modified in PXT but not Python.

Share On
Facebook Twitter Google Plus

Published: December 23, 2016 Updated: December 23, 2016

Acknowledgements: SMD push button switch by Sparkfun (CC-BY-2.0)

Push Button

Use buttons to provide external inputs to the microbit.

Jez Dean
Teacher