Home · Academy · Robotics & Coding · micro:bit · Pins and External Components

Pins and External Components

Learn to connect external LEDs, buzzers and buttons to the edge pins safely.

LESSON COMPASS

What will you use this page for?

Core idea

The pins along the bottom edge of the micro:bit are connection points that let us attach outside parts such as LEDs, buzzers, or buttons, and write or read digital and analog signals to and from them.

Evidence to produce

Complete the page task with your own input, test conditions and reasoning.

Control trap

Using the wrong pin A common mistake is connecting the buzzer to the 3V or GND pin and expecting a signal. Sound and general signals come from the input/output pins such as 0, 1, and 2; 3V and GND are only for power. Forgetting to connect GND An outside part will not work with just a signal pin; the circuit must be…

Next connection

micro:bit with Python: We move from MakeCode blocks to MicroPython and learn to write the same programs as text-based code.

Module sources: Python Tutorial · Arduino Learn

LevelBeginner
Age10–16
Duration35–50 min
PrerequisiteRadio Communication
ContentIn-depth guide · 1,844 words
Last updated

One-sentence summary

The pins along the bottom edge of the micro:bit are connection points that let us attach outside parts such as LEDs, buzzers, or buttons, and write or read digital and analog signals to and from them.

Why does it matter?

So far you have worked with the parts built into the micro:bit itself: the LED display, the A and B buttons, the accelerometer, light and temperature sensing, and the radio. But a real robot or project usually reaches beyond the board too: a bell needs to ring, a separate LED needs to light up, or an external button needs to be pressed.

This is where the pins come in. The metal strips along the bottom of the board are gateways that connect the micro:bit to the outside world. You can use a pin like an "output" to send a signal out, or like an "input" to read a signal coming in.

Learning about pins lets you combine the LEDs, buzzers, and buttons from the electronics lessons with a programmable board. You build the circuit and control it with code at the same time. This is the first step behind many ideas, from a toy alarm to a wearable project.

What are the edge pins?

Along the bottom edge of the micro:bit you can see gold-colored metal strips. These are called pins (connection points). A pin is like a gateway that lets electricity flow into and out of the board.

The five largest and most-used pins are:

What are the edge pins? table
PinNameWhat it does
0Pin 0Input/output; general purpose
1Pin 1Input/output; general purpose
2Pin 2Input/output; general purpose
3VPower (+)Gives a positive supply to a part
GNDGround (−)The negative end of the circuit

Pins 0, 1, and 2 have large holes, so a crocodile clip attaches to them easily. You can use them both to send a signal out (output) and to read a signal in (input).

The 3V pin gives positive power, and GND is the negative end. To run an outside part, you usually connect a signal pin (0, 1, or 2) together with one of these.

Connecting with crocodile clips

The easiest way to reach the large pins is to use crocodile clips (cables with jaw-shaped clips at the ends). You clip the jaw onto the metal around the pin's big hole and connect the other end to your part. No soldering is needed, which makes it perfect for beginners.

Example: Think of a flashlight. Inside it there are batteries, a switch, and a bulb, all joined by wires. A micro:bit project uses the same idea, but instead of wires we use crocodile clips, and instead of a switch we use code.

Example: When you plug headphones into a phone, sound flows from the phone to the headphones. A pin is a similar gateway, letting a signal flow from the micro:bit to the outside part.

Digital and analog: writing and reading

There are two basic ways to use a pin: writing (sending a signal out) and reading (taking a signal in). The signal itself can also come in two kinds: digital and analog.

Digital: on or off

A digital signal takes only two values: 1 (on, electricity present) or 0 (off, no electricity). Think of a light switch; it is either on or off, with nothing in between.

Analog: a range of values

An analog signal can take many values, from 0 to 1023. Think of a dimmer switch; you can raise or lower a light little by little.

Example: A radio's volume knob is analog; you turn the sound up bit by bit. The lamp in a fridge door is digital; it lights when the door opens and goes off when it closes. Pins carry these same two ideas.

Example project: A sound on pin 0 with a buzzer

Now let us put it together. We will connect a buzzer to pin 0 and make the micro:bit play sound. To use the micro:bit's music blocks, it is traditional to connect the buzzer to pin 0.

Connection plan:

