microbit Logic Gates Practical

microbit Logic Gates Practical Overview:

I wanted a hands on way to teach logic gates and truth tables to my students, so I decided to program a set of microbits to act like logic gates. These logic gates could then be connected to switches and outputs using crocodile clips.

Logic gates practical activity

Equipment Required:

Getting Things Ready:

Start by covering a piece of A4 card in foil.

Next attach the brass and nylon hex spacers to 2 microbits as shown in the picture, these will become logic gates.

Logic gate spacers

The upward facing brass hex spacers make it easy to connect crocodile clips without them touching the other pins. The downward facing brass hex spacer allows all the microbits to be grounded by touching the foil.

Now attach the brass and nylon hex spacers to the remaining microbit as shown in the picture, this will be the output.

Logic gate output spacers

Programming the Logic Gates:

Two of the microbits will be programmed to be logic gates. The program is explained below.

This section of code imports the microbit module and defines the icons that will be displayed when each logic gate is active.

from microbit import *

notGate = Image("99000:95990:95599:95990:99000")
andGate = Image("99990:95559:95559:95559:99990")
orGate = Image("99990:09559:09559:09559:99990")

This is the function that is called when the NOT gate is active. It starts by displaying the notGate icon. It checks whether pin0 is connected to ground, if so this is taken as a 1 being inputted. This is opposite to the behaviour we would normally expect for a logic gate, however this method removes the need for the switches to be connected to a power source.

If a 1 is received the NOT gate outputs a 1 on pin2. This is interpreted as a 0 on the receiving logic gate or output.

def notGateProg():
    if pin0.is_touched():

These are the functions for the AND and OR gates.

def andGateProg():
    if pin0.is_touched() and pin1.is_touched():

def orGateProg():
    if pin0.is_touched() or pin1.is_touched():

This part of the program allows the user to cycle through the logic gates by pressing the A button. The appropriate function for the current logic gate is continually called within a while loop.


while True:
    if gateChoice==1:
    elif gateChoice==2:
    elif gateChoice==3:
    if button_a.was_pressed():
        if gateChoice < 3:

Programming the Output:

The remaining microbit needs to programmed to be an output.

This program checks whether pin0 is grounded, if so it displays a 1, otherwise it displays a 0. Therefore if a 1 is received this is interpreted as a 0.

from microbit import *

while True:
    if pin0.is_touched():

Creating a Logic Circuit:

Connect the components as shown in the diagram and picture. This is a simple logic circuit with 1 input, a NOT gate and 1 output.

Example logic gate circuit

Try it out by turning the switch on and off.

Follow the activities in the PowerPoint workbook in order to create more complex logic circuits.



  • Make sure all micro bits are touching the foil.
  • Try not to touch the metal contacts on the switches or crocodile clips with your hands, this could ground the inputs unintentionally.

One thought on “microbit Logic Gates Practical

Leave a Reply

Your email address will not be published.