Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP

The OSOYOO Magic I/O Shield for Arduino is a powerful board for the beginners. With this Magic board, we can  easily connect various sensors and actuators much easier than before.

The RGB color model is an additive color model in which red, green and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green and blue. In this lesson, we will show how to use a RGB (Red Green Blue) LED with an OSOYOO Basic Board for Arduino.

RGB Module Specification

How do RGB LEDs work?

At first glance, RGB (Red, Green, Blue) LEDs look just like regular LEDs, however, inside the usual LED package, there are actually three LEDs, one red, one green and yes, one blue. By controlling the brightness of each of the individual LEDs you can mix pretty much any color you want.

How to create different colors?

The reason that you can mix any color you like by varying the quantities of red, green and blue light is that your eye has three types of light receptor in it (red, green and blue). Your eye and brain process the amounts of red, green and blue and convert it into a color of the spectrum.

In a way, by using the three LEDs we are playing a trick on the eye. This same idea is used in TVs, where the LCD has red, green and blue color dots next to each other making up each pixel.

You can create one of those three colors – red, green or blue – by activating just one LED.

For example, if you want to produce blue, you activate the blue LED and turn off the other two.

If we set the brightness of all three LEDs to be the same, then the overall color of the light will be white. If we turn off the blue LED, so that just the red and green LEDs are the same brightness, then the light will appear yellow.

We can control the brightness of each of the red, green and blue parts of the LED separately, making it possible to mix any color we like.

Black is not so much a color as an absense of light. So the closest we can come to black with our LED is to turn off all three colors.

Pulse-width Modulation(PWM)

The brightness of an LED is proportional to the current going through it, but it would be rather difficult to use a microcontroller to accurately control the current flowing through an LED. Fortunately, human vision has a nice phenomenon called persistence of vision. Persistence of vision is the phenomenon where an image that is seen for only a fraction of a second will continue to be “seen” by your brain even after the original image has vanished or moved. This this the same principle behind film and television, where a rapidly changing image tricks your brain into seeing continuous motion. By turning our LED on and off rapidly, we can trick the brain into seeing an “average” value of brightness based on the duty cycle of the driving PWM signal.

Pulse-width modulation (PWM) is the practice of modulating the duty cycle of a signal, used in this application to control the average power sent to each LED. In the following figure, we show three different duty cycles, first with 50% duty cycle, then 10% and 90% duty cycle. During the 10% duty cycle, the signal is at the logic high level for only a brief time each cycle, but with 90% duty cycle, most of the signal’s period is spent at logic high level. If the frequency of the signal is fast enough, then there will be no visible flicker, and the LED’s brightness will be proportional to the signal’s duty cycle.

RGB LED Color Control

RGB stands for the red, green, and blue color channels and is an industry color standard. RGB displays various new colors by changing the three channels and superimposing them, which, according to statistics, can create 16,777,216 different colors. If you say the color displayed doesn’t completely match a natural color, then it almost certainly cannot be differentiated with the naked eyes.

Each of the three color channels of red, green, and blue has 255 stages of brightness. When the three primary colors are all 0, “LED light” is the darkest, that is, it turns off. When the three primary colors are all 255, “LED light” is the brightest. When superimposing the light emitted by the three primary colors, the colors will be mixed. However, the brightness is equal to the sum of all brightness, and the more you mix, the brighter the LED is. This process is known as additive mixing.

First, please plug Osoyoo Magic I/O shield into UNO board:

Then connect the RGB module to the RGB port of the Magic I/O shield with a 4-pin PNP cable as below:

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to OSOYOO Basic Board for Arduino.

After above operations are completed, connect the OSOYOO Basic Board for Arduino to your computer using the USB cable. The green power LED (labelled PWR) should go on.

Open the Graphical Programming software Mixly, iMixly is not English, you should change the language first:

You can download the code directly, then click “Open” in Mixly to choose the code you download:

Download the Code

Or you can do as following operations:

  1. Click “Functions” block;
  2. Drag the first block “procedure do” to the blank space, and edit “procedure” to “RED“;
  3. Click “In/Out” block;
  4. Drag  “DigitalWrite PIN#” to fit “do RED” block, and edit the parameter to “DigitalWrite PIN# 11 Stat HIGH“;
  5. Repeat step 3 & step 4, fit the three “DigitalWrite PIN#” blocks, and edit the other two blocks parameter to “DigitalWrite PIN# 12 Stat LOW“ and “DigitalWrite PIN# 13 Stat LOW“.

  1. Right click the “do RED” block;
  2. Duplicate the existing blocks;
  3. Edit the parameter as the picture shows;
  4. Refer to the above step 1-3 to finish the blocks, remember to edit the parameter as the picture shows.

  1. Click “Functions” block;
  2. Drag  “do RED” block to the blank space;
  3. Click “Control” block;
  4. Drag  “Delay” to fit “do RED” block(use default delay time 1000 ms);
  5. Refer to the above step 1-4 to finish the blocks.

The whole program blocks are as following:

After above operations are completed, do as following:

  1. Click Save after programming is done.
  2. Select the board type and serial port before uploading. In our case, we use  UNO board, so just select Arduino/Genuino Uno. If you use a Mega2560, select Arduino/Genuino Mega or Mega2560.
  3. Select the serial device of the OSOYOO Basic Board for Arduino from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your OSOYOO Basic Board for Arduino and re-open the menu; the entry that disappears should be the OSOYOO Basic Board for Arduino. Reconnect the board and select that serial port.
  4. Next, click upload to send the program to OSOYOO Basic Board for Arduino. If uploading fails, check connection according to the prompts.
  5. Finally, the status will change to ‘Upload success!’.

how_to_play.png (1150×56)

A few seconds after the upload finishes, you should see the RGB LED flash circularly in red, green, and blue  colors.