Arduino Intro Labs for Tangible Computing
8. Building Circuits




8.1 The Circuit Board



Notice how there is no keyboard, mouse, or screen. The computer is the large square "chip" in the middle of the blue circuit board. At the top is a USB connection to a "normal" computer that is used to program the Arduino, and to give it power. Around the edge of the blue circuit board are black connectors that you plug wires into. These are called interface pins.

The Arduino has 3 kinds of pins on the board. The power pins (top left) are used to provide power to the devices that are connected to the Arduino.

The most common pins are the digital I/O pins, numbered 0 to 53 on the Arduino Mega and 0 to 13 on the Arduino Uno. These pins are used to send binary data (0 and 1) between the Arduino and the outside world. These pins can be configured as input mode (that is, to read from the outside world), or as output mode (that is, to write to the outside world).

Digital pin 13 also has a small green LED on the board attached to it. It is labelled L on the circuit board, and is adjacent to digital pin 13. There are special digital pins that you should avoid until later: pins 0, 1, 14 to 19 are used for serial communication.

The other form of pin is the analog input. These are labelled A0 to A15, and appear on the left side of the circuit board of the Arduino Mega and pins A0 to A5 on the Arduino Uno. We will get to these later.

Finally, you should note that in the lower middle is the reset button which is used to reset the board if it gets stuck, or if you want to restart your program that is running on the Arduino.

8.2 The Breadboard

The white block with holes in it is called a breadboard. It is used to build small circuits that connect to the Arduino interface pins. The board is divided into 4 regions, left to right.

The two outermost regions have a red and blue vertical line. These are called power buses. All of the pins in the red column are connected together, as are all of the pins in the blue column. Normally, the red column is the positive (+) power bus and the blue column is the negative (-) or ground bus. The Arduino can be used as a power source. If you look carefully at the wires, there is a red wire running from the Arduino pin labelled 5V to the left hand positive power bus, and a black wire running form the Arduino pin labelled GND to the left hand ground bus.

The two innermost regions are divided by a vertical groove. There are 30 horizontal rows of 5 pins running along both sides of the groove. Each of the 5 pins in a horizontal row are connected together. These rows are used to make connections for the components of your circuit. The grove down the middle lets you plug in more complex components, many of which are integrated circuits.

8.3 Safety

These rules apply in general for any wiring.

So before you start:
  1. REMOVE THE POWER WHEN WIRING STUFF UP! Just unplug the USB cord.
  2. Do NOT connect the 5V to the Ground! This will short circuit the Arduino!
  3. Some components do not have reverse polarity so check that component before you apply the power (or else you may destroy the hardware).


8.4 Basic Wiring Example

The Arduino can be used as a power source. If you look carefully at the image below, there is a red wire running from the Arduino pin labelled 5V to the left hand positive power bus, and a black wire running form the Arduino pin labelled GND to the left hand ground bus.

Principle: In a circuit, electric current flows from higher potential locations to lower potential locations. Potential is measured in Volts (symbol V), relative to some ground point. This is similar to how we measure altitude. Altitude is your height in meters relative to the ground. But what we choose as ground depends on our needs. Airplane and mountain altitudes are measured relative to sea level. Parachutists measure altitude relative to the ground they are going to hit. The positive bus in our circuits is at +5 V compared to the ground at 0 V. In some circuits there are potentials below ground, in which case they will have negative voltages.
Remember your circuit safety!



How to wire up the Power Buses:

Start by connecting the 5 V (five volt positive) and 0 V GND (ground) pins to the breadboard. Until you know more, Do no connect anything up to the other pins (such as the 3.3 V and Vin).

Modern breadboards are easy to use. There are specially designed patch wires which are flexible but have rigid pins on the end to make them easy to plug into the board. If the breadboard is fairly new the wires will not go in easliy. Go ahead and use some force to get the wires into the breadboard. If that isn't working you can try a pin above or below it. As long as the 5 V connects to a pin in the positive (red) bus on the breadboard and the ground connects to the negative (blue) bus on the breadboard, then it's fine.

Here is a short video of the construction of the circuit for the first part of the SOS lab. It will give you an idea of how to construct circuits even if you do not need to wire everything the video does.

Watch the video: Lab01Wiring01.mov

8.5 Types of Circuit Diagrams

We can use photos to give a sense of how the circuit might appear, but there are other methods of displaying more complicated diagrams. Fritizing diagrams made with a Fritzing program make much easier to see how the circuit is wired. There are also the circuit Diagrams that use Circuit symbols, which are standards for representing hardware in many places.

Here is an example of each of the diagrams from the finished circuit of the SOS lab.

Photograph Fritzing Circuit
Click the image for full size!


8.6 LED

Light Emitting Diode: The LED is the common replacement for the incandescent light bulb. (See LED). LEDs comes in various colors.
The intensity of a LED is controlled by turning it off and on very rapidly. Your eye cannot see the flashes, but it can detect the proportion of on and off time. The more on the LED is, the brighter it appears to you. This on-off timing relationship is called a duty cycle. Duty cycle describes the proportion of one unit of time during which the device is on.
So a 100% duty cycle means always on, 50% means on half the time, and 0% means off. You can operate a digital output in Pulse-Width Modulation (PWM) mode by using the analogOutput function. You give the function a digital pin number and a duty cycle value (from 0 to 255) where 0 is 0% and 255 is 100%.



