Create a Christmas tree cut-out with three LEDs using a Micro:bit.
Welcome to the third blog of Christmas!
What you’ll need:
- Small breadboard
- 470 ohm resistor
- Three LEDs
- Jumper cables and crocodile clips
- Sheet of cardboard
Part 1: making
We’re going to make a cardboard cut-out of a Christmas tree and stick three LEDs through it. We’re then going to connect the LEDs to a micro:bit using the pins. Firstly, find a thin piece of cardboard and cut out a Christmas tree shape. Then you poke three small holes through the cardboard (anywhere you want) and push the legs of the three LEDs through.
Part 2: code
Now we have to create the code that will turn the three LEDs on and off. Open the Python editor at microbit.org and copy the foollowing code:
from microbit import * while True: pin0.write_digital(1) sleep(1000) pin0.write_digital(0) sleep(10) pin1.write_digital(1) sleep(1000) pin1.write_digital(0) sleep (10) pin2.write_digital(1) sleep(1000) pin2.write_digital(0) sleep(10)
The code simply turns on pin 0 before turning it off a second later. It then does this again for pin 1 and 2 before repeating again forever. This means that LED 1 will come on for a second, then LED 2 will come on for a second and then LED 3. Compile your code to the Micro:bit and then disconnect it from power, as we’ll be connecting the electronics next.
Part 3: electronics
Here’s the wiring diagram for the project:
Note: As you can see, there is only one resistor instead of three. This means that this set up only enables you to turn on one LED at the time or you could damage your Micro:bit.
You can use a mix of crocodile cables and jumper cables to connect everything together.
Double check your wiring before turning your micro:bit on. You should see your Christmas tree light up with the three LEDs flashing. Enjoy!