micro:bit RGB box


Last Christmas I taught my son’s school algorithms by getting them to write an algorithm for some Christmas lights.

The younger children had to colour in 3 boxes with 3 different colours. The older ones had to write down the time delays. The eldest group had a look at RGB values and loops.

When a child asked me what does 255, 100, 100 look like in lights I quickly coded it on the micro:bit and turned on the strip of lights. The problem was once one child saw their light all the others wanted to see theirs!  It just took forever to have to keep changing the numbers and upload the code to the micro:bit. (In hindsight if I had used python and the MU editor this would have been a lot quicker)

To combat the problem I’ve made an RGB box! A very simple box with 3 buttons – Red, Green, Blue. As you press each button it increases that colour in the strip of lights. It’s a great way to demonstrate how RGB works in lights.



We need to connect wire to 4 pins to connect 3 buttons and the light strip. Therefore I used the Edge Connector to access more pins on the micro:bit.

I used jumper wires and chopped their heads off to connect from the edge connector to the buttons and the light strip.

Connect the lights to the edge connector

  1. Connect a female to female jumper wire to GND
  2. Chop off the other half of the wire
  3. Strip the wire to expose the wire underneath
  4. Connect it to the ground of the lights using a terminal block
  5. Connect a female to female jumper wore to Pin 1
  6. Chop off the other half of the wire
  7. Strip the wire to expose the wire underneath
  8. Connect it to the data wire of the lights using a terminal block
  9. The ground and data wires of the lights connected to jumper wires

Connect the buttons

  1. Cut a female to female jumper wire in half
  2. Strip the one half of the wire to expose the wire underneath
  3. Crimp a spade terminal onto the exposed wire
  4. Connect the jumper wire to GND on the edge board
  5. Connect the other wire to Pin 0 on the edge board
  6. Do the same for the other two buttons connecting red to Pin 3 and GND then connect blue to Pin 2 and GND
  7. Cut holes in your box and place the buttons in
  8. Connect the wires to the buttons – each button has a data wire and a ground wire.
  1. On the opposite side of the strip of lights connect the battery.
    1. Connect the black ground wire from the battery to the white ground wire of the lights.
    2. Connect the red live wire from the battery cage to the red live wire of the lights

On your edge board you should have wires connected to all the 4 grounds, Pins 0, 1, 2 and 3


  1. Go to https://makecode.microbit.org/
  2. Under on start:
    1. Select Advanced > Add Package and select Neopixel to add the Neopixel menu
    2. Set the variable item to 30 lights on Pin 1
    3. Set the lights on Pin 0, 2 and 3 to pull up (this block is under Advanced > Pins > More)
    4. Create Variables R, G and B and set them to 0
    5. Create a function called changeColour. This is called anytime a button or buttons are pressed. It sets the lights to the colour of the variables R, G and B.
      1. Set item to the RGB variables R, G and B
    1. Under forever we’re going to check for button presses.
    2. Add the logic blocks
      1. if
      2. 0 = 0
      3. and
    3. If digital read pin 3 (red) and digital read pin 0 (green) both = 0 that means they pressed the red and green buttons together. (Digital read pin is found under Advanced > Pins)
      1. Set variables R, G and B to 0 – turn the lights off
      2. Call the function changeColour
    4. If digital read pin 3 = 0 they pressed red
    5. If digital read pin 0 = 0 they pressed green
    6. If digital read pin 0 = 0 they pressed blue
    7. For each check change that variable (R,G or B by 1) and call the function changeColour. 


  1. Press Download to download the code to your computer
  2. Drag and drop that file onto your micro:bit
  3. Plug the micro:bit into the edge connector
  4. Put batteries in the battery cages
  5. Turn the lights battery cage on
  6. Press some buttons!