Lesson 16

LED strips

The Upgrade Kit  contains two LED strips covered with a video protector. This is what the LED strips inside the protector look like:

These LEDs are very popular. As you can see in the photo below, you can find them in many lengths and shapes. Our LED strips have 15 LEDs each.

Step 1: Connect the strip

The black connector on our LED strips connects to the cable we installed in the previous lesson. Connect one of our LED strips to the cable as shown in the video below:

Now that the LED strip is connected to Arduino, let’s learn how to tell Arduino to turn the lights on.

Step 2: Make sure Arduino Nano is installed

 

Open mBlock and make sure Arduino Nano is in the devices list.

 

If Arduino Nano is there, you can skip this step. If it is not in your Devices, add it as shown below:

Step 3: Install PR-Advanced extension

mBlock doesn’t support LED lights and MP3 player by default, so will will need to install an extension that will enable programming these components.

Search for “PR-Advanced” and install it as shown in the video below.

Please note this is a two step process. First, you will need to download it by clicking on the blue “+” sign. Then, you will need to search for it again and click on “+Add”.

The PR-Advanced is our second extension. It is required to program the new components in this kit. This is an addition to the regular PlayRobotics extension we installed in Lesson 7 Step 1.

Step 4: Setup LEDs

First, we need to tell Arduino that we will be using LEDs and which pin the LEDs are connected to (in our case, it will be pin 10).

We also need to tell Arduino how many LEDs we are going to have.
I our case we have 2 strips of 15 LEDs each, so 30 LEDs in total.

Update your code as shown in the video:

Step 5: Light a LED

Now it is time to light our first LED. Update the code as shown in the video below and upload it.
Then, we will explore how the code works.

This is the result you should get:

Now, let’s see how the Set LED block works.

The first parameter in this block is the address of the LED we want to illuminate. The other parameters are a mix of red, green, and blue colors. By mixing these color settings, we can produce thousands of different colors.

Let’s learn more about these parameters. 

Address parameter

Our strip has 15 LEDs, and each LED has a unique address. (Imagine the LED strip as a street with 15 houses, each with a unique address number).

In computer programming, counting usually starts from 0, not 1.

In our example, we asked Arduino to turn on an LED with the address of 1. Since the first LED’s address is 0, we actually asked Arduino to paint the second LED and not the first one!

Try changing the address from 1 to 0 in your code and upload it.
This is the result you you will see:

RGB colors

It is really hard to see, but each of our LEDs in the strip has three tiny LEDs inside of it!

So technically, we have 45 tiny LEDs in each 15 LEDs strip.

When looking from a distance, the tiny LEDs are not visible. Instead of seeing three tiny LEDs with different colors, we see one big LED with a single color. The single color is determined by how bright each of the three tiny LEDs is.

By telling Arduino how bright each of the tiny LEDs should be, we can mix colors and create any desired color we want.

By mixing Red Green and Blue colors we can get 16,777,216 different colors!

 The strength of each color is defined by a number from 0 to 255 (0-LED is OFF , 255- Max power).

Some examples:

Red -> Red: 255 | Green: 0 | Blue: 0

Yellow -> Red: 0 | Green: 255 | Blue: 255

Violet -> Red: 238 | Green: 130 | Blue: 238

Try changing the RGB value in your block and see how the colors of the LED change.

Below is an example of the color yellow. (Feel free to be creative and try other colors!)

We are done!

Well done! Now we know how to light LEDs!

In the following lessons, we will make some advanced things, such as animations with LEDs!