LED technology has now evolved and is starting to be present in a pronounced way in many environments, from the home to the offices up to public lighting. The advantages in terms of energy-saving are enormous and the quality of the light emitted is achieving satisfactory visual comfort. Even in the furnishings, we find nice solutions that range from the multicoloured living room lamp to the courtesy lights in the hobs or to the waterproof LED bars placed in the shower cubicle. Given our passion for self-construction, we will create Arduino based RGB LED Rainbow and also learn how to produce custom colors on it.

An RGB element is composed of 3 distinct LED (Red, Green, Blue) arranged so that they can interact with each other to form different complementary colors.

1. CONCEPTS

LED’s are a special type of p-n junction diodes, formed by a thin layer of doped semiconductor material. In case of RGB LED, three single LED each of its own color; Red, Green and Blue are inserted inside the same container. The mixture of three colors gives rise to a light that depends on the intensity of each color. Moreover, there are two types of RGB LED as shown below.

common cathode rgb led, common anode rgb led and rgb color mixing, rgb color wheels
Figure 1: Common Anode RGB LED (left), RGB Colour Mixing (centre) and Common Cathode RGB LED (right)

By mixing the colors with the different intensities and then superimposing one color on the other, you can have a light characterized by different shades that illuminate the environment in an elegant way; for example, light purple is given by mixing blue light with the red light. This technique is also used for electronic devices that have a flat-screen, such as televisions and monitors.

2. COMPONENTS

3. CONNECTIONS

Arduino RGB LED Rainbow Code Using PWM
Arduino RGB LED Rainbow Code Using PWM

4. PROGRAMS

Program 1: Cycle through colors of RGB LED.

/*UNCIA ROBOTICS | www.unciarobotics.com
  PROGRAM:CYCLE THROUGH COLORS OF RGB LED
  This program different colors one by one on an RGB LED

  Connections:
  9     Red
  10    Green
  11    Blue
  GND   (-)
*/

const int Red = 9, Green = 10, Blue = 11;
void setup() {
}
void loop() {
  analogWrite(Red, 255);  //Glow Red
  analogWrite(Green, 0);
  analogWrite(Blue, 0);
  delay(1000);
  analogWrite(Red, 0);
  analogWrite(Green, 255); //Glow Green
  analogWrite(Blue, 0);
  delay(1000);
  analogWrite(Red, 0);
  analogWrite(Green, 0);
  analogWrite(Blue, 255); //Glow Blue
  delay(1000);
}

Program 2: Arduino RGB LED Rainbow Code Using PWM

Arduino RGB LED Rainbow Code Using PWM | Uncia Robotics
/*UNCIA ROBOTICS | www.unciarobotics.com
  PROGRAM: ARDUINO RGB LED RAINBOW CODE USING PWM
  Glow RGB led with different patterns

  Connections:
  9     Red
  10    Green
  11    Blue
  GND   (-)
*/

// variables to hold the LED color
int Rvalue = 254, Gvalue = 1, Bvalue = 127;;
int Rdirection = -1, Gdirection = 1, Bdirection = -1;

// constants to name the pins
const int Red = 9, Green = 10, Blue = 11;
void setup() {
}

void loop() {
  //send PWM signal on LEDs
  analogWrite(Red, Rvalue);       // write analog signal
  analogWrite(Green, Gvalue);
  analogWrite(Blue, Bvalue);

  Rvalue = Rvalue + Rdirection;   //changing values of LEDs
  Gvalue = Gvalue + Gdirection;
  Bvalue = Bvalue + Bdirection;

  //now change direction for each color if it reaches 255
  if (Rvalue >= 255 || Rvalue <= 0)
  {
    Rdirection = Rdirection * -1;
  }
  if (Gvalue >= 255 || Gvalue <= 0)
  {
    Gdirection = Rdirection * -1;
  }
  if (Bvalue >= 255 || Bvalue <= 0)
  {
    Bdirection = Bdirection * -1;
  }
  delay(10);    //give some delay so you can see the change
}

FUNCTIONS USED


const( )

analogWrite( )


FAQ’s

What are the uses of RGB LED?

Having RGB Led lamps leads to many advantages: first of all, to work, they require little current and therefore are considered low consumption. The low voltage ignition allows you to install many more lights in the same place and, as mentioned above, the RGB LEDs have a longer life than the other bulbs. But in addition to this, colored LEDs find various applications in everyday life: table lamps, floor lamps, spotlights for the garden, etc … Compared to white light, the RGB LED allows you to give an extra touch to the environment and it is possible to change the light to reflect your moods or to give an extra style, whether there are guests or your family. In addition, RGB LEDs have a high light diffusion that allows you to reduce eye strain and illuminate any corner of the room, such as a reading corner. RGBW LEDs also have a warm white light available, which will illuminate all parts of the environment in which they will be placed. It is therefore particularly suitable for large rooms such as living rooms, dining rooms and corridors.

How does standard LED work?

To know the functioning of a LED diode we take into consideration that light is a form of energy and that this energy is released by an atom. Light is made up of small particles, which are called photons. Now suppose that in a LED there are several atoms with different electrons that go around the nucleus on their orbits, obviously depending on the orbit that an electron occupies it will be more or less charged with energy (the energy is directly proportional to the width of the orbit).

When one of these electrons passes from a wide orbit to a lower one going to fill a Positive gap, it loses a few of its energy and the mystery is revealed: hence the light we see, that is from the loss of energy in the form of a photon. The more energy the moving electron loses (for example with a high orbit drop) the higher the frequency of the light emitted, from here you determine the color of the light itself.

So we said that with the loss of energy during the passage from one orbit to the other the color of light is determined, now the question arises: what if we wanted to produce white light? First of all, it must be said that white light is not a color but the combination of many colors. One way to achieve this would be to use an RGB LED and mix the colors red, green and blue to make white, but this would require some control over the various LEDs which is very difficult to achieve.

However, there is another simpler and faster method of obtaining white light from a Led and is to apply a few layers of phosphorus on the top of the Led itself. Usually one chooses a blue one; these layers have the function of moving the wavelength of the light that passes through them and reproducing the white light.

Still, having doubts?

Ask your questions regarding Arduino RGB LED in comments section below or Contact Us.

Leave a Reply