Hi, welcome to Arduino tutorial from Robojax.
my name is Ahmad Shamshiri and the tutorial going to show you how we can
control an RGB LED using Arduino. to get different color or using this RGB LED
module or standalone RGB LED like this see how we can calculate the resistance
then then you want to find out the pinm subtract and divided by zero point zero
one eight and you get one hundred and fifty five one resistor you can get the
code for this by clicking at the link of the description below which will take you to
www.robojax.com/learn/arduino let's get started with this.
I am presenting this tutorial from Canada.
what is an RGB LED RGB LED is a light emitting diode and RGB stands for red
green and blue RGB means a combination of three diodes in one package. that have
either a common-cathode or common -node so the common anode is that these are
anodes and also common this pin is called anode and this is on this side which we
have a line is called cathode. so I know the common anode all of the more common
and you just turn on cathode of whichever you want for example if you
want the red to be turned on so this is connected to positive all of will have you
just need to connect the negative to this cathode of red if you connect
negative to this the green will be turned ON. if you connect it to this the
blue blue will turn ON. same thing this time the cathodes are connected together
to the negative and you will connect the positive 200 of each of those to you
turned on a combination of colors will create different color for you if you
combine or the combination of colors will create the color this color for you
as you can see here this is red green blue the maximum value that you get is
255 (2 to power 8 = 256-1 = 255) now this this means red is full rightness and green and blue or a
zero there is no color of blue and green so that's why you are getting red and
for green you get 255 so now it's full green and then if you want blue just
turn that one off and then 255 will give you blue. so pay attention here if you
want color black red green and blue must be zero. so when there's no color exist
that's why we call it black if you want this one to be white so all of them
should have maximum so with combining
red green and blue you can get white color. this is also true in real life. I
will provide the link for this so you can play with. the color the combination
of both of these will give you another color. for example if you have blue and then
red you will get pink or if you want green and red you get yellow. or if you
get these two color you get aqua. and then the variation of all those numbers
as I move this lesser than the blue so I want to go in this area within different
shades of green or if I go and in here different shades of red. from darkest to
any color you want. this is the hex value or hexadecimal value that are used in many
applications 181 62 and 83 so these are the value B and five and three E and 53
if I put here zero you see that becomes zero green zero the second two digits
will become zero now 83 in terms of decimal is 53 in terms of hex. if I put
the zero on that one also become 0 if I go to 55 you will see this would become
F F. F F so the first two digits are for red two or for green and two or for
blue. and we have two types of leds either there's regular LED with
different sizes from 1 or 2 millimeters that goes 10 to 15 millimeter huge sizes
and this is SMD or surface mount device that we have 3 LEDs connected together
in a surface mount. this is the surface mount device it has three pins and one
common. for that reason they have connected it as green ground red green
and blue even you can see the actual under the lens you can see those
pieces. that not I shown you and here this is the diode that I just spoke
about so this has one common and then T just common cathode and this is also
common cathode. if you see VCC or any of this module then that module is common
anode and if you see ground and ground the
fifth common cathode.
Datasheet viewed
here is a data sheet for example this is one of the surface mount LED that shows
here for example for the pin. here that they needed 18.5 mA
typical for this one. and here is the operating voltage for red green blue
1.8 to 2.2V and then for the green is 3.0 to 3.2V
and blue is 3.2 to 3.4V keep that in mind and that
the average led currents for each piece for red for green and blue about twenty
milli ampere and average voltage is around 2 volts as you saw it was from
1.8V to 2.X something or even three but average is around
2.2V and average current is about 20mA. so based on
that average you can do your calculation or refer to the data sheet of each
specific LED that you purchase.
Calculating value for Resistor
now let's see how we can calculate the resistance this is common anode you will
put your resistor and cathodes and each LED will have separate independent
resistor and they are almost equal so you can calculate the same value and put
for all unless it's very critical. and if you have common cathode again the side
that is common you leave it and on the other side you just put now this side
there is resistors are connected in anode so let's say on the datasheet you read that the
voltage over lead is 2.2 V volts and rated current I is 18 mA and
the VCC is here that you want to connect is 5 volts and that 18 mA will
be 0.018 ampere so let's say you want to find the resistor so this is the
formula VCC-VLED /I so V/I=R V is 5 volts this is VCC is 5
volts and LED voltage is 2.2V subtract and divide by 0.01a
and you get 155 ohm resistor. if you go with the lower voltage
3.3 volts now and it just has changed and you get 61 ohm
and if you are connecting an LED to 12 volts the same thing 12 minus 2.2
and this is the current 544 ohm resistor is needed. if any of these
values are not available directly for example you will not find 155 you might
150 ohm and then 68 ohm resistor or 560 ohm which are
one of the standard resistors that are closer you can get it.
and this module have that tree resistors one two and three and if I put magnifier
if you look at , it says 102 if you can read it that 102 means 10
and 2 means two zeros they put one kilo ohm making sure that this module
can work let's say up to 18 V or higher voltages. and on this one also we
have these resistors that three you can see there is resistor are
written 1 0 2 that's 1 kilo. now let me explain the wiring has connected 10 11
12 and 13 from arduino as you can see this is on this side accordingly and
then the last pin green is GND so ground is connected here and then i have
11 and then 12 and 13 are connected here.
Identifying RGB LED Pins
and if you have this type of LED in your hand and you want to find out the pins
as you can see one of the pin is the longest one and that is the common.
I have connected these two wires here to 3.3 volts and ground so this is ground 3.3
volts in the common and then move this connected to this pin now it's turned on
connected to that the second one turned on blue so that's all that is G that is
B blue and if you reverse it you see that the light will not turn ON. so you
know that the positive is common and that when positive is common we call it
common anode.
let me now explain the code. at the top of the line first I've defined for the
red green and blue pins 11 12 and 13 these are for pulse width modulation (PWM)
control of the different value and then we have this as a color time that that
between each color this sketch wil show so I said that for 2 seconds or whatever
you want. and these are the colors that are a little famous I just put a few
colors with the name and these are the value white red green blue and all these
values including pink aqua yellow brown and I put another array these names so
it will print it or for us on the serial monitor. and then we set up serial
monitor with 9600 baud make sure that this 9600 baud is selected accordingly
so you can see the text. it after that we said the red the red is defined here as for
example 13 and all those values this is just a number and we said an output and
then we said that as law so the ideas off and then we said the green
pin as an output blue pin as an output
and also set them LOW.after that inside the loop I've written this for
loop which goes from 0 to 7 and 8 steps so it goes for a different color that I
have defined here to print all those color for us or turn the led with those
colors. and here is we say color "j" this J becomes 0 1 2 3 and 4 and then
colors J 0 means the first color color G 1 means the second color j 0 mean the
third one so this is the R this is the G this is the B, RGB 0 1 2 and it has been
defined here or G and B all of those will have 3 values.
so it passes this value in to RGB LED and press this text for us and wait for
the time that we set above and this time that we set here. for two seconds
now let's have a look at this function RGB_LED. RGB_LED receives the
value and we call them here R small R small G small B and then when we receive
them we send this pin the value to the green pin, this value to the blue pin
this B value will turn the LED for us so just makes our code very neat. and the
loop continues like that after this it will just go our repeated
Demonstration
let me know demonstrate the color. the system is starting as you can see it
shows white red green now blue yellow aqua pink brown the camera doesn't show
properly the color but if you go further away because the camera is very close
you will see actual real color because they will be mixing up and we are here
the camera is very close-up so you can distinguish and see each led all those
billboards that you see majority of those are based on this RGB and that's
why you don't see any difference that it looks like actual color photo
I would like to thank my Patrons from Patreon.com
I did my part to help you learn. Now it's your turn.
You can subscribe to my channel, thumb up 👍 the video and say "thank you" in the comment section.
The link to my PayPal account is below this video if you want to send me chase donation. Thank you.
thanks for watching this with how to use these two types of G BDD and control
them with our if you learned something and found it useful please thump up 👍 as
this will help my video in the search algorithm of YouTube. if you have comment
or question please post a comment section below I try to answer a reply.
and to get updates of my upcoming videos make sure to subscribe