Create a new sketch and upload the following code to read the button presses in the Serial Console

const int buttonA = 5;     // the number of the pushbutton pin
const int buttonB = 11;     // the number of the pushbutton pin

void setup() {  
  Serial.println("microbit is ready!");
  pinMode(buttonA, INPUT);  
  pinMode(buttonB, INPUT);   

void loop(){
  if (! digitalRead(buttonA)) {
    Serial.println("Button A pressed");
  if (! digitalRead(buttonB)) {
    Serial.println("Button B pressed");

Open up the Serial console at 9600 baud and press the reset button on the back of the microbit to restart the software

You will see the welcome message and then try pressing some buttons!

This guide was first published on Sep 27, 2017. It was last updated on Mar 08, 2024.

This page (Buttons) was last updated on Sep 07, 2017.

Text editor powered by tinymce.