Halloween + Micro:bit

Add some life to your Halloween decorations! Using micro:bit + LEDs, and some spooky music!

Things used in this project

Hardware components

HARDWARE LIST
1 BBC micro:bit board
1 addressable LED strip affiliate link
1 3 pin led strip connector Optional - easy alternative to soldering (affiliate link)
1 Alligator Clips
1 Buzzer
1 5v Cell Phone Power Bank
1 Pumpkin
1 Wax Paper
1 Tape
1 Paper Clips

Software apps and online services

Microsoft MakeCode

Story

 

The story

 

Add some life to your Halloween decorations! Using micro:bit + LEDs, and some spooky music! I did something similar last year using Arduino, but because of the limitations of some of the libraries, I needed to use two separate boards to combine the LEDs and music. Using Micro:bit allowed me to combine them all into one.

Watch video for more details:


 

Step 1: Carve a Pumpkin

projectImage
projectImage
projectImage

Carve a spooky face for the pumpkin! Make sure to leave openings for eyes, and for light from the candle to be visible. You can carve some scars and other openings to let a bit more light leak out.

 

 

Step 2: Candle + Eyes (code)

projectImage
projectImage
projectImage

I used Microsoft's Makecode to develop the code for this project, which can be found here: Micro:bit blocks + code

We are going to create a single LED strip to use for both the eyes and the candle. So we initiate it with the blocks, and then split it into two smaller LED strips.

 

For the candle, it picks a random amount of LEDs to light up (between 2 and 4 LEDS), and a random color (yellow orange or red orange), then turns them on for a short random duration. After the pause, it repeats the process again, simulating the look of a flickering candle.

 

For the eyes, there is an array that contains a list of colors, and the function cycles through the array, one color at a time. For each color, it gradually fades in and then back out before changing to the next color.

 

 

 

Step 3: Candle + Eyes (wiring - Part 1)

projectImage
projectImage

Cut 3 pieces off the LED strip. The one for the candle is four LEDs long, and the each of the eyes has a strip two LEDs long. Connect them together using the LED connectors, or solder if you prefer. Put the four for the candle first, then each of the eyes. The arrows on the LEDs should all point in the same direction.

 

Make sure there is enough wire between the two sets of LEDs for the eyes so that they can stretch between the eyes carved into the pumpkin, and make sure you have given enough space between the LED for the candle and the first eye, so that it can reach to the floor of the pumpkin.

 

Add a connector on the side of the candle that will connect to the micro:bit. Cut off the end, and strip the three wires.

 

 

 

Step 4: Candle + Eyes (wiring - Part 2)

projectImage
projectImage

-Connect the + pin from the LED strip to the 3.3v pin on the micro:bit

 

-Connect the - pin from the LED strip to the gnd pin on the micro:bit

 

-Connect the middle pin from the LED strip to pin 1 on the micro:bit

Step 5: Song (Code)

projectImage
projectImage
projectImage

The code for the song takes an array, and cycles through it one item at a time, playing the current note for a short period of time, then switching to the next. When the song is over, it repeats again from the beginning.

 

To simplify the process of creating the code for the song, I switched to the javascript tab and created variables to hold the frequencies of the notes used in the song. Then I pasted the notes for the song. If you want to use a different song, this would be the place to change the notes.

 

 

Step 6: Speaker (Wiring)

projectImage

Connect one end of the speaker to the gnd pin, and the other end to pin 0. Since there is already a wire connected to the ground pin, you can connect this end of the speaker to either end of the wire that was connected there first. I used a little tiny buzzer, but this can be done with any speaker. The buzzer gets pretty muffled inside the pumpkin. To improve the volume, the speaker could be placed outside the pumpkin, or the micro:bit could be connected to a speaker with its own built in amplifier.

 

 

 

Step 7: Diffusing LEDs

projectImage
projectImage

The LEDs produce bright light that is not diffused, making it easy to see individual pixels. To make the LEDs blend together a bit, and so that they glow a bit, I used wax paper to diffuse them. Cut with a width slightly longer than the length of the LED segments, and then wrap with the wax paper, using some tape to hold it in place.

 

 

 

Step 8: Adding Everything to the Pumpkin

projectImage
projectImage
projectImage
projectImage

To hold the eyes in place, unfold a paper clip and then push it into the walls of the pumpkin where the individual LEDs for the eyes are. The rest just drops into the middle, and you can place it in a plastic bag if you do not want to get pumpkin gunk on it.

 

If something doesn't work as suspected, try adjusting/changing connections, and make sure the correct pins are hooked up.

Step 9: All Done!

projectImage
projectImage

Place it in a good spot, and be careful not to be to startled by the horrifyingly spooky creation sitting in front of your house. The cell phone powerbanks last a long time at such a low current draw, so you can leave it plugged in for a while without the battery dying.

 

Thank you for reading. If you are interested in seeing future projects, please subscribe to my Youtube channel: More Than The Sum

Schematics

Micro:bit wiring guide

This diagram shows how to connect the LEDs and the speaker to the micro:bit

projectImage

