The Arduino Inventor's Guide (23 page)

BOOK: The Arduino Inventor's Guide
11.86Mb size Format: txt, pdf, ePub
5
A Color-Mixing Night-Light

The wonderful thing about digital electronics and microcontrollers is that they are smart. They can read sensors and make decisions based on what those sensors tell them.
Sensors
are components that collect information about the environment around them and convert that into something a microcontroller can understand.

You can use sensors to make projects that react to all sorts of stimuli (like temperature, sound, and the proximity of an object), but in this project, we’ll start small with a night-light that reacts to changes in light level, shown in
Figure 5-1
.

FIGURE 5-1:
Finished Night-Light project

MATERIALS TO GATHER

This project uses a new kind of LED and a
photoresistor
, a sensor that changes resistance based on how much light it detects. We encourage you to be creative and design a custom shade, too, but if you don’t feel up to that challenge yet, fear not! This book’s resource files include a shade design you can start with.
Figures 5-2
and
5-3
show the parts and equipment you’ll need for this project.

Electronic Parts

NOTE

The parts marked with an asterisk (*) do not come with the standard SparkFun Inventor’s Kit but are available in the separate add-on kit.

• One SparkFun RedBoard (DEV-13975), Arduino Uno (DEV-11021), or another Arduino-compatible board

• One USB Mini-B cable (CAB-11301 or your board’s USB cable; not shown)

• One solderless breadboard (PRT-12002)

• One mini breadboard (PRT-12043*; not shown)

• One RGB LED, common cathode (COM-09264)

• Three 330 Ω resistors (COM-08377, or COM-11507 for a pack of 20)

• One 10 kΩ resistor (COM-08374, or COM-11508 for a pack of 20)

• One photoresistor (SEN-09088)

• Male-to-male jumper wires (PRT-11026)

• Short 4-inch male-to-male jumper wires (PRT-13870*)

• (Optional) Male-to-female jumper wires (PRT-09140*)

• (Optional) One 4 AA battery holder (PRT-09835*; not shown)

FIGURE 5-2:
Components for the Night-Light

Other Materials and Tools

• Craft knife

• Metal ruler

• Glue (hot glue gun or craft glue)

• One sheet of cardstock (not cardboard), about 8.5 × 11 inches

• One sheet of white or translucent vellum, or standard copy paper, about 8.5 × 11 inches

• Enclosure template (see
Figure 5-20
on page
144
)

FIGURE 5-3:
Recommended building materials for the Night-Light

NEW COMPONENTS

You’ll be using two new components in this project: an LED that has three colors integrated into a single package, and a photoresistor. Let’s take a look at how these components work.

The RGB LED

If you’ve built any of the other projects in this book, then you already have experience with regular LEDs. The
red, green, blue (RGB)
LED shown in
Figure 5-4
works very similarly. This LED is actually three LEDs in one package: one red, one green, and one blue. Each LED has its own positive (or anode) leg, but they all share a single negative (or cathode) leg, called the
common cathode
.

If you look closely at the LED in
Figure 5-4
, you’ll notice that the legs are all different lengths. With regular LEDs, the short leg is the negative leg, but with the RGB LED, the longest leg is the negative leg. The circuit diagram for this component is usually drawn like
Figure 5-5
. Notice that it shows three separate LEDs connected together, and they each share a single negative connection.

FIGURE 5-4:
An RGB LED with a common cathode leg

FIGURE 5-5:
Circuit diagram of an RGB LED

To figure out which positive leg is which color for this particular LED, orient the LED so that it looks like the one shown in
Figure 5-5
. In this orientation, the leftmost leg is the red positive leg. The next leg (the longest one) is the shared negative leg, and the last two legs are the green and blue positive legs, respectively.

Keeping in mind which positive leg corresponds to which color, you can wire this LED into a circuit just like you would three separate LEDs. Just connect the positive leg(s) you want to use to power or to an Arduino output pin through a current-limiting resistor, and connect the common cathode to ground.

RGB LEDs are cool because you can use them to create a slew of colors. Red, green, and blue are the primary colors in the additive color scheme, and the LED can mix these colors to create light in other colors. (This is different from the
primary pigments
—red, blue, and yellow—which, as you might remember from grade-school art class, mix together in paints to create new colors.) The additive color wheel in
Figure 5-6
shows how primary colors can combine to create any color in the rainbow.

FIGURE 5-6:
The additive color wheel

With your RGB LED, if you turn on the blue LED and the red LED together, you get magenta light. Combine the red and green LEDs, and you get yellow. If all the LEDs are on, you get white light. This concept is the foundation for how an LED TV or monitor works: each pixel on your screen is essentially an RGB LED.

The Photoresistor

This Night-Light will turn on when it is in a dark room and turn off when the room is bright. That means the Night-Light needs to determine whether the room is dark. To do so, it uses a light sensor to monitor the light level of its surroundings. There are a number of different light sensors available, but we used the simple photoresistor
shown in
Figure 5-7
. This component is sometimes also called a
light-dependent resistor (LDR)
or a
photocell
. Also, similar to many other types of sensors, a photoresistor is sometimes referred to as a
variable resistor sensor
.

The resistance of the photoresistor in this project varies from about 80 Ω to around 1,000,000 Ω (1 MΩ) depending on how much light it is exposed to. The photoresistor has a low resistance when exposed to bright light and a high resistance when it’s in the dark.

FIGURE 5-7:
A photoresistor

To use the photoresistor to measure brightness, you have to place it in a
voltage divider
circuit, like the one in
Figure 5-8
. A voltage divider uses two resistors wired in
series
(that is, in line with each other) between a supply voltage (5 V) and ground to obtain a smaller voltage.

FIGURE 5-8:
Voltage divider circuit

Other books

From the Fire III by Kelly, Kent David
Religion 101 by Peter Archer
ShameLess by Ballew, Mel
Touched by Lilly Wilde
Hard to Hold on To by Laura Kaye
Fated: An Alpha Male Romance by Walker, K. Alex
One Boy Missing by Stephen Orr
Merry and Bright by Jill Shalvis