Buzzer connection (crocodile clips)

  Buzzer (+) ----> micro:bit Pin 0
  Buzzer (-) ----> micro:bit GND

The program as a MakeCode block sequence:

on start
  set audio output pin to "P0"
forever
  if <button A is pressed> then
    play note "C" for 1 beat
  if <button B is pressed> then
    play melody "ba ding"

The same idea in MicroPython:

from microbit import *
import music

while True:
    if button_a.is_pressed():
        music.pitch(262, 500)   # note C, 500 ms
    elif button_b.is_pressed():
        music.play(music.BA_DING)

In MicroPython the music module sends sound out of pin 0 by default, so connecting the buzzer there is enough. The command music.pitch(262, 500) plays a 262 Hz tone (the note C) for half a second.

Lighting an LED with digital write

Instead of sound, you can light an outside LED. Connect the LED's long leg (positive) to pin 0 through a resistor, and its short leg to GND. Then write digital 1 to pin 0.

from microbit import *

while True:
    if button_a.is_pressed():
        pin0.write_digital(1)   # LED on
    else:
        pin0.write_digital(0)   # LED off

Mini practice

In this practice you plan the connection before you make it. The goal is to think about choosing the right pin and connecting the part in a safe order.

Imagine you have these: a micro:bit, a buzzer, a few crocodile clips, and an adult's help.

Task: Fill in the plan below and write down which pin you use at each step.

Connection plan (you fill it in):

1. Buzzer (+) ----> micro:bit pin ________
2. Buzzer (-) ----> micro:bit pin ________
3. Code: Which pin should the audio output be set to? ________
4. Check: Does the sound play when you press button A? (It should)
5. Check: Did you power the board off before removing the clips?

Check questions:

There is no single correct layout. What matters is that the connection is safe, uses the right pins, and matches the code.

Common mistakes

Using the wrong pin

A common mistake is connecting the buzzer to the 3V or GND pin and expecting a signal. Sound and general signals come from the input/output pins such as 0, 1, and 2; 3V and GND are only for power.

Forgetting to connect GND

An outside part will not work with just a signal pin; the circuit must be completed with a GND (negative end) connection too. If there is no sound or light, check the GND cable first.

Confusing digital and analog

If you want to set brightness gradually but use write_digital, you only get fully on or fully off. For a gradual change you need write_analog. Pick the right command for what you want.

Connecting an LED without a resistor

Connecting an outside LED straight to a pin can draw too much current and harm the LED or the board. Always place a suitable resistor between the LED and the pin, and check it with an adult.

Safety note

Lesson summary

Check questions

  1. What are the 3V and GND pins on the micro:bit used for?
  2. Which pin do we traditionally connect a buzzer to in order to play sound?
  3. What is the main difference between a digital signal and an analog signal?
  4. If we want to take a signal in from an outside part, how do we use the pin: by writing or by reading?
  5. Why do we place a resistor when connecting an external LED to a pin?

Answers

  1. The 3V pin gives positive power (supply) to a part, and the GND pin is the negative (ground) end of the circuit. Together they provide the power a part needs to work.
  2. We traditionally connect it to pin 0; the micro:bit's music module and music blocks send sound out of this pin by default.
  3. A digital signal takes only two values: 0 (off) or 1 (on). An analog signal can take many gradual values from 0 to 1023, which lets us set things like brightness or tone slowly.
  4. We use the pin by reading it; that is, we treat the pin as an input and take the incoming signal with read_digital or read_analog. Writing is for sending a signal out.
  5. The resistor limits the current flowing through the LED. Without it, too much current could strain the LED or the pin; the resistor lowers that risk.

Source and verification note

For “Pins and External Components”, verification focuses on whether the relationship between What are the edge pins? and Digital and analog: writing and reading remains consistent across examples. MakeCode and MicroPython names can vary slightly by version. Test in the simulator first; when external components are connected, check the board’s pin and voltage limits separately.

Next lesson

micro:bit with Python: We move from MakeCode blocks to MicroPython and learn to write the same programs as text-based code.

Start QuizBack to micro:bit
QUESTION POOL

Reinforce this lesson with 10 questions

This lesson has a pool of 20 questions. Each attempt selects 10 and reshuffles the choices.