The basic circuit for an LED consists of a resistor and a LED. There are two very important things to remember about LEDs.

8.7 Resistor

The resistor has a color code on it that specifies the value of the resistor.(See resistor color code). Ω is the sign for Ohms, which is a measure of resistance. The purpose of a resistor is to limit the amount of current that can flow in a part of a circuit.
Principle: The amount of current flowing in a circuit is measured in Amps (symbol A). Current, voltage, and resistance are related by the relationship
E = I R
where E is the potential difference measured in Volts, I is the current measured in Amps, and R is the resistance measured in Ohms.

Reality Check: In an LED circuit, the voltage E is 5V, the resistance R is 560 Ω, and so the current I is 5 / 560 = 0.009 A. Or, since we typically have small currents in our circuits, the current is 9 mA (milli Amps).


When Wiring: It does not matter which way you plug in the resisitor.

What requires a resistor?
  1. A LED use 560Ω resistor (Green-Blue-Brown).
  2. A photoresistor use the 10kΩ resisitor (Brown-Black-Orange).
  3. A RGB LED uses threee 560Ω resistors (Green-Blue-Brown), one for each coloured LED contained inside.


8.8 Potentiometer

A potentiometer is a special kind of resistor. It has three pins. The outer pins are connected to the ends of the resistor. The middle pin is connected to a slider that moves between the ends of the resistor. If the outer pins are connected between +5 V and 0 V (GND), then the voltage on the middle pin will vary between 5 and 0 V, depending on whether it is closer to the 5V end or closer to the 0 end.


If we connect the middle pin of the potentiometer to an analog input pin on the Arduino, then we can read the voltage on the pin as an integer value that varies from 0 (at 0 V) to 1023 (at 5 V).

There are only 10 bits of precision in an Arduino analog input. This is why the maximum value you can read is 1023 = 2 ** 10 - 1.



When Wiring: It does not matter which way you plug it in. As long as the middle pin leads to an analog pin, it does not matter which outside pin leads to the ground or positive bus.

8.9 Pushbutton

The pushbutton is a simple switch. When it is not pushed, the circuit between the pins is open (not conducting). When pushed, the circuit between the pins is closed (conducting). The digital input pins on the Arduino convert a voltage on the pin into a HIGH or LOW signal. A voltage near 5 V is considered a HIGH input, and a voltage near 0 V is considered a LOW input. A value in the middle is ambiguous.
Concept: If a digital input pin is not connected to anything, it is said to be floating. Reading from a floating pin is very unreliable. It might be HIGH, but can be LOW. So to ensure that a proper voltage is always present on a digital input, a pullup circuit is used. The resistor attached to the pin is called a pull up resistor. It's job is to ensure that the digital input pin has 5V present when the switch is open. Then when the switch is closed it pulls down the voltage to 0V. You can install the pull up resistor yourself. But this is such a common issue that the Arduino processor has built in pull up resistors that can be turned on.




Wiring tips
  1. The switch should have the pins coming out of the left and right sides, not the top and bottom when properly placed on the breadboard.
  2. A way to test this is to place the pushbutton on the breadboard just as shown in the wiring diagrams. Only when the pushbutton is placed correctly will it span over the gap easily between the division of the two halves of the breadboard.
  3. It does not matter which pushbutton pin goes to ground and which one goes to positive.


8.10 Piezo Speaker

A loudspeaker (or just speaker) is a device that converts an electrical signal into a pressure wave. This is usually done by moving a diaphram (or speaker cone) back and forth a distance that is proportional to the applied voltage. The diaphram can be moved via an electromagnet, or via a piezoelectric crystal.
The Arduino does not have built in analog outputs. So if you connect a digital output to a speaker, you do not get very smooth excursions. Instead you get a (roughly) square wave. But we still perceive these square waves as tones.




Wiring Tips
  1. It does not matter which way it is placed.
  2. It also does not matter which pin goes to ground and which goes to positive.


8.11 Photoresistor

The Arduino does not have a camera, but it does have a simple light sensor called a photoresistor. It is a device whose resistance varies with the intensity of the light falling on it. As the light gets stronger the resistance decreases. Thus you can measure the amount of light falling on the photoresistor. If you arrange the photoresistor in a voltage divider circuit, then you can measure a voltage that is proportional to the resistance of the photoresistor, and thus is proportional to the intensity of the light.
When the illumination on a surface is of a particular color, then the photoresistor can be used to sense how well that color is reflected or absorbed by the surface. By measuring the amount of red, green, and blue coming from the surface we can detect the color of the surface. It looks like this


Wiring Tips
  1. It does not matter which way it is placed.
  2. It also does not matter which pin goes to ground and which goes to positive.
  3. Requires 10kΩ resisitor! (Brown-Black-Orange)


8.12 RGBLED

We can create almost any color by mixing red, green, and blue light. A RGB LED has three LEDs inside one package. By varying the intensity of each LED you can mix these primary colors and generate a wide range of color hue (the actual mix of colors) and saturation (the amount of white mixed in with the color).



Wiring Tips
  1. Order Matters! For reference, if we say the longest lead is the second one, that one must go to ground. Then the first lead controls the red LED, the third controls the green LED and the fourth one controls the blue LED.
  2. The three LED wires also require a 560Ω (green-blue-brown) resistor.

8. Building Circuits
Arduino Intro Labs for Tangible Computing / Version 1.00 2012-09-24