Updated: micro:bit sound sensing hoodie

After buying the MonkMakes sensor board:

https://www.monkmakes.com/mb_sensor/

I decided to upgrade the micro:bit light up hoodie. The lights would now light up the louder it got around me!

Here’s the final result:

Build

The sensor board is very easy to connect using crocodile clips

Using 3 different crocodile clips you connect

  1. Pin 1 of the micro:bit to the sound pin on the sensing board (the microphone labelled hole)
  2. 3V from the micro:bit to 3V on the sensor board
  3. GND from the micro:bit to GND on the sensor board

screenshot_20171105-222413.png

You need to connect the light strip to the micro:bit as well. Things get a bit crowded around the Ground pin but it does all fit (pics to follow)

The micro:bit can only power 8 lights. I power my lights using one power source and my micro:bit using a separate one. That way I can run lots of lights! There are 30 on this hoodie.

Code

Setup the lights

  1. Go to https://makecode.microbit.org
  2. Select the micro:bit
  3. Select Advanced > Add Package and select the Neopixel package
  4. Under the on start block adding the following:
    1. Under the Variable menu: Create a variable called LEDCount and set it to 30
    2. Under the Neopixel menu: Set the variable item to 30 leds on Pin 0 (though in my picture above the sound board is on Pin0! Chose the pin your lights are connected to 🙂 )

sound2

Setup the sound board

This is the code needed for the jacket to react to the sound. There are a lot of blocks here! Below is a text description of where each block came from… but try creating it yourself first. All the blocks are colour coded, so you should be able to find them.

It shows the light level on the micro:bit too

To change sensitivity you need to change the first number: 511

What it does: it gets the sound level from reading the analog sensor on the sound board. If the sound level is greater than a certain level it divides that level into 3  – I have 3 levels on my jacket: green, orange and red. Red is the loudest level.

Each time we read a sound we calculate how many lights to light up and then we light them up.

sound1

Add the following code under the forever block

    1. Under the LED menu drag out “plot bar graph of”
      1. Under the Math menu add a subtraction block
      2. Under the Advanced > Pins menu add “analog read pin”
      3. Enter “511” on the other side of the sum
      4. Enter “512” in the “up to” field
    2. Under the Variable menu create a new variable called soundLevel
      1. Set sound level to “analog read pin P1” from the Advanced > Pins menu
    3. Under Logic drag out a “if then” block and then in the if statement:
      1. Under Logic add a 0 < 0 block and change it to >
      2. Add the variable soundLevel to one side
      3. Enter the number 512 on the other side
    4. Inside the if statement:
      1. Under variable change soundlevel by -512
      2. Under variable create a new variable called volume and set it to (soundlevel x LEDcount) / 512. The calculation blocks you will find other Math
      3. Under Neopixel menu clear the variable item
      4. Under Loops get a for loop and set it from 0 to the variable volume
      5. Inside the for loop:
        1. Add a if else if statement and add 1 if else to it
        2. For the first if: Under Logic drag out a block to compare two numbers. Set one to the variable index and the other to 10
        3. If it’s true drag out from Neopixel > Advanced “set pixel colour at 0 to red”. Change 0 to the variable index and red to green
        4. For the second if: Under Logic drag out a block to compare two numbers. Set one to the variable index and the other to 20
        5. If it’s true drag out from Neopixel > Advanced “set pixel colour at 0 to red”. Change 0 to the variable index and red to orange
        6. For the else statement drag out from Neopixel > Advanced “set pixel colour at 0 to red”. Change 0 to the variable index and leave red
      6. The final statement in the if statement is from the Neopixel menu and it’s to show the lights

 

Advertisements

One thought on “Updated: micro:bit sound sensing hoodie

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s