Arduino Tutorial: How to use an RGB LED with Arduino.

Dear friends welcome to another video tutorial! Today we are going to learn how to use anRGB led with Arduino.

There is a lot to cover so let’s get started! Hey guys, I am Nick and welcome to educ8s.

tva channel that is all about DIY electronics projects with Arduino, Raspberry Pi, ESP8266and other popular boards.

In this video we are going to learn how touse an RGB led with Arduino, a very interesting type of LED.

As you can see I have connected this LED toan Arduino Uno and every second it changes its color.

That’s very handy because we can use onlyone LED in our projects and produce many colors! But what is an RGB LED? An RGB LED is a light emitting diode whichcan display any color we want.

It consists of 3 discrete LEDs, a RED, a GREEN, and a BLUE LED housed in a single package.

So by combining these 3 colors we can createany color.

As you can see, the RGB LED has 4 pins.

So far the LEDs we were using only had 2 pins.

The pins are used in order to control thecolor of the LED.

The longest pin is either the anode or thecathode depending on the type of the RGB LED.

The LED I have bought is a common cathodeLED so the longest leg will be connected to GND.

If it was a common anode LED, the longestpin would connect to 5V.

The other three pins are Red, Green, and Blue.

Let’s connect this RGB LED to Arduino andsee how to make it work.

The parts that we are going to need for thisproject are the following: • An Arduino Uno• An RGB LED • 3 330 Ohms resistors• A small breadboard • Some wiresYou can find links for all the parts in the description of the video below.

Let’s now connect the parts together.

I have connected an RGB LED to a small breadboard.

This is the longest pin, this the RED pin, the Green and the Blue.

In order to limit the current that will runthrough it we need to use 3 resistors, one for each color pin.

If we do not use a resistor or if we use alow value resistor the LED will be destroyed.

We need to use a 330 Ohms resistor or higher.

The higher the resistor value though the lowerthe brightness of the LED, so the ideal resistor value is 330 Ohms.

Now all we have to do is to connect the firstpin of the LED to digital pin 9, the second pin to GND, the third pin to digital pin 10and the last pin to digital pin 11.

In this first example you can use any digitalpins you like.

Now if we power up Arduino we can see thatthe LED lights up RED, then GREEN, and BLUE.

All we do in the code is to write HIGH toone digital pin of the Arduino and the LED will light up.

So, if we write HIGH to digital pin 9 whichis connected to the first pin of the LED, the LED will turn RED at the highest brightness.

We follow the same procedure for the othertwo pins as well.

But if we want to control the brightness ofthe LED in order to produce more colors we have to use the PWM functionality of the Arduino.

Pulse Width Modulation, is a technique forgetting analog results with digital means.

Instead of writing HIGH to the digital pin, with PWM we send a pulse.

The more time the signal is HIGH the brighterthe LED appears to the human eye even though it turns on and off quickly.

PWM is attached to certain pins of the ArduinoUno.

Those digital pins the support PWM have thissymbol next to them.

I will prepare a detailed tutorial on PWMsoon because it is a very useful feature.

We have connected the RGB LED to digital pin9, 10 and 11 which support PWM so we can run another example code that produces more colorsusing the PWM feature.

Let’s see.

As you can see that LED now produces manycolors, and with different brightness.

Less see how to achieve that in code.

I am using a simple function which is namedsetColor to set the color of the LED.

This function takes three arguments.

The first one is the brightness of the redLED, the second one is the brightness of the green and lastly the brightness of the blueLED.

In each case the number will be in the range0 to 255, where 0 means off and 255 means maximum brightness.

The function then calls 'analogWrite' commandto set the brightness of each LED.

So, in this line we set the brightness ofthe red LED to 1 which is the lowest value that we can set, and the other two LEDs aredisabled.

So, the result we get is RED color with verylow brightness.

In this line of code we set the brightnessof the RED LED to maximum so we get a very bright red color.

If we light up more than one LEDs and settheir brightness we can create any color we like.

For example in this line of code we createthe yellow color! You can experiment with the code and createyour own colors easily.

As always you can find the code of the examplesin the description of the video.

As you can see using an RGB led with Arduinois very easy.

Now we can easily add RGB LEDs to our projectsin order to make them much more interesting.

I am going to use RGB LEDs a lot in my futureprojects.

I hope that you liked this video, if so pleasepress the like button below.

It really helps! Thanks! If this is your first time here, I would loveto have you subscribed.

In this channel I post videos about DIY projectsevery Saturday.

I love making things and I believe that anyonecan make things, anyone can become a maker.

That’s why I created this channel, in orderto share my knowledge with the community and learn from the community.

I hope you will join us.

Until next Saturday, Watch, Learn, Build! [ Translating these subtitles? Add your name here! ].

Leave a Reply