micro:bit – How to use the Sound Sensor to Control Lights

Sound Lights Feature Photo

Description

This project is a beginner project to show how to use the sound sensor on the micro:bit to trigger a behavior based on the sound level. We will use the sound sensor to turn the LED array lights on in response to a loud sound, then turn them off when the sound level gets quiet.

Video

Programming Language

MakeCode Blocks

Difficulty Level

Easy beginner

Age Level

11 and up

Programming Concepts Covered

  • Event Handling

Materials

This project can be done completely online using the micro:bit simulator built into MakeCode, but having a micro:bit will give a better understanding of how the micro:bit senses sound.

Designing the Project

Develop the problem statement

The problem I am trying to solve is getting the lights to turn on when a loud sound is made, then go off when the sound gets quiet.

Write the Algorithm

The design of this algorithm is based on events happening, so

  • When a loud sound is heard
    • show LED icon
  • When the sound level is quiet
    • Turn the LEDs off

Note that this is a pretty simple algorithm. A more complex algorithm might need to be turned into pseudocode prior to writing the actual computer program.

Write and Test the Code

Here is the video tutorial of the project:

 

Here is the code I wrote.