Controlling an RGB LED Diode with Arduino

11 May

Introduction:

There comes times where we want to use the RGB LED Diode, the RGB Diode is great for colour mixing and creating a rainbow of colours. But sometimes, using the 4 legged RGB LED lights can be a little confusing. So, let’s run through some basics and get you up and running in no time!.

How does the RGB LED diode work?

The RGB LED diode consists of 3 small led light modules inside it, which are Red, Green and Blue colour. There are 2 types of RGB LED lights.

Common Anode

Common Cathode

Common Anode is the most commonly used. So, you can assume that the one you have is more than likely a common Anode type.

The colour produced by an RGB LED light is in fact the combination of those 3 LED lights. As the LEDs are very close to each other, we can only see the final colours result rather than the three colours individually.

Code Explanation:

In this code, we have written a few loops to vary the internal Red, Green and Blue lights individually to see the colour variations.

Through using the analogWrite() function we are generating PWM. The value of the function can be any integer number between 0 to 255, where 0 means always off and 255 means always on. Anything between them adjusts the intensity of the light. So first we start by slowly adjusting the intensity of the red light from 0 to 255, then we increase the intensity of the green light and then the blue. We give a little delay so the colour changes can catch our eyes.

Then we decrease the intensities of the lights one by one through 3 loops.