My sons love power rangers. I made this power rangers sword for my eldest's birthday. When he tilts left and right it changes to a different colour. It will look great at Halloween!

Equipment

Build

  1. Take the connector off the strip of lights. This has 3 wires on it: red for 5V, white for GND and red for 5V
  2. Strip the wire back off each of the wires
  3. Crimp a ring terminal to each wire. The wire is a bit thin for these ring terminals - try folding the bare back onto the coloured wire so the crimp will have something to crimp onto
  4. Place the red terminal against the 3V hole on the micro:bit. Put the bolt through both of them and secure on the back of the micro:bit with the nut
  5. Place the green wire against the 0 hole and do the same
  6. Place the white wire against the GND hole and do the same

  1. Plug the connector into the rest of the strip. It should only connect to the end that says DIN on it

Code

Add the Neopixel package

Before attaching to the sword, let's code it

  1. Go to microbit.makecode.com
  2. Add the Neopixel package
    1. Select Advanced
    2. Select Add Package
    3. Select Neopixel

Setup the lights

  1. Create a variable called lights
    1. Select Variable
    2. Select Create New Variable
    3. Type "Lights"
    4. Select OK

  1. From the Variables menu drag out "Set item to 0"
  2. Connect it under "On start"
  3. Change item to Lights
  4. From the Neopixel menu select the first block "Neopixel at pin 0.."
  5. Drag this out onto 0
  6. Change 24 leds to 30

Turn the lights on

  1. From Input select "on shake" and drag it onto the screen
  2. Change "on shake" to "tilt left"
  3. From Neopixel select "item show color red" and place it under tilt left
  4. Change item to lights
  5. Change red to whatever colour you want
  6. Add a test block to make sure tilt has happened: select Basic
  7. Select "show icon" and choose an icon
  8. Put it under "tilt left"
  9. Repeat steps 1 to 8 using tilt right, a different colour and a different icon

Download and test the code

  1. Plug your micro:bit into your computer with a USB cable
  2. Select Download
    1. In Chrome the file will go to your Downloads folder. Go to your Downloads folder and drag your file onto the micro:bit
    2. In Internet Explorer it will ask you where to save your file to. Select "Save As" then select the micro:bit
  3. Tilt your micro:bit left then right
  4. Ta-da!

Finish Assembly

Now your micro:bit is coded: the micro:bit can only power a maximum of eight RGB LEDs at once. I counted ten lights and cut off the remaining twenty. These strips are built to be cut. You can solder and use the reamining twenty for a different project.

  1. Tape the battery pack to the back of the sword
  2. Tape the micro:bit to the front, just under the handle
  3. Tape the lights onto the sword "blade"

What colour will your sword change? What happens you shake your sword?

Full code