Arduino Tutorial #4: RGB LED
In this tutorial, we will look into how to control the RGB LED. First, let us look at the theoretical of the RGB LED. But before that, I would like to demonstrate how it will look when you test the LED with Arduino.
Basically, an RGB LED is no difference from the normal LED, except that it has an addition of two more pins. And obviously, the internal structure is of difference from the common LED. Below is the image of the RGB LED.
Referring to the image above. we can see that there are 4 pins. Pin no 2 is the common cathode pin, Pin no 4 is for the GREEN, Pin 3 for BLUE and Pin 1 is for RED. These are the 3 main colours available from the RGB LED. We achieve or get other different colours by combining these 3 colours. The diagram below the colour combination.
As you can see the, when combining the colour you can get a different colour. We can achieve this by varying the brightness of each colour. The reason why we can see three different colour is that because our eyes have three types of light receptor. Our brain processes the amounts of red, green and blue and converts it into a colour of the spectrum.
Next, let us look into the Arduino sketch for controlling the RGB LED.
Looking into the code by section, the first part we define the pins. In our case, we connect them to the PWM pin, which is pin 9, pin 10 and pin 11.
And next is the to define the type of LED being used either common anode or common cathode. If we are using the common anode, we need to uncomment these line, whereas if we are using common cathode, we can leave it commented.
Following this line is the setup line. As we have seen in the previous tutorial, here will do the setting of the pins which we will use in this project. Basically, we will use these pin as the output.
Once this is done we will write the main program in the void_loop(). Below is the code which we will use
As we can see from the code, we have written the code to display 6 different colours. This has been illustrated in the demonstration video earlier. The first three colour is straightforward, meanwhile, the next three colour is achieved through the combination of two or three different colour. And the last portion of the code which we will look into is for controlling the brightness of each the three colour.
That's all for now. In our next tutorial, we will look into using the LED and push button.
Thank you.
Basically, an RGB LED is no difference from the normal LED, except that it has an addition of two more pins. And obviously, the internal structure is of difference from the common LED. Below is the image of the RGB LED.
RGB LED Image extracted from Kingbright Datasheet. Credit to Kingbright. |
Referring to the image above. we can see that there are 4 pins. Pin no 2 is the common cathode pin, Pin no 4 is for the GREEN, Pin 3 for BLUE and Pin 1 is for RED. These are the 3 main colours available from the RGB LED. We achieve or get other different colours by combining these 3 colours. The diagram below the colour combination.
As you can see the, when combining the colour you can get a different colour. We can achieve this by varying the brightness of each colour. The reason why we can see three different colour is that because our eyes have three types of light receptor. Our brain processes the amounts of red, green and blue and converts it into a colour of the spectrum.
Next, let us look into the Arduino sketch for controlling the RGB LED.
Looking into the code by section, the first part we define the pins. In our case, we connect them to the PWM pin, which is pin 9, pin 10 and pin 11.
And next is the to define the type of LED being used either common anode or common cathode. If we are using the common anode, we need to uncomment these line, whereas if we are using common cathode, we can leave it commented.
Following this line is the setup line. As we have seen in the previous tutorial, here will do the setting of the pins which we will use in this project. Basically, we will use these pin as the output.
Once this is done we will write the main program in the void_loop(). Below is the code which we will use
As we can see from the code, we have written the code to display 6 different colours. This has been illustrated in the demonstration video earlier. The first three colour is straightforward, meanwhile, the next three colour is achieved through the combination of two or three different colour. And the last portion of the code which we will look into is for controlling the brightness of each the three colour.
That's all for now. In our next tutorial, we will look into using the LED and push button.
Thank you.
No comments:
Post a Comment