代码

Song + Eyes + Candle

JavaScript

This is the javascript version of the makeCode blocks for this project

CODE
let g5 = 0
let b4 = 0
let ef5 = 0
let bf5 = 0
let e5 = 0
let b5 = 0
let f5 = 0
let c6 = 0
let d6 = 0
let fs5 = 0
let cs6 = 0
let candle_colors: number[] = []
let Candle_strip: neopixel.Strip = null
let eye_strip: neopixel.Strip = null
let eye_colors: number[] = []
let Full_LED_strip: neopixel.Strip = null
let Song_1: number[] = []
let candle_LED = 0
let current_candle_strip: neopixel.Strip = null
let rest_of_candle: neopixel.Strip = null
let Number_LEDs = 0
let index2 = 0
function song() {
    for (let index = 0; index <= Song_1.length; index++) {
        music.playTone(Song_1[index], music.beat(BeatFraction.Half))
        basic.pause(10)
    }
}
function eyes() {
    for (let index1 = 0; index1 <= eye_colors.length - 1; index1++) {
        for (let index22 = 0; index22 <= 255; index22++) {
            eye_strip.setBrightness(index22)
            eye_strip.showColor(eye_colors[index1])
            basic.pause(5)
        }
        for (let index23 = 0; index23 <= 255; index23++) {
            eye_strip.setBrightness(255 - index23)
            eye_strip.showColor(eye_colors[index1])
            basic.pause(5)
        }
    }
}
function candle() {
    rest_of_candle.clear()
    current_candle_strip = Candle_strip.range(0, Math.randomRange(0, candle_LED - 1 + 1) + 1)
    current_candle_strip.showColor(candle_colors[Math.randomRange(0, 1)])
    basic.pause(Math.randomRange(0, 41) + 80)
}
index2 = 0
Number_LEDs = 8
candle_LED = 4
Full_LED_strip = neopixel.create(DigitalPin.P1, Number_LEDs, NeoPixelMode.RGB)
Candle_strip = Full_LED_strip.range(0, candle_LED)
eye_strip = Full_LED_strip.range(candle_LED, Number_LEDs - candle_LED)
candle_colors = [neopixel.rgb(255, 80, 0), neopixel.rgb(255, 150, 0)]
eye_colors = [neopixel.colors(NeoPixelColors.Red), neopixel.colors(NeoPixelColors.Green), neopixel.colors(NeoPixelColors.Blue), neopixel.colors(NeoPixelColors.Purple), neopixel.colors(NeoPixelColors.Yellow)]
rest_of_candle = Candle_strip.range(1, candle_LED - 1)
music.setTempo(136)
cs6 = 1109
fs5 = 740
d6 = 1175
c6 = 1047
f5 = 698
b5 = 988
e5 = 659
bf5 = 932
ef5 = 622
b4 = 494
g5 = 784
Song_1 = [cs6, fs5, fs5, cs6, fs5, fs5, cs6, fs5, d6, fs5, cs6, fs5, fs5, cs6, fs5, fs5, cs6, fs5, d6, fs5, cs6, fs5, fs5, cs6, fs5, fs5, cs6, fs5, d6, fs5, cs6, fs5, fs5, cs6, fs5, fs5, cs6, fs5, d6, fs5, cs6, fs5, fs5, cs6, fs5, fs5, cs6, fs5, d6, fs5, cs6, fs5, fs5, cs6, fs5, fs5, cs6, fs5, d6, fs5, c6, f5, f5, c6, f5, f5, c6, f5, cs6, f5, c6, f5, f5, c6, f5, f5, c6, f5, cs6, f5, cs6, fs5, fs5, cs6, fs5, fs5, cs6, fs5, d6, fs5, cs6, fs5, fs5, cs6, fs5, fs5, cs6, fs5, d6, fs5, c6, f5, f5, c6, f5, f5, c6, f5, cs6, f5, c6, f5, f5, c6, f5, f5, c6, f5, cs6, f5, b5, e5, e5, b5, e5, e5, b5, e5, c6, e5, b5, e5, e5, b5, e5, e5, b5, e5, c6, e5, bf5, ef5, ef5, bf5, ef5, ef5, bf5, ef5, b5, ef5, bf5, ef5, ef5, bf5, ef5, ef5, bf5, ef5, b5, ef5, b5, e5, e5, b5, e5, e5, b5, e5, c6, e5, b5, e5, e5, b5, e5, e5, b5, e5, c6, e5, bf5, ef5, ef5, bf5, ef5, ef5, bf5, ef5, b5, ef5, bf5, ef5, ef5, bf5, ef5, ef5, bf5, ef5, b5, ef5, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4, fs5, b4, b4, fs5, b4, b4, fs5, b4, g5, b4]
basic.forever(function () {
    eyes()
})
basic.forever(function () {
    song()
})
basic.forever(function () {
    candle()
})

The article was first published in hackster, October 27, 2018

cr: https://www.hackster.io/aams86/halloween-micro-bit-3fe7e3

author: aams86

License
All Rights
Reserved
licensBg
0