Indicator lights give people a way to see a representation of what’s going on inside a device, or patterns of communication between two devices. Next, you will build indicator lights to display the communication signals that the Arduino will send to the servos. If you haven’t ever built a circuit before, don’t worry, this activity shows you how.
A resistor is a component that resists the flow of electricity. This flow of electricity is called current. Each resistor has a value that tells how strongly it resists current flow. This resistance value is called the ohm, and the sign for the ohm is the Greek letter omega: Ω. (Later on you will see the symbol kΩ, meaning kilo-ohm, which is one thousand ohms.)
This resistor has two wires (called leads and pronounced “leeds”), one coming out of each end. The ceramic case between the two leads is the part that resists current flow. Most circuit diagrams use the jagged line symbol with a number label to indicate a resistor of a certain value, a 470 Ω resistor in this case. This is called a schematic symbol. The part drawing on the right is used in some beginner-level texts to help you identify the resistors in your kit, and where to place them when you build circuits.
The resistors in your parts kit have colored stripes that indicate what their resistance values are. There is a different color combination for each resistance value. For example, the color code for the 470 Ω resistor is yellow-violet-brown.
There may be a fourth stripe that indicates the resistor’s tolerance. Tolerance is measured in percent, and it tells how far off the part’s true resistance might be from the labeled resistance. The fourth stripe could be gold (5%), silver (10%) or no stripe (20%). For the activities in this book, a resistor’s tolerance does not matter, but its value does.
Each color bar on the resistor's case corresponds to a digit, as listed in the table below.
Digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Color | black | brown | red | orange | yellow | green | blue | violet | gray | white |
Here’s how to find the resistor’s value, in this case proving that yellow-violet-brown is really 470 Ω:
Yellow-Violet-Brown = 4-7-0 = 470 Ω.
A diode is a one-way electric current valve, and a light-emitting diode (LED) emits light when current passes through it. Since an LED is a one-way current valve, you have to make sure to connect it the right way for it to work as intended.
An LED has two terminals: the anode and the cathode. The anode lead is labeled with the plus-sign (+) in the part drawing, and it is the wide part of the triangle in the schematic symbol. The cathode lead is the pin labeled with a minus-sign (-), and it is the line across the point of the triangle in the schematic symbol.
When you build an LED circuit, you will have to make sure the anode and cathode leads are connected to the circuit properly. You can tell them apart by the shape of the LED’s plastic case. Look closely at the case—it’s mostly round, but there is a small flat spot right near one of the leads, and that tells you it’s the cathode. Also note that the LED’s leads are different lengths. Usually, the shorter lead is connected to the cathode.
Always check the LED’s plastic case.
Usually, the longer lead is connected to the LED’s anode, and the shorter lead is connected to its cathode. But sometimes the leads have been clipped to the same length, or a manufacturer does not follow this convention. So, it’s best to always look for the flat spot on the case. If you plug an LED in backwards, it will not hurt it, but it won’t emit light until you plug it in the right way.
The white board with lots of square sockets in it is called a solderless breadboard. This breadboard has 17 rows of sockets. In each row, there are two five-socket groups separated by a trench in the middle. All the sockets in a 5-socket group are connected together underneath with a conductive metal clip. So, two wires plugged into the same 5‑socket group make electrical contact. This is how you will connect components, such as an LED and resistor, to build circuits. Two wires in the same row on opposite sides of the center trench will not be connected.
The prototyping area also has black sockets along the top, bottom, and left.
Digital and analog pins are the small pins on the Arduino module’s Atmel microcontroller chip. These pins electrically connect the microcontroller brain to the board.
A sketch can make the digital pins send high or low signals to circuits. In this chapter, we’ll do that to turn lights on and off. A sketch can also make a digital pin monitor high or low signals coming from a circuit; We’ll do that in another chapter to detect whether a contact switch has been pressed or released.
A sketch can also measure the voltages applied to analog pins; we’ll do that to measure light with a phototransistor circuit in another chapter.
(2) LEDs – Red
(2) Resistors, 220 Ω (red-red-brown)
(3) Jumper wires
Always disconnect power to your board before building or modifying circuits!
1. Set the BOE Shield’s Power switch to 0.
2. Disconnect the programming cable and battery pack.
The image below shows the indicator LED circuit schematic on the left, and a wiring diagram example of the circuit built on your BOE Shield’s prototyping area on the right.
The next picture will give you an idea of what is going on when you program the Arduino to control the LED circuit. Imagine that you have a 5 volt (5 V) battery. The Board of Education Shield has a device called a voltage regulator that supplies 5 volts to the sockets labeled 5V. When you connect the anode end of the LED circuit to 5 V, it’s like connecting it to the positive terminal of a 5 V battery. When you connect the circuit to GND, it’s like connecting to the negative terminal of the 5 V battery.
On the left side of the picture, one LED lead is connectd to 5 V and the other to GND. So, 5 V of electrical pressure causes electrons to flow through the circuit (electric current), and that current causes the LED to emit light. The circuit on the right side has both ends of the LED circuit connected to GND. This makes the voltage the same (0 V) at both ends of the circuit. No electrical pressure = no current = no light.
You can connect the LED to a digital I/O pin and program the Arduino to alternate the pin’s output voltage between 5 V and GND. This will turn the LED light on/off, and that’s what we’ll do next.
Volts is abbreviated V.
When you apply voltage to a circuit, it’s like applying electrical pressure. By convention, 5 V means “5 V higher than ground.” Ground, often abbreviated GND, is considered 0 V.
Ground is abbreviated GND.
The term ground originated with electrical systems where this connection is actually a metal rod that has been driven into the ground. In portable electronic devices, ground is commonly used to refer to connections that go to the battery supply’s negative terminal.
Current refers to the rate at which electrons pass through a circuit.
You will often see measurements of current expressed in amps, which is abbreviated A. The currents you will use here are measured in thousandths of an amp, or milliamps. For example, 10.3 mA passes through the circuit shown above.
Let’s start with a sketch that makes the LED circuit connected to digital pin 13 turn on/off. First, your sketch has to tell the Arduino to set the direction of pin 13 to output, using the pinMode function: pinMode(pin, mode). The pin parameter is the number of a digital I/O pin, and mode must be either INPUT or OUTPUT.
void setup() // Built-in initialization block { pinMode(13, OUTPUT); // Set digital pin 13 -> output }
Now that digital pin 13 is set to output, we can use digitalWrite to turn the LED light on and off. Take a look at the picture below. On the left, digitalWrite(13, HIGH) makes the Arduino’s microcontroller connect digital pin 13 to 5 V, which turns on the LED. On the right, it shows how digitalWrite(13, LOW) makes it connect pin 13 to GND (0 V) to turn the LED off.
Here’s the loop function from the next sketch. First, digitalWrite(13, HIGH) turns the light on, delay(500) keeps it on for a half-second. Then digitalWrite(13, LOW) turns it off, and that’s also followed by delay(500). Since it’s inside the loop function’s block, the statements will repeat automatically. The result? The light will flash on/off once every second.
void loop() // Main loop auto-repeats { digitalWrite(13, HIGH); // Pin 13 = 5 V, LED emits light delay(500); // ..for 0.5 seconds digitalWrite(13, LOW); // Pin 13 = 0 V, LED no light delay(500); // ..for 0.5 seconds }
/* Robotics with the BOE Shield - HighLowLed Turn LED connected to digital pin 13 on/off once every second. */ void setup() // Built-in initialization block { pinMode(13, OUTPUT); // Set digital pin 13 -> output } void loop() // Main loop auto-repeats { digitalWrite(13, HIGH); // Pin 13 = 5 V, LED emits light delay(500); // ..for 0.5 seconds digitalWrite(13, LOW); // Pin 13 = 0 V, LED no light delay(500); // ..for 0.5 seconds }
A timing diagram is a graph that relates a signal's high and low stages to time. This timing diagram shows you a 1000 ms slice of the HIGH (5 V) and LOW (0 V) signals from the sketch HighLowLed. Can you see how delay(500) is controlling the blink rate?
How would you make the LED blink twice as fast? How about reducing the delay function’s ms parameters by half?
Blinking the pin 12 LED is a simple matter of changing the pin parameter in the pinMode and two digitalWrite function calls.
You can also make both LEDs blink at the same time.
pinMode(13, OUTPUT); // Set digital pin 13 -> output pinMode(12, OUTPUT); // Set digital pin 12 -> output
digitalWrite(13, HIGH); // Pin 13 = 5 V, LED emits light digitalWrite(12, HIGH); // Pin 12 = 5 V, LED emits light delay(500); // ..for 0.5 seconds digitalWrite(13, LOW); // Pin 13 = 0 V, LED no light digitalWrite(12, LOW); // Pin 12 = 0 V, LED no light delay(500); // ..for 0.5 seconds
How would you modify the sketch again to turn one LED on while the other turns off? One circuit will need to receive a HIGH signal while the other receives a LOW signal.