Arduino Lesson 4
Arduino Lesson 4
Overview
Parts
Part
Qty
Breadboard Layout
Colors
Arduino Sketch
Using Internet Colors
Theory (PWM)
Other Things to Do
8/15/2017
3 Overview
In this lesson, you will learn how to use a RGB (Red Green Blue) LED with an
Arduino.
You will use the analogWrite function of Arduino to control the color of the
LED.
8/15/2017
4 Overview
At first glance, RGB (Red, Green, Blue) LEDs look just like
regular LEDs, however, inside the usual LED package,
there are actually three LEDs, one red, one green and
yes, one blue. By controlling the brightness of each of
the individual LEDs you can mix pretty much any color
you want.
8/15/2017
5 Overview
We mix colors just like you would mix audio with a 'mixing
board' or paint on a palette – by adjusting the brightness
of each of the three LEDs. The hard way to do this would
be to use different value resistors (or variable resistors) as
we played with in lesson 2. That's a lot of work!
Fortunately for us, the Arduino has an analogWrite
function that you can use with pins marked with a ~ to
output a variable amount of power to the appropriate
LEDs. 8/15/2017
6 Parts
8/15/2017
7 Parts
8/15/2017
8 Parts
8/15/2017
9 Breadboard Layout
The RGB LED has four leads. There is one lead going to the positive
connection of each of the single LEDs within the package and a single
lead that is connected to all three negative sides of the LEDs.
8/15/2017
10 Breadboard Layout
The common negative connection of the LED package
is the second pin from the flat side of the LED package.
It is also the longest of the four leads. This lead will be
connected to ground.
8/15/2017
12 Colors
The reason that you can mix any color you like by varying the
quantities of red, green and blue light is that your eye has three
types of light receptor in it (red, green and blue). Your eye and
brain process the amounts of red, green and blue and convert it
into a color of the spectrum.
In a way, by using the three LEDs we are playing a trick on the eye.
This same idea is used in TVs, where the LCD has red, green and
blue color dots next to each other making up each pixel.
8/15/2017
13 Colors
8/15/2017
14 Colors
If we set the brightness of all three LEDs to be the same, then the
overall color of the light will be white. If we turn off the blue LED, so
that just the red and green LEDs are the same brightness, then the
light will appear yellow.
We can control the brightness of each of the red, green and blue
parts of the LED separately, making it possible to mix any color we
like.
8/15/2017
16 Arduino Sketch
8/15/2017
17 Theory (PWM)
The diagram below shows the signal from one of the PWM pins on
the Arduino.
8/15/2017
18 Theory (PWM)
8/15/2017
19 Theory (PWM)
8/15/2017
20 Theory (PWM)
If however the output is at 5V for 90% of the time then the load will
get 90% of the power delivered to it. We cannot see the LEDs
turning on and off at that speed, so to us, it just looks like the
brightness is changing.
8/15/2017
21
End
8/15/2017