What to expect
In this activity, you will connect and code an RGB LED module that can produce a variety of colors and intensity levels (brightness). Then, you will create a program that changes the light based on sounds from your local environment as captured by the micro:bit.
Connections
In previous activities, you experimented with digital signals (on/off). An RGB LED uses analog signals, which are capable of having a range of states – not just on or off. An RGB LED module is actually made up of three LEDs, each with 256 possible output options. That means that there are over 16 million possible combinations of color! After this activity, you’ll have many ideas you can use in your smart party house – the final project for this unit.
Materials
Micro:bit w/ USB cable and battery pack
Motor Driver Board w/ external battery pack or USB power supply cable
(you won’t use a motor here, just the connection on the board)
RGB LED Module
RGB Jumper Connectors
Instructions
There are 3 main parts to this activity
Circuit Setup
Creating a Basic Program to Test the Circuit
Controlling the RGB LED with Sounds From the Environment
Circuit Setup
Setup the circuit as shown in the images below. Note the use of the motor drive board and jumper wires. This is help make the connection to the RGB LED module easier and so that you can see how to add to it later!
Hint: The black wire (ground or minus) can conect to ANY black GND terminal.
Creating a Basic Program to Test the Circuit
Create and download the following code to your micro:bit. This will test your LED module setup. If everything is connected and coded correctly, it should act like a digital signal, in that it simply turns the RGB LED module (technically there are 3 LEDs!) on and then off every second.
2.4.1 RGB LED Random Color Every One Second : https://makecode.microbit.org/S76178-92147-60843-15963
If something isn’t right, check your hardware connection and code before moving on.
Next, create and download the following code. This program will allow you to choose a color value between 0 - 255 for each of the LEDs, then choose a brightness between 1-4.
2.4.2 RGB LED: https://makecode.microbit.org/S22631-39686-66124-00825
If you choose a color or brightness value of zero, what happens?
Want to set a specific color? (There are over 16 million options, it’s hard to remember them all…) Type “color picker” into the Google search bar and you’ll get an option to find the values for R, G, and B based on the “mixed” color output. Note: These RGB LED modules may not look exactly like the final mixed result, because they do not have a diffuser on them, which softens the glow of the light making the colors appear to mix smoothly.
Controlling the RGB LED with Sounds From the Environment
Now things are getting interesting! Create and experiment with the following code to use the built-in microphone to randomly change the color and brightness based on sound input. Sound is an analog input signal, because it can be a range of volumes. However, in this example, we are using the built-in functions of the micro:bit to listen for “loud” vs. “soft”. If you want to try to be more “scientific” with your coding, try using the input options in the sound blocks library (you can always right-click on a block to learn more about how to use it and related blocks.)
2.4.3 Sound Controlled RGB LED: https://makecode.microbit.org/S82786-58829-15585-34659
To test: Clap your hands then snap your fingers; try whispering vs talking, or play your favorite song and watch how the RGB LED module changes!
Think about it
In this activity, you created your own party light system that can change color and intensity based on programmed input conditions.
Where have you seen RGB LEDs used around you? Why were/are RGBs used instead of a single color?
What other inputs (besides sound) could be used to control an RGB LED? Why?
If you have time, try your ideas out!
Feedback link