male-to-female jumper wires (SparkFun PRT-09385) to extend each of the LEDs. You’ll need a total of six of these jumper wires. Simply plug each LED leg into thefemale end of the jumper wire. To keep things organized, we like to use black wires for the negative (shorter) leg and colored wires for the positive (longer) leg, as shown in Figure 2-26 .
FIGURE 2-26: Attaching jumper wires to the LEDs
With the jumper wires connected to the LEDs, plug the male end into the breadboard in the same place where the LED came out, as shown in Figure 2-27 . Again, pay attention to which LED goes where. If you don’t remember, consult the original diagram in Figure 2-10 .
FIGURE 2-27: Inserting the male end of each jumper wire into the breadboard
Check to make sure your connections work by plugging in the Arduino to your computer or to a battery pack. If one of the lights isn’t working, try jiggling the connections or double-checking that the wires are plugged into the correct row on the breadboard.
You can either leave the Arduino and breadboard outside the Stoplight housing or tack them inside the housing with glue or double-sided tape. Whatever you decide, when you’re done, power up your Stoplight, and go find a busy hallway intersection in need of traffic safety.
Figure 2-28 shows the finished Stoplight in all its glory.
FIGURE 2-28: Finished Stoplight project
GOING FURTHER
The concepts you saw while building the Stoplight, such as timing the control of output (LEDs), can be applied to a number of different uses in your house and life. Here are a couple of suggestions for adapting the Stoplight.
Hack
The basic concept of a stoplight is all about timing. When else would a timer be useful? What about changing the code to help you time frying an egg? You could rework the Stoplight so that the red LED is lit while the egg is still in a state of “iffy” or “rare” doneness, the yellow LED lights when it’s almost cooked the way you like it, and then the green LED lights when the egg is done.
We can’t give you the timing, as we probably have different preferences for how we like our eggs cooked. There are also a number of variables that will affect the timing, like the temperature, the type of pan, and the size of the egg. You’ll have to figure that all out on your own.
In the code, you’d need to work with pretty big numbers for the delay, since it’s measured in milliseconds. To set a delay in minutes, all you need is a little multiplication. Remember that 1,000 ms equals 1 second; multiply by 60, and you’ll find that 60,000 ms equals 60 seconds, or 1 minute. For a delay of 3 minutes, you can multiply 3 by 60,000 directly in the delay() function, like this:
delay (60,000 * 3);
You may be wondering how long you can set the delay() function for. The data type that delay() receives is an
unsigned long
, which is any number that falls in the range of 0 to 4,294,967,295. So the maximum delay is 1,193 hours or so. Pretty cool! Knowing this, is there anything else you’d want to time with the delay() function?
Modify
If you’re looking to make this project more permanent and sturdy, you can solder wires to the LEDs instead of using the male-to-female jumpers. If you’ve never soldered before, turn to “ How to Solder ” on page 302 for some soldering instructions before you start. You’ll need to snip the end off of a male-to-male jumper wire, strip the insulation back about 1/2 inch using wire strippers, and then solder the stripped end to each leg of a trimmed LED, as shown in Figure 2-29 . Notice that we twisted the wire around the leg of the LED to hold it securely while soldering. After soldering, the connection will be more durable, and you’ll be able to use the LEDs for other projects since the other end is still a male jumper.
FIGURE 2-29: Soldering a cut jumper wire to an LED
Though this project looks impressive, the programming and hardware are pretty simple. As you read about sensors and