Lab: Using a Transistor to Control High Current Loads with an Arduino

In this tutorial, you’ll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller.

Introduction

In this tutorial, you’ll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller. Microcontrollers can only output a very small amount of current from their output pins. These pins are meant to send control signals, not to act as power supplies. The most common way to control another direct current device from a microcontroller is to use a transistor. Transistors allow you to control the flow of a high-current circuit from a low-current source.

What You’ll Need to Know

To get the most out of this Lab you should be familiar with the following concepts beforehand. If you’re not, review the links below:

Things You’ll Need

Prepare the breadboard

Connect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V or 3.3V (depending on your model) and any of the ground connections, as shown in Figures 11 and 12.

An Arduino Uno on the left connected to a solderless breadboard, right.
Figure 11. Breadboard drawing of an Arduino Uno on the left connected to a solderless breadboard on the right

Figure 11 shows an Arduino Uno on the left connected to a solderless breadboard, right. The Uno’s 5V output hole is connected to the red column of holes on the far left side of the breadboard. The Uno’s ground hole is connected to the blue column on the left of the board. The red and blue columns on the left of the breadboard are connected to the red and blue columns on the right side of the breadboard with red and black wires, respectively. These columns on the side of a breadboard are commonly called the buses. The red line is the voltage bus, and the black or blue line is the ground bus.


Arduino Nano on a breadboard.
Figure 12. Breadboard view of an Arduino Nano mounted on a solderless breadboard.

As shown in Figure 12, the Nano is mounted at the top of the breadboard, straddling the center divide, with its USB connector facing up. The top pins of the Nano are in row 1 of the breadboard.

The Nano, like all Dual-Inline Package (DIP) modules, has its physical pins numbered in a U shape, from top left to bottom left, to bottom right to top right. The Nano’s 3.3V pin (physical pin 2) is connected to the left side red column of the breadboard. The Nano’s GND pin (physical pin 14) is connected to the left side black column. These columns on the side of a breadboard are commonly called the buses. The red line is the voltage bus, and the black or blue line is the ground bus. The blue columns (ground buses) are connected together at the bottom of the breadboard with a black wire. The red columns (voltage buses) are connected together at the bottom of the breadboard with a red wire.


Images made with Fritzing

Add a potentiometer

Connect a potentiometer to analog in pin 0 of the module as shown in Figure 13 through Figure 15:

Schematic view of a potentiometer. First leg of the potentiometer is connected to +5 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground.
Figure 13. Schematic view of a potentiometer connected to analog in 0 of the Arduino
Breadboard view of a potentiometer. First leg of the potentiometer is connected to +5 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground.
Figure 14. Breadboard view of a potentiometer connected to analog in 0 of an Arduino Uno. The potentiometer is mounted in three rows of the left center section of the breadboard. The two outside pins of the potentiometer are connected to the voltage and ground bus rows, respectively. The center pin is connected to analog in 0 of the Uno.

Breadboard view of a potentiometer connected to analog in 0 of an Arduino Nano.
Figure 15. Breadboard view of a potentiometer connected to analog in 0 of an Arduino Nano. The potentiometer is mounted in three rows of the left center section of the breadboard below the Nano. The two outside pins of the potentiometer are connected to the voltage and ground bus rows, respectively. The center pin is connected to analog in 0 (physical pin 4) of the Nano.

Connect a Transistor to the Microcontroller

The transistor allows you to control a circuit that’s carrying higher current and voltage from the microcontroller. It acts as an electronic switch. You can use a bipolar Darlington transistor like the TIP120, or you can use a MOSFET like the IRF520 or FQP30N06L for this lab. All three will work the same way and use the same circuit. See Figures 16 through Figure 19 for the drawings and schematic symbols of the transistors.

Pinout drawing of a TIP-120 transistor. It is facing forward with the heat sink tab at the top and the bulging side of the component facing you. From left to right the legs are labelled 1. base, 2. collector, 3. emitter.
Figure 16. Pinout drawing of a TIP-120 transistor. From left to right the legs are labelled 1. base, 2. collector, 3. emitter.
The schematic symbol of an NPN transistor where B is the base, C is the collector, and E is the emitter.
Figure 17. The schematic symbol of an NPN transistor. B is the base, C is the collector, and E is the emitter.
NPN Transistor and N-Channel MOSFET side by side. The physical packages of the transistor and MOSFET are nearly identical. The pin out of the N-channel MOSFET is comparable to the transistor, where G of the MOSFET is the gate (equivalent of base of the transistor), D is the drain (equivalent of the collector) and S is the source (equivalent of the emitter).
Figure 18. NPN Transistor and N-Channel MOSFET side by side with a schematic diagram of the MOSFET. G is the gate (equivalent of base), D is the drain (collector) and S is the source (emitter).
Another version of the schematic symbol of an N-channel MOSFET, where G is the gate (equivalent of base), D is the drain (collector) and S is the source (emitter).
Figure 19. Schematic symbol of an N-channel MOSFET, where G is the gate (equivalent of base), D is the drain (collector) and S is the source (emitter).

The IRF520 MOSFET has the same pin configuration as the TIP120, and performs similarly with a 5V gate voltage. The FQP30N06L MOSFET has the same pin configuration, and operates on as low as 1.0V, and works well for 3.3V applications. MOSFETs can generally handle more amperage and voltage, and switch a little faster (the difference is in microseconds, so you won’t notice), but they are more sensitive to static electricity damage. They are grouped into N-Channel and P-Channel, which are equivalent to NPN and PNP bipolar transistors.

All three transistors mentioned here are designed for switching high-current loads. All of them have built-in protection diodes. Each has three connections Table 1 below details their connections.

Bipolar TransistorMOSFETConnection
BaseGateConnects to microcontroller output
CollectorDrainConnects to power through load
EmitterSourceConnects to ground
Table 1. Names of the pins on the bipolar transistor and the equivalent names on the MOSFETs

The datasheets for each of the recommended transistors can be found below:

Here’s the main operating principle of using a transistor as a switch: When a small voltage and current is applied between the base (or gate) and the emitter (or source), the transistor allows a larger current to flow between the collector (or drain) and emitter (or source).

Figures 20 through 22 show how to connect the transistor.

Schematic view of a potentiometer and transistor connected to an Arduino.
Figure 20. Schematic view of a potentiometer and transistor connected to an Arduino. First leg of the potentiometer is connected to +5 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground. The base (or gate) of the transistor is connected to digital pin 9 of the Arduino through a 1-kilohm resistor. The emitter (or source) is connected to ground.
Breadboard view of a potentiometer and transistor connected to an Arduino.
Figure 21. Breadboard view of a potentiometer and transistor connected to an Arduino. First leg of the potentiometer is connected to +5 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground. The base (or gate) of the transistor is connected to digital pin 9 of the Arduino through a 1-kilohm resistor. The emitter (or drain) is connected to ground.

Breadboard view of a potentiometer and transistor connected to an Arduino Nano.
Figure 22. Breadboard view of a potentiometer and transistor connected to an Arduino Nano. First leg of the potentiometer is connected to +3.3 volts. The second leg connected to analog in 0 of the Arduino. The third leg is connected to ground. The base (or gate) of the transistor is connected to digital pin 9 of the Arduino through a 1-kilohm resistor. The emitter (or drain) is connected to ground.

Connect a Motor and Power Supply

Attach a DC motor to the collector (or drain) of the transistor as shown in Figures 23 through 25. Most motors will require more current than the microcontroller can supply, so you will need to add a separate power supply as well. If your motor runs on around 9V, you could use a 9V battery. A 5V motor might run on 4 AA batteries (6V). You could also use a 12-volt DC wall adapter and a 5-volt regulator. A 12V battery may need a 12V DC wall adapter, or a 12V battery. The ground of the motor power supply should connect to the ground of the microcontroller on the breadboard.

Add a 1N400x power diode in parallel with the collector and emitter of the transistor, pointing away from ground. The diode protects the transistor from back voltage generated when the motor shuts off, or if the motor is turned in the reverse direction. Used this way, the diode is called a protection diode or a snubber diode. You can omit the diode if you don’t have one, as the transistors recommended here all have a built-in protection diode

Schematic view of a potentiometer connected to analog in 0 of the Arduino.
Figure 23. Schematic view of a potentiometer connected to analog in 0 of the Arduino. A transistor is connected to Digital Pin 9. A DC motor connects to the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the DC motor. The negative wire of the DC jack connects to ground. The second wire of the DC motor connects to the collector (or drain) of the transistor. A 1N400x diode’s anode is connected to the collector (or drain), and its anode is connected to ground.
Breadboard view of an Arduino connected to a potentiometer, a transistor, a DC motor, and a DC jack.
Figure 24. Breadboard view of an Arduino connected to a potentiometer, a transistor, a DC motor, and a DC jack. A transistor is connected to Digital Pin 9. A DC motor connects to the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the DC motor. The negative wire of the DC jack connects to ground. The second wire of the DC motor connects to the collector (or drain) of the transistor. A 1N400x diode’s anode is connected to the collector (or drain), and its anode is connected to ground.
Breadboard view of an Arduino Nano connected to a potentiometer, a transistor, a DC motor, and a DC jack.
Figure 25. Breadboard view of an Arduino Nano connected to a potentiometer, a transistor, a DC motor, and a DC jack. A transistor is connected to Digital Pin 9 through a 1-kilohm resistor. A DC motor connects to the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the DC motor. The negative wire of the DC jack connects to ground. The second wire of the DC motor connects to the collector (or drain) of the transistor. A 1N400x diode’s anode is connected to the collector (or drain), and its anode is connected to ground.

Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so in Figure 26:

Schematic representation and physical representation of a diode. The schematic form shows an equilateral triangle with a line bisecting the triangle equally from one point to and through the middle of the opposing flat side. There is also a line perpendicular to the other line that also intersects the triangle at its bisected point. The cathode is represented by the side of the schematic with the line. The drawing of the physical form of the diode looks like a black resistor with only a single grey stripe on one side. The side with the stripe represents the cathode
Figure 26. Schematic representation and physical representation of a diode. The silver band on the diode indicates the anode end.

Connect a Lamp Instead of a Motor

You could also attach a lamp using a transistor. There are many 12V incandescent lamps, designed for use in track lighting, gallery lighting, and so forth. Nowadays, there are many 12V DC LED equivalents of the 12V AC lamps as well.  Here are a few examples:

The lamp circuit in Figures 27 through 29 assumes a 12V lamp. MOSFETs are generally best for switching incandescent and LED lamps, so the circuit below uses a MOSFET. In the lamp circuit, the protection diode is not needed, since there’s no way for the polarity to get reversed in this circuit.

Schematic view of a potentiometer, MOSFET, and lamp connected to an Arduino.
Figure 27. Schematic view of a potentiometer, MOSFET, and lamp connected to an Arduino. The gate of a MOSFET transistor is connected to Digital Pin 9 of the Arduino. A 12V lamp connects to the drain of the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the lamp. The negative wire of the DC jack connects to ground. The second wire of the lamp connects to the drain of the transistor. The source of the transistor connects to ground.
Breadboard view of a potentiometer, MOSFET, and lamp connected to an Arduino.
Figure 28. Breadboard view of a potentiometer, MOSFET, and lamp connected to an Arduino. The gate of a MOSFET transistor is connected to Digital Pin 9 of the Arduino. A 12V lamp connects to the drain of the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the lamp. The negative wire of the DC jack connects to ground. The second wire of the lamp connects to the drain of the transistor. The source of the transistor connects to ground.

Breadboard view of a potentiometer, MOSFET, and lamp connected to an Nano.
Figure 29. Breadboard view of a potentiometer, MOSFET, and lamp connected to an Nano. The gate of a MOSFET transistor is connected to Digital Pin 9 of the Nano. A 12V lamp connects to the drain of the transistor and a DC jack. The DC jack connects its positive wire to the first wire of the lamp. The negative wire of the DC jack connects to ground. The second wire of the lamp connects to the drain of the transistor. The source of the transistor connects to ground.

Program the microcontroller

Write a program to test the circuit, whether it’s a motor or a lamp. Your program should make the transistor pin an output in the setup method. Then in the loop, it should turn the motor on and off every second, just like the blink sketch does.

1
2
3
4
5
6
7
8
9
10
11
12
13
const int transistorPin = 9;    // connected to the base of the transistor
 
 void setup() {
   // set  the transistor pin as output:
   pinMode(transistorPin, OUTPUT);
 }
 
 void loop() {
   digitalWrite(transistorPin, HIGH);
   delay(1000);
   digitalWrite(transistorPin, LOW);
   delay(1000);
 }

Now that you see it working, try changing the speed of the motor or the intensity of the lamp using the potentiometer.

To do that, read the voltage of the potentiometer using analogRead(). Then map the result to a range from 0 to 255 and save it in a new variable. Use that variable to set the speed of the motor or the brightness of the lamp using analogWrite().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const int transistorPin = 9;    // connected to the base of the transistor
 
 void setup() {
   // set  the transistor pin as output:
   pinMode(transistorPin, OUTPUT);
 }
 
 void loop() {
   // read the potentiometer:
   int sensorValue = analogRead(A0);
   // map the sensor value to a range from 0 - 255:
   int outputValue = map(sensorValue, 0, 1023, 0, 255);
   // use that to control the transistor:
   analogWrite(transistorPin, outputValue);
 }

For the motor users: A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the DC Motor Control lab.

Come Up with an Application

Now that you’ve got motor or lamp control, come up with an application.

If you used a motor in this lab, consider any toys you have that have a motor you could take control over. Charley Chimp™ has a motor that’s easy to control from an Arduino, for example.

Photo of a toy monkey. The back has been removed to reveal the inner gear mechanism that plays the cymbals. At the center of a mechanism is a DC motor. Wires have been attached to it to run the motor from an H-bridge.
The guts of a Charley Chimp™ cymbal-playing monkey.

You could also consider simple movements in the work of artists like Jennifer Townley, Johannes Langenkamp (instagram), Nick Yulman, or Lu Lyu.

You’ve got the beginnings of a good desk lamp or table lamp, if you chose to use a light bulb in this lab. How will you control it? How will you mount the switchor the dimmer knob? You might also want to consider a gooseneck pipe to mount your socket on, and a socket that goes with it. Here are a few inspirations:

Electricity: the Basics

Introduction

Adapted from Understanding Electricity
In order to understand how electronic circuits work, and how to use them to build physical interfaces to digital systems using microcontrollers, there are some basic terms, relationships, and components that you need to know about. What follows is a brief introduction to those terms.

You won’t need to know anything about electricity or electronics to understand this page.

Definitions

Electricity is the flow of electrical energy through conductive materials.  An electrical circuit is made up of two elements: a power source and components that convert the electrical energy into other forms of energy.  We build electrical circuits to do work, or to sense activity in the physical world.

Sensors are components that convert other forms of energy into electrical energy so we can read the changes in those other forms. Switches, knobs, light and motion sensors all fit in this category.  Actuators are components that convert electrical energy into other forms. Light bulbs, motors, LEDs, and heaters are all actuators.

Electronics refers to reading changes in electrical properties as information.  For example, a microphone changes sound pressure waves in the air to a changing electrical voltage. This process of changing one energy into another is called transduction, and devices that do it are called transducers. Much of the technical work of physical computing is about figuring out what forms of energy a person is generating, and what kind of transducer you can buy or build to read that energy. In order to do that, though, it’s necessary to understand a few things about electricity. Following are a few terms we’ll use to refer to electrical properties and components. After that, we’ll talk about the important relationships between some of these terms.

Voltage is a measure of the difference in electrical potential energy between two points in a circuit. It is measured in Volts.

Current is a measure of the magnitude of the flow of electrons through a particular point in a circuit. It is measured in Amperes, or Amps.

Resistance is a measure of a material’s ability to oppose the flow of electricity. It is measured in Ohms.

To understand the relationship between voltage, current, and resistance, imagine an avalanche of snow on a mountain. The height of the mountain is analogous to the voltage; the higher the mountain, the more potential energy the falling material has.  The amount of snow and rocks in the avalanche is analogous to the current.  And the steepness of the mountain is analogous to the resistance: the steeper the mountain, the less it will resist the flow of the snow and rocks. We’ll define this a bit more formally below.

Every circuit has to have a source of electrical energy and a load that uses the energy.All of the electrical energy in a circuit has to get used by the load. The load will convert the electrical energy to some other form of energy, A circuit with no load  is called a short circuit. In a short circuit, the power source feeds all of its power through the wires and back to itself, and either the wires melt (if you’re lucky), or the battery and the components blow up.

Figure 1 is a very basic circuit, consisting of a lamp, a pushbutton, and a battery. The battery is the source and the lamp is the load. The electrical energy coming from the battery is converted to heat and light energy by the light bulb. All of the energy is used up in the process. However, if the bulb cannot take the voltage produced by the battery (for example, a 6V lamp and a 9V battery), the lamp’s filament will melt trying to transduce all the electrical energy into light and heat.

One AA Battery connected to a button switch and lamp in series
Figure 1. AA Battery connected to a button switch and lamp in series

There are two common kinds of circuits:  Direct Current (DC), and Alternating Current (AC). In a DC circuit, current always flows one direction. In an AC circuit, the direction of current flow is reversed in a regular repeating cycle.  Most of the circuits we’ll talk about in this class will be DC circuits.

Schematic diagrams are diagrams of circuits that represent the electrical relationships between the components in the circuit. A schematic doesn’t  always show the spatial arrangement of the components; it’s arranged so that you can best understand the flow of the electricity. You can find a large collections of schematic symbols in SVG format, useful for drawing your own, on the Wikipedia page for “Electronic Symbol”. An SVG collection of them in one file, convenient for editing into your own diagrams, can be found on this Wikimedia commons page. The symbols for the components you’ll use most commonly in this class are shown below as well.

Figure 2 show two schematics of the light bulb circuit above. In both, the important parts to note are the functional components, namely the lamp and the switch, and the power and ground terminals. In the diagram on the right, the whole circuit is shown as a loop, with the battery (marked V1) to the left of the loop. In the diagram on the left, the circuit is not shown as a loop. Instead, the power source is at the top, and the point of lowest energy, or ground, is at the bottom.  This diagram shows the flow of energy from the top of the diagram to the bottom. Related Video: Intro to Schematics

Schematic of a 1.5 volt battery connected to a switch and lamp in series. In the diagram on the right, the whole circuit is shown as a loop, with the battery (marked V1) to the left of the loop. In the diagram on the left, the circuit is not shown as a loop. Instead, the power source is at the top, and the point of lowest energy, or ground, is at the bottom.
Figure 2. Two schematics of a 1.5 volt battery connected to a switch and lamp in series.

Components

Conductors are materials through which electrical current moves freely.

Insulators are materials which prevent the flow of electricity.

Resistors resist, but do not totally block, the flow of electricity. They are used to control the flow of current. Current can move either way through a resistor, so it doesn’t matter which way they’re connected in a circuit. Resistors are measured by their resistance in ohms (Ω), often seen in kilohms (kΩ). They are symbolized as shown in Figure 3:

Four resistor types, from left to right: Fixed Value Resistor, Variable Resistor, Potentiometer, Photo-resistor or light dependent resistor
Figure 3. Four resistor types, from left to right: Fixed Value Resistor, Variable Resistor, Potentiometer, Photo-resistor or light dependent resistor.

Related videos: Resistors, variable resistors, and photocells; Potentiometer

There are many different types of variable resistors, including:

  • Thermistors change resistance in reaction to varying temperature;
  • Photoresistors change resistance in reaction to varying light;
  • Flex sensors change resistance in reaction to being bent or flexed;
  • Force sensing resistors change resistance in reaction to a force placed upon them;

Capacitors store up electricity while current is flowing into them, then release the energy when the incoming current is removed. Capacitors are measured by their capacitance in farads (F), most commonly seen in microfarads (µF). Sometimes they are polarized, meaning current can only flow through them in a specific direction, and sometimes they are not. If a capacitor is polarized, it will be marked as such on the diagram. Don’t wire a polarized capacitor backwards; this can damage the capacitor, and your circuit. Capacitors are also rated by their maximum voltage. Don’t apply more voltage to a capacitor than it’s rated for, or it will explode.

Capacitors are symbolized as shown in Figure 4:

Schematic symbols of a polarized capacitor and a non-polarized capacitor. Polarized shows a + symbol near the anode and the cathode is connected to a curved line. The non polarized capacitor symbol contains only straight lines and is symmetric
Figure 4. Schematic symbols of a polarized capacitor and a non-polarized capacitor

Related video: Capacitors

Diodes permit the flow of electricity in one direction, and block it in the other direction. Because of this, they can only be placed in a circuit in one direction. Light-Emitting Diodes (LED’s) are special types of diodes which emit light when current flows through them.  Diodes are symbolized as shown in Figure 5:

Schematic symbols of a diode and a light-emitting diode. The light-emitting diode looks like the diode symbol with 2 arrows pointing away from the center of the symbol.
Figure 5. Schematic symbols of a diode and a light-emitting diode (LED)

Related video: Diodes and LEDs

Switches and pushbuttons control the flow of current through a junction in a circuit, as shown in Figure 6:

Drawing of a switch, left, and a pushbutton, right. The switch has two lines separated by a gap, with a hinged third line almost connecting them, indicating that it is the switch between the two contacts. The pushbutton has two lines separated by a gap and a third line parallel to them, indicating that, it would close the connection between the first two lines when pressed against them.
Figure 6. Schematic drawing of a switch and a pushbutton

Related video: Switches

Transistors and relays are electrical switching devices, as shown in Figure 7:

Schematic symbols for an NPN transistor, a PNP Transistor, and a Relay
Figure 7. Schematic symbols for an NPN transistor, a PNP Transistor, and a Relay

Related video: Relays

Piezoelectric devices create a varying voltage in reaction to slight changes in pressure.

Relationships

Voltage (V), Current (I), and Resistance (R) are all related, by the following formula, as shown in figure 8:

Volts = Amps x Ohms

or

V = I x R

Three equations using ohms law to calculate Voltage, Amperage, or Resistance. A circle is divided into 3 sections, each section containing one element of Ohms law, V for voltage, I for Amperage, R for resistance. Each equation is adjacent to the corresponding section of the circle
Figure 8. Three equations using ohms law to calculate Voltage, Amperage, or Resistance

Related video: Ohm’s Law Part 1 & Part 2. See also Measuring Voltage and Current.

Current (I), voltage (V), and resistance (R) are also related to electrical power (P) (measured in watts), as follows:

Watts = Volts * Amps

or

P = V * I

Electrical current flows from places of higher potential energy to places of lower potential energy (i.e. from positive to negative), as shown in Figure 9. In order for current to flow, there has to be a circuit, and there has to be a load to convert the electrical energy into some other form of energy.

Simple circuit showing the direction of current flowing from the + V terminal to ground
Figure 9. Simple circuit showing the direction of current flowing from the + V terminal to ground

Ground is the place in a circuit with where the potential energy of the electrons is zero. Sometimes this point is connected to the actual ground, either through a grounded electrical circuit, water pipe, or some other method. Basically, any conductor that goes to the earth will do.

Electrical Energy Flow in a Circuit

When you start to add multiple components to a circuit, following the electrical energy can get a bit more complex.  Following are some principles that explain how energy flows in a circuit.

Electrical components can be arranged in a circuit so that the energy flows through one to the other, or they can be arranged so that the energy is split, flowing through both at the same time. When the energy flows from one to the other, the components are in series (Figure 10). When it flows through them at the same time, they are in parallel (Figure 11).

Two lightbulbs in series
Figure 10. Two lightbulbs in series
Two lightbulbs wired in parallel
Figure 11. Two lightbulbs wired in parallel

There are a few rules that explain how electrical energy moves through these circuits:

Current tends to follow the path of least resistance to the ground. So if it has a choice of two paths in a circuit, and one has less resistance, that’s the path it’ll take. Looking at the parallel circuit above, if one light bulb offered less resistance, then more of the current wold pass through that bulb.

In any given circuit, the total voltage around the path of the circuit is zero. Each component that offers a resistance lowers the voltage, and by the time you reach the end of the circuit loop, there will be no voltage left. In other words, all energy generated by the electrical power source in a circuit is converted to some other form of energy.  Looking at the light bulbs in series above, if you were to measure the voltage on between the two contacts of each bulb, it would be less than the voltage between the contacts of the battery, but when you add up the voltages for all the bulbs, the sum would equal the voltage of the battery.

This explains why some components in a circuit get warm when you don’t expect them to. They are offering resistance to the energy in the circuit, and if they are not efficient at converting that energy into their desired form of energy, they convert it to heat.

The amount of current going into any point in a circuit is the same as the amount coming out of that point.

Let’s look in more detail at how the current and voltage changes when components are in series or in parallel:

When two components are in series, they are placed one after another, as shown in Figure 12:

Two resistors wired in series with a junction in between the resistors
Figure 12. Two resistors wired in series.

When resistors are in series, the voltage drops across each resistor, and the total resistance is equal to the sum of all the resistors:

Resistors in series:

Rtotal = R1 + R2 + R3

In the above circuit, the current through both of the resistors is the same and the voltage drops across each resistor, and the total of all the voltage drops equals the voltage across the battery. The voltage between the junction point and the negative terminal of the battery (which is the ground of this circuit)  is dependent on the ratio of the two resistors in series. If the resistors are equal in resistance value, then the voltage at the junction point is exactly half that of the battery’s total voltage.

When two components are in parallel, they are placed beside each other, as shown in Figure 13:

Two resistors wired in parallel
Figure 13. Two resistors wired in parallel

For resistors in parallel, the voltage across them is equal, but the current is divided between them. The divided current across the parallel resistors is equal to the total current. So I1 + I2 = Itotal. That means that

1/Rtotal = 1/R1 + 1/R2 + 1/R3

If the resistors are equal in resistance value, then the current flowing through each of them is half that of the total current.

Though it’s sometimes useful to think about the mathematical relationships of parallel and series circuits, it’s often more useful to think about them in terms of practical effects: resistors divide voltage when in series, and divide amperage when in parallel.

When you’re ready to begin building circuits, read the Breadboard Setup Lab for a quick introduction to how to use a solderless breadboard. The Components Lab introduces many of the components you will use and the Electronics lab introduces you to how to measure electrical properties. You should also read the the switches lab, and watch this video about connections in schematics.

Lab: Soldering

In this tutorial you’ll learn the basics of soldering for electronics.

In this tutorial you’ll learn the basics of soldering for electronics.

Introduction

If you’re going to do any electronics work, you’re going to have to do some soldering, or have someone help you do it. Many people fear it before they’ve done it, but it’s really pretty simple to do. This exercise will show you how to solder a DC Power connector to a set of wires for a breadboard.

In order to get the most out of this tutorial, you should have a basic understanding of electrical circuits, so you understand why you’re soldering, and you should know what a solderless breadboard is.

You might also find this video on soldering by Andy Sigler and this video on desoldering helpful.

Soldering is a process in which you use a metal alloy with a low melting point to fuse together two other pieces of metal. It’s used in electronics all the time, because it ensures a mechanically solid connection between two materials that’s also electrically conductive. To do this, you heat the alloy, called solder, until it melts, and let it run across the two metal pieces you’re attempting to join.

There are many different ways to solder, but the most common for hobbyists uses a handheld soldering iron and a reel of solder wire. That’s the process that’s demonstrated here.

Things You’ll Need

Photo of a solderable DC power jack. It is shown disassembled, with the metal insides separate from the plastic insulator sleeve
Figure 1. Solderable DV power Jack. You can find this particular model on Jameco.com
Photo of breakaway header pins. There are 20 pins in one row. The pins are all 0.5 inch (1.3cm) long, and separated by 0.1 inch (2.5mm) plastic spacers. The plastic is scored so that the pins can be broken off one at a time.
Figure 2. Breakaway header pins
Photo of helping hands tool. The tool has a metal base witha swivel joint at the top. The swivel joint holds a metal bar approximately 6 inches (15cm) long. Each end of the bar has another swivel joint with a metal clip mounted on it.
Figure 3. Helping hands tool
Photo of a soldering iron. The base of the iron is approximately 5 inches (13cm) on a side. The left side is reaised and has a power switch and a temperature knob on the front. The right side has a metal coil, and the iron itself is inserted in the coil. The iron is approximately 8 inches (20cm) long, metal with a plastic handle. The handle has a thick wire coming out of the back that attaches to the base below the temperature knob.
Figure 4. Soldering iron
Photo of a roll of solder wire. The wire is thin, approximately 0.05 inches (1mm) in diameter. It is quite soft, and breaks easily.
Figure 5. A roll of solder wire
Photo of two pieces of 22AWG hookup wire. The wire is approximately 0.05 inches (1mm) in diameter, and clad in a plastic insulation. These two wires have red and black insulation, respectively.
Figure 6. 22AWG hookup wire
Photo of a hot glue gun.
Figure 7. Hot glue gun
Wire strippers. The jaws of this wire stripper have multiple hole sizes so that it can strip wires of variable sizes.
Figure 8. Wire stripper tool

In the steps that follow, you’ll connect jumper wires to a power connector. When you’re prototyping a circuit, you need all of your parts to have connections that can fit firmly in a solderless breadboard. Many electronic components and connectors don’t have such connections, so you need to solder them on. The DC power jack shown in this exercise is one such connector. It comes with no wires, just connections onto which you’re expected to solder your own wires.  You’ll solder wires onto it, and then you’ll solder a pair of stiff header pins onto the ends of the wires.

Preparing the parts

Cut a red and a black wire about four inches (10cm) in length. Strip the ends back about 1/4 of an inch (1/2 cm). Bend a hook on one end of each wire. Unscrew the power jack. As shown in Figure 9, connect the red wire to the hole in the the center tab of the power, and the black to the hole in the outside tab. Use pliers to crimp the hooked wires to their connections on the jack. If the connections aren’t soldered, you’ll get an inconsistent connection at best, and a short circuit at worst.

Related video: Wiring a power supply using a DC power jack

Photo of a DC power jack with 22AWG wires hooked into its two solder tabs. The wires are not yet soldered.
Figure 9. A DC power jack ready to solder

Heating the Soldering Iron (and the connections)

Heat up your soldering iron. It doesn’t need to be cranked to its maximum heat. For most small jobs like this, 600-700 degrees Fahrenheit (315-370 C) will work just fine. You really only need the iron hot enough to heat the metal connections so that they’ll melt the solder.

The best solder joints are those where the two metal connections to be joined are heated up together, and the solder is then melted by the heat of the connections. That way, all three metals cool down together. As they cool, they contract. You want them to contract together, so there is no cracking of the joint between them.

Make sure the two pieces of metal are touching each other firmly. Use a helping hand or a clamp to hold them in place. When they’re solidly touching, and held firmly by your clamp or helping hands, touch the iron to the joint between the wire and the metal to heat the joint (see Figure 10). Then touch the solder to the joint (NOT to the iron) until it melts. This should make a clean solder with a small blob of solder.

You may find that it takes longer to heat the connection in order for the solder to melt. The larger a connector is, the more time it takes to heat. This is because the metal of the connector is conducting the heat away from the joint. If your connector is too big, you may need to use a mechanical joint, as opposed to a solder joint. The DC power jacks shown in this tutorial will solder just fine, however.

As the solder cools down, its surface will go from shiny to a more matte surface. When it cools down, test the joint by wiggling it to make sure it’s firm.

Repeat the process with the other wire and the other part of the connector.

Photo of a wire hooked into the metal tab of a power connector. Both are held by a pair of helping hands clips. A soldering iron is touched to the joint between the wire and the tab. A piece of solder is touched to the joint, but is not touching the iron directly.
Figure 10. Preparing the solder joint. The solder should be touched to the joint, not to the iron.

Twist the wires together and thread them through the sleeve of the jack.

The result should look like this in Figure 11:

Photo of a soldered power connector. The wires are soldered to the two tabs of the connector, then twisted together before they are threaded into the plastic insulating sleeve of the connector.
Figure 11. The inside of a soldered power connector, with red and black wires twisted together.

Soldering the Header Pins

The two wires are now properly separated inside the connector, but the other ends can move freely. Even though these two ends can fit firmly in a breadboard, it can be dangerous to leave them loose. They might touch each other while you have the connector plugged in, causing a short circuit.

Header pins(Figure 12) are a great way to maintain the spacing between wires that you need to fit into a breadboard. If you solder two of them to the ends of your wires, with the metal spacer still on them, they’ll keep your wire leads safely apart.

Photo of breakaway header pins. There are 20 pins in one row. The pins are all 0.5 inch (1.3cm) long, and separated by 0.1 inch (2.5mm) plastic spacers. The plastic is scored so that the pins can be broken off one at a time.
Figure 12. Breakaway header pins

Trim the ends of the wires to the same length, and strip them back to about 1/8th of an inch. Break off two header pins and hold them in one clip of a helping hands device. Clip the wires in the other clip, and align them with the header pins like so in Figure 13:

Photo of two header pins held in a helping hands tool. The headers are touching two wires, one red, one black. The wires and the header pins are not soldered together.
Figure 13. Header pins ready to be soldered to the ends of your wires.

Solder the wires to the headers. Move quickly, as the plastic spacer between the headers can melt (that’s another reason not to heat your iron too hot). When you’re done soldering, you should have two separate blobs like this in Figure 14:

Photo of two header pins held in a helping hands tool. The headers are touching two wires, one red, one black. The wires and the header pins are soldered together.
Figure 14. Header pins successfully soldered to wires.

If you can’t see space between the two solder joints, de-solder them and do it again. You need to be sure there’s no connection between these wires that can cause a short circuit, and the best way to do that is to leave space.

Take a hot glue gun and surround the bare connections to insulate them and provide some strain relief. When you’re done, you should have a connection like this in Figure 15:

Photo of an assembled DC power connector. Red and black wires, twisted together, protrude from the connector. They terminate in a pair of header pins, The connection between the wires and the header pins, previously soldered, is hot glued for insulation.
Figure 15. DC power connector assembled, with the wire-to-header connections insulated with hot glue.

Make sure you can tell which pin is connected to the red wire and which is connected to the black.

Testing

Before you connect it to power, take a meter and check the connections for continuity. The center pin should be connected to the red wire, and the outer rim should be connected to black. When that’s good, you’re ready to use it.

What Else Can I Solder?

Any time you have loose mechanical connections, you should solder them if you can. For example, many common potentiometers have ring contacts(Figure 16). If you loop the wires around the rings as shown in Figure 17, you get inconsistent readings from your potentiometer. Solder the leads if they are loose.

Photo of a potentiometer with metal ring contacts.
Figure 16. A potentiometer with ring contacts, ready for soldering.
Photo of a potentiometer with ring contacts. Three wires are soldered to the three contacts, from left to right: black wire, blue wire, red wire.
Figure 17. Potentiometer with wires successfully soldered.

Many breadboard-friendly printed circuit boards come without headers soldered on. One of the most common mistakes beginners make with these boards is to push them into a breadboard using headers, but with no solder. This will also give inconsistent readings. Figure 18 shows an ADXL335 accelerometer module pins are properly soldered.

An ADXL335 accelerometer module. There are six pins along the bottom, labeled GND, Z, Y, X, 3V, and ST (left to right)
Figure 18. An ADXL335 accelerometer module. There are six pins along the bottom, labeled GND, Z, Y, X, 3V, and ST (left to right). These pins are properly soldered (You can find this accelerometer on adafruit.com)

When in doubt, if you have loose connections, solder them!

For more on soldering, check out Adafruit’s soldering tutorial.

Digital Input & Output

Introduction

This is an introduction to basic digital input and output on a microcontroller. In order to get the most out of it, you should know something about the following concepts.  You can check how to do so in the links below:

These videos will help in understanding digital inputs and outputs:

Digital Inputs

When you’re trying to sense activity in the physical world using a microcontroller, the simplest activities you can sense are those in which you only need to know one thing about the physical world: Whether something is true or false. Is the viewer in the room or out? Are they touching the table or not? Is the door open or closed? In these cases, you can determine what you need to know using a digital input, or switch.

Digital or binary inputs to microcontrollers have two states: off and on. If voltage is flowing, the circuit is on. If it’s not flowing, the circuit is off. To make a digital circuit, you need a circuit, and a movable conductor which can either complete the circuit, or not.

Schematic of a Digital Input to a microcontroller
Figure 1. Schematic of a Digital Input to a microcontroller

Figure 1 shows the electrical schematic for a digital input to a microcontroller. The current has two directions it can go to ground: through the resistor or through the microcontroller. When the switch is closed, the current will follow the path of least resistance, to the microcontroller pin, and the microcontroller can then read the voltage. The microcontroller pin will then read as high voltage or HIGH. When the switch is open, the resistor connects the digital input to ground, so that it reads as zero voltage, or LOW.

On an Arduino module, you declare the pin to be an input at the top of your program. Then you read it for the values 1 (HIGH) or 0 (LOW), like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void setup() {
 // declare pin 2 to be an input:
 pinMode(2, INPUT);
 declare pin 3 to be an output:
 pinMode(3, OUTPUT);
}
 
void loop() {
 // read pin 2:
 if (digitalRead(2) == 1) {
   // if pin 2 is HIGH, set pin 3 HIGH:
   digitalWrite(3, HIGH);
 } else {
   // if pin 2 is LOW, set pin 3 LOW:
   digitalWrite(3, LOW);
}

Digital output

Just as digital inputs allow you to sense activities which have two states, digital or binary outputs allow you to control activities which can have two states. With a digital output you can either turn something off or on. Figure 2 is the schematic diagram for digital output controlling an LED:

Schematic of and led as a digital output from a microcontroller
Figure 2. Schematic of and led as a digital output from a microcontroller

Digital outputs are often used to control other electrical devices besides LEDs,  through transistors or relays. For more information on that, see these notes on controlling high-current circuits.

On an Arduino module, you declare the pin an output at the top of the program just like you did with inputs. Then in the body of the program you use the digitalWrite() command with the values HIGH and LOW to set the pin high or low, as you’ve seen above.
Here’s a simple blinking LED program in Arduino:

1
2
3
4
5
6
7
8
9
10
void setup() {
  pinMode(13, OUTPUT);
}
 
void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

As inputs, the pins of a microcontroller can accept very little current. Likewise, as outputs, they produce very little current. The electrical signals that they read and write are mainly changes in voltage, not current. When you want to read an electrical change that’s high-current, you limit the current input using a resistor. Similarly, when you want to control a high-current circuit, you use a transistor or relay, both of which allow you to control a circuit with only small voltage changes and minimal current. Related video: Transistor

Lab: Components

In this lab you will learn about some of the components you’ll use frequently when making electronic circuits.

Introduction

In this lab you will learn about some of the components you’ll use frequently when making electronic circuits. For more on any given component, please check out its datasheet. There are no specific activities in this lab other than to examine the components and to familiarize yourself with them.

Video: Schematics 5

A datasheet or spec sheet is a document (printed or .pdf) that describes the technical characteristics of a sensor, electronic component, product, material or other. It includes details on how to use the component in a circuit and other useful design info on how to integrate it into a system together with specifications on performance and other characteristics that are important to know.

Components

Video: Datasheets

Voltage Regulator

5-volt regulator, model 7805. This component has three legs and a tab at the top with a hole in it. If you hold the component with the tab at the top and the bulging side of the component facing you, the legs will be arranged, from left to right, voltage input, ground, and voltage output.
Figure 1. 5-volt voltage regulator, model 7805

Related Video: Voltage Regulator
Related Video: Using a voltage regulator on a breadboard

Different electronic circuits operate at different voltages. For example, the Arduino Uno operates at 5 volts, while the Arduino Nano 33 IoT and BLE, and the MKR series, operate at 3.3 volts. A voltage regulator takes a range of DC voltage as input and convert it to a constant voltage. For example, this regulator shown in Figure 1, a 7805 regulator, takes a range of 9 – 15 volts DC input and converts it to a constant 5-volt output. Using this regulator, you could power a 5-volt motor or a string of addressable LEDs from a 12-volt power source.

Note the label on the regulator that reads “7805”. This is the part number. Other parts have the same physical form factor, however. The form factor, called the package, is not dependent on what the actual part is. This  is a TO-220 package. Many different parts use this same package, for example, and not all of them are voltage regulators. Also, sometimes the same part will come in different packages, so you can use it in different size devices.

Related Video: Read the labels to differentiate similar packages

The 7800 series regulators come in many different voltages. 7805 is a 5-volt regulator. 7809 is a 9-volt regulator. 7812 is a 12-volt regulator. All the regulators of this family have the same pin connections. In the image above, the left leg is connected to the input voltage. The middle leg is connected to ground. The right leg is the output voltage.

Link to 7805 datasheet

3.3-volt regulator, model LD111733V. This component has three legs and a tab at the top with a hole in it. If you hold the component with the tab at the top and the bulging side of the component facing you, the legs will be arranged, from left to right, ground, voltage output, and voltage input. The back tab is attached to the voltage output pin.
Figure 2. 3.3V voltage regulator

3.3V regulators are also common. Note that not all regulators which share the same package have the same pin configuration. For example, the LD1117V33, a 3.3V regulator shown in Figure 2, comes in the same physical package as a 7805, but its pins are in a different order. The LD1117V33’s pins, from left to right, are ground, output voltage, input voltage.

LED

LEDs. Shown here are four LEDs. The one on the right is an RGB LED. You can tell this because it has four legs, while the others have only two legs.
Figure 3. LEDs. Shown here are four LEDs. The one on the right is an RGB LED. You can tell this because it has four legs, while the others have only two legs.

Related Video: Diodes and LEDs

LEDs, or Light Emitting Diodes (see Figure 3), are diodes that emit light when given the correct voltage and current. Like all diodes, they are polarized, meaning that they only operate when oriented correctly in the circuit. The anode of the LED connects to voltage, and the cathode connects to ground. The anode in the LEDs in this photo is the longer leg on each LED. LEDs come in many different packages. The packages above have built-in lenses.

Related Video: How to connect an LED and resistor

These LEDs are the cheapest you can buy, and they’re not very bright. You can get super-bright LEDs as well, which are much brighter. If you’re working on applications that need very small light sources, you can also get LEDs in a surface mount package.

LEDs can only handle a limited amount of current and voltage. The details should be covered in each LED’s datasheet. Here is the datasheet of a typical white LED. You’ll see that the forward current is 30 mA max, and the forward voltage is between 2.9 and 3.6V. That means if you give it 30mA at 3.6V, you should get maximum brightness out of it. If you don’t have the datasheet for your LED, here’s a link to a handy LED current calculator. Try putting in the supply voltage (3.3V or 5V), the voltage drop across the LED (the forward voltage), and the current (30 mA) and see what value of resistance you get. For most common LEDs running at 3.3 or 5 volts, a resistor about 220 will limit the current safely while still providing enough to light the LED.

Solderless Breadboard

A short solderless breadboard with two rows of holes along each side. There are no components mounted on the board. The board is oriented sideways so that the long rows of holes are on the top and bottom of the image.
Figure 4. A short solderless breadboard.

Related Video: Introduction to breadboards

Solderless breadboards are reusable prototyping tools for electronics that allow you to build and experiment with circuits simply by plugging components in and out of its rows and columns. They come in different shape and sizes. Figure 4 shows a typical short solderless breadboard. It has two rows of holes on either side of the board, usually used as voltage and ground buses. The board is turned in this photo so that the bus rows are on top and bottom. In the center of the board, there are thirty rows of holes. There is a divider down the center of the board that breaks up the rows of holes into separate rows. There are five holes per row on the center left and on the center right of each row.

Resistors

Resistors. Shown here are 220-ohm resistors. You can tell this because they have two red and one brown band, followed by a gold band.
Figure 5. Resistors. Shown here are 220-ohm resistors. You can tell this because they have two red and one brown band, followed by a gold band.

Related Video: Resistors, variable resistors, and photocells

Resistors resist the flow of electrical current. When placed in series, they reduce the voltage, and limit the current. The bands on a resistor indicate the resistor’s value. Here’s a handy resistor color code calculator. Resistors come in 4-band, 5-band, and 6-band models. In a 4-band resistor, the bands represent the first digit, second digit, multiplier, and tolerance. The resistors shown in Figure 5 are 4-band resistors marked red, red, brown, and gold, for 2, 2, times 101, 5%. In other words, these are 220 ohm resistors, +/-5%.  The resistor color code calculator explains the bands for 5-and 6-band resistors as well.

Potentiometers

Potentiometer. The one shown here has three legs spaced 0.1 inches apart and can be therefore mounted on a solderless breadboard.
Figure 6. Potentiometer. The one shown here has three legs spaced 0.1 inches apart and can be therefore mounted on a solderless breadboard.

Related Video: Potentiometer

Potentiometers are variable resistors. The two outside terminals act as a fixed resistor. A movable contact called the wiper moves across the resistor, producing a variable resistance between the center terminal and either of the two sides. The potentiometer in Figure 6 has pins so you can mount it on a breadboard.

Related Video: Measure a potentiometer’s variable resistance
Related Video: Potentiometer schematic

Trimmer potentiometers. These are small potentiometers, square, approximately half an inch (1cm) square. They have three legs spaced 0.1 inches (2.54cm) apart and can be therefore mounted on a solderless breadboard.
Figure 7. Trimmer potentiometers

Trimmer potentiometers like those shown in Figure 7 are designed to be mounted on a circuit board, and are difficult to turn, so you can use them to adjust a circuit. They’re very small. They’re handy to use as physical variables, to tune your project.

Force Sensing Resistors

Force sensing resistors are sensors that change their resistance in response to force. They’re usually used to make analog alternatives alternatives to buttons. They’re made of a substrate of resistive rubber between two layers of conductive ink on a plastic film. They come in a variety of form factors. Figure 8 shows a pair of force sensors about 2.5cm across, sized for finger presses. There are a few companies who make them, including Interlink, Ohmite, and Tekscan.

A pair of force sensing resistors
Figure 8. Force sensing resistors

Flex Sensors (Flex Resistors)

Flex sensors are similar to force sensing resistors in construction, but they change their resistance as they bend. They are typically about the length of a finger, and they work well for measuring the bend of a finger. Spectrasymbol make these.

Photo of a flex sensor. A plastic strip approx. 0.25 inches wide by 6 inches long, with pins at one end. When you bend the sensor, the resistance between the pins changes
Figure 9. Flex sensor

Force Sensing Potentiometers

Force Sensing Potentiometers, sometimes called SoftPots, are also similar to force sensing resistors. The difference is that a force sensing resistor gives one value wherever you press on it, while a force sensing potentiometer acts like a normal potentiometer: the value changes depending on where along its length you press. They come in linear and round form factors. Ohmite, Interlink, and Spectrasymbol make FSPs.

Figure 10. Force Sensing Potentiometer

Light-Dependent Resistors (Photocells)

Photocell, or light-dependent resistor. This component has a round top and two wire legs. You measure the resistance between the two legs and expose the top to a varying light source in order to vary the resistance between the two legs.
Figure 11. Photocell, or light-dependent resistor

Related Video: Wiring a photocell to measure light

Light-dependent resistors, or photocells, are variable resistors whose resistance changes with the intensity of the light falling on the resistor. Photocells, as seen in Figure 11, are made with cadmium sulfide, which is a toxic chemical. Increasingly, they are being replaced in hobbyist kits by phototransistors, which are somewhat less toxic (see below).

Thermistors

Thermistor, or temperature-dependent resistor. This component has a bulbous top and two wire legs. You measure the resistance between the two legs and expose the top to a varying temperature in order to vary the resistance between the two legs.
Figure 12. Themistor, or temperature-sensitive resistor

Thermistors, seen in Figure 12, are variable resistors whose resistance changes as the temperature changes. You measure the resistance between the two legs of the thermistor and expose the top to a varying temperature in order to vary the resistance between the two legs.

Switches

Pushbuttons. These ones are designed to be mounted on a solderless breadboard. They have four legs spaced 0.2 inches apart on both sides of the component.
Figure 13. Pushbuttons, also called momentary switches

Related Video: Switches
Related Video: Connect a switch to a digital pin

Switches are one form of digital input. There are many kinds of switches. The two most useful categories are momentary switches, which remain closed only when you press them, and toggle switches, which stay in place after you switch them.

Pushbuttons are a common type of momentary switch. The pushbuttons in the photo in Figure 13 above are designed to be mounted on a circuit board. They are very small, less than 1 centimeter on a side. They have four pins. When the button is facing you,  top two are connected to each other, and the bottom two are connected to each other. Pushing the button connects the top pins to the bottom pins.

Toggle switches (Figure 14) stay in one position when you flip them. Wall light switches are common examples of toggle switches. Unlike a momentary switch, a toggle switch can be used to turn a device on or off, because they stay in one state when you remove your hand. The toggle switches below each have three connectors, also called pins or legs. They’re usually labeled C for common, NO for Normally Open, and NC for Normally Closed. When you switch the switch, it will open the connection between the common pin and the normally closed pin, and close the connection between the common pin and the normally open pin. Switch it the other way, and you will reverse the connection.

Toggle switches. These switches are approximately half an inch (1cm) long, and have a switch on top that moves from one side to the other. They typically have two or three legs.
Figure 14. Toggle switches

Rotary Encoder

Photo of a rotary encoder
Figure 15. Rotary encoder

A rotary encoder is a sensor that usually looks a bit like a potentiometer. It has a central shaft that you can turn with your fingers, or with an axle. It produces a pair of electrical pulses as you turn the shaft of the encoder, one slightly before or after the other, depending on the direction you are turning the shaft. Unlike a potentiometer, they can turn endlessly. They are used both as tangible controls, when you want a knob that turns endlessly, and as rotary sensors for motors and axles. The encoder in Figure 15 has three pins. The center is connected to ground, and the two side pins produce the pulses. The Encoder library for Arduino is useful for reading these.

Capacitors

Ceramic capacitor. This component has a disc top and two wire legs. You measure the capacitance between the two legs. Ceramic disc capacitors like this are generally low-capacitance components.
Figure 16. Ceramic disc capacitors

Related Video: Capacitors

Capacitors store electrical energy while there’s energy coming in, and release it when the incoming energy stops. They have a variety of uses. One common use is to smooth out the dips and spikes in an electrical supply. This use is called decoupling.

Related Video: Clean a noisy signal with a Capacitor

Ceramic capacitors are unpolarized. They generally have very small capacitance values. They’re useful decoupling caps in a low-current circuit. You often see them used to decouple the power going into a microcontroller or other integrated circuit.

The number on a ceramic cap gives you its value and order of magnitude. For example, 104 on the capactors in Figure 16 indicates a 0.1 microfarad (uF) cap. 103 indicates a 0.01 microfarad cap.

Electrolytic capacitor. This component has a tubular top and two wire legs coming out of one end of the tube. They are generally polarized. The longer leg is the positive leg. You measure the capacitance between the two legs. Electrolytic capacitors are generally higher capacitance than ceramic capacitors.
Figure 17. Electrolytic capacitor

Electrolytic capacitors (Figure 17) can generally store more charge than ceramic caps, and are longer lasting. They’re usually polarized, meaning that they have a positive leg and a negative leg. This is because current flows more efficiently through them one way than the other.

Electrolytic capacitor, showing the minus sign on the negative side. This component has a tubular top and two wire legs coming out of one end of the tube. They are generally polarized. The longer leg is the positive leg. You measure the capacitance between the two legs. Electrolytic capacitors are generally higher capacitance than ceramic capacitors.
Figure 18. Electrolytic capacitor, showing the minus sign on the negative side.

An electrolytic cap will have a + or – on one side, as shown in Figure 18.

Diodes

Diodes. Shown here are 1N400x power diodes. The body of the component is black, and the end is silver. The silver end indicates the cathode end of the diode.
Figure 19. Diodes. Shown here are 1N400x power diodes. The body of the component is black, and the end is silver. The silver end indicates the cathode end of the diode.

Related Video: Diodes and LEDs

Diodes permit voltage to flow in one direction and block it in the other direction. LEDs are a type of diode, as are the 1N4001 diodes shown in Figure 19. They’re useful for stopping voltage from going somewhere you don’t want it to go. The 1N4001 diodes are power diodes, capable of carrying a higher amount of current than other diodes.

Zener diodes. These diodes are smaller than the power diodes shown above, and have a gladd body and a black stripe to indicate the negative end of the diode. They have a breakdown voltage past which they allow current to flow in both directions.
Figure 20. Zener Diodes

Zener diodes (Figure 20) have a breakdown voltage past which they allow current to flow in both directions. They’re used to chop off excess voltage from a part of a circuit. They are usually smaller than power diodes.

Transistors

TIP120 transistor. The transistor here has the same physical package as the voltage regulators shown above. It has three legs and a tab at the top with a hole in it. The tab is the back of the component. If you hold the component with the tab at the top and the bulging side of the component facing you, the legs will be arranged, from left to right, base, collector, emitter. The only way to know the difference between two components of the same package is to read the label on the package, unfortunately. This one is labeled TIP120.
Figure 21. TIP120 transistor

Video: Schematics 3 – Transistors

Transistors act as electronic switches. When you put a small voltage across the base and emitter, the transistor allows a larger current and voltage to flow from the collector to the emitter. The transistor shown above in Figure 21, a TIP120, is a type of transistor known as a Darlington transistor. It is usually used to control high-current loads like motors. Note that it uses the same physical form factor, or package, as the voltage regulator above (the TO-220 package).

The TIP120 shown here is jus one option for controlling high current loads. Metal Oxide Semiconductor Field Effect Transistors, or MOSFETS, are also good for controlling motors, lights, and other high current loads. These two models also come in the same physical package as the TIP120. The IRF510 and IRF520 MOSFETs have the same pin configuration as the TIP120, and perform similarly with a 5V gate voltage. The FQP30N06L MOSFET has the same pin configuration, and operates on as low as 1.0V, and works well for 3.3V applications. MOSFETs can generally handle more amperage and voltage, but are more sensitive to static electricity damage. 

Related Video: Connect Transistor

Phototransistors

Photo of a handful of Phototransistors.
Figure 15. Phototransistors. The short leg goes to voltage, and the long leg goes to the input pin of a microcontroller.

Phototransistors are transistors, but instead of being controlled by electricity, they are controlled by light. The base of a phototransistor is photosensitive. They often look like LEDs. The ones in Figure 15, Everlight model ALS-PT243-3C/L177, have flat tops to differentiate them from LEDs. The short leg of a phototransistor is the emitter, and the long leg is the collector. The lens is the base. To use them in an analog input circuit.  emitter goes to voltage and the collector goes to your input pin. A 10-kilohm pulldown resistor connects the input pin to ground, just as it would if you were using a photocell..

Power Jacks

A DC power jack. It pairs with a plug with a 2.1mm inside diameter, 5.5mm outside diameter plug, and has screw terminals on the back so that you can attach wires to it.
Figure 22. A DC Power Jack

DC Power jacks are used to connect your breadboard to a DC power supply that you can plug into a wall. They’re less common in microcontroller circuits now that USB power connectors and USB wall plugs are common, but they are still very handy when you have only a DC power supply to work with. The one in Figure 22 has screw terminals on the back to which you can connect wires to connect to your breadboard. It is a 2.1mm inside diameter, 5.5mm outside diameter jack, which is a very common size.

Battery Holders

This is a square box that can hold four AA size batteries. There are four columns in the box, each with a spring in it. The negative end of the battery (the flat end) contacts the spring. The positive end of the battery (the end with a small protrusion) connects to the end opposite the spring. The batteries sit parallel to each other, each facing the opposite direction of its neighbors. Two round metal terminals protrude from one corner of the box, one red and one black. These connect to a 9-volt battery
Figure 23. AA battery holder
9V battery snap. This flat component with rounded ends has two round metal mounts on one side. One is slightly bigger than the other, about half an inch (3-2cm) across. They are designed to snap onto a 9-volt battery. There is a pair of wires coming out one end that has a DC power plug attached to it. This can plug into a DC power jack.
Figure 24. 9V battery snap with DC power plug on it.

Battery connectors like the ones shown in Figures 23 and 24 are good for connecting batteries to your project. The one in Figure 20 can hold 4 AA batteries, and has a 9V battery snap on the outside. The one in Figure 21 has a DC power jack  on one end, and a 9V battery snap on the other end.

Motors

Servo Motor

Servomotor. This is a rectangular motor with a round shaft protruding from one of the narrow sides. a wire connector protrudes from the diagonally opposite corner. The motor is approximately 1.t5 inches square (about 4cm) by half an inch thick (about 1cm). The shaft connects to one of several plastic horns so you can attach it to things you want to move. When turned by hand, the shaft will only turn 180 degrees.
Figure 25. A small RC Servomotor

Video: Analog Output: Servo

A servo motor is a motor paired with an encoder (e.g. a potentiometer) to provide position/speed readings and control messages in a feedback loop. This loop is used to precisely control of the servo’s degree of rotation. RC servomotors like the one shown in Figure 25 can only turn 180 degrees. They are often used for the rudder control on remote control planes and cars. The plastic bits shown in the photo are called horns, and they attach to the shaft to let you attach the motor to the mechanism that you want to control.

DC Motor

DC toy motor, hobby size. This motor is a metal tube with flattened sides, approximately 2 in. (5cm) long. a thin shaft at one end spins when the motor is on. Two small metal tabs or wires protrude from the other end to connect the motor to your circuit.
Figure 26. Small DC motor, 130 size

Related Video: Inside a DC Motor

DC motors, as seen in Figure 26, utilize induction (an electromagnetic field generated by current flowing through a wire coil) to rotate a central shaft. You can reverse the direction that the shaft rotates by reversing the leads powering it.

Motor Driver

Photo of a Motor Driver (H-bridge), model TB6612FNG
Figure 27. Motor Driver (H-bridge), model TB6612FNG

A motor driver, sometimes called an H bridge, is an electronic circuit that enables a voltage to be applied across a load in either direction. They are often used to control the direction of DC motors. The motor driver in Figure 27 is a Toshiba model TB6612FNG. It is a good option for both 5V (from an Arduino Uno) and 3.3V (from a Nano 33 IoT) control of DC motors and stepper motors.

Electromechanical Relay

These components are rectangular, approximately three quarters of an inch long and half an inch tall, with seven pins on the bottom.
Figure 28. Electromechanical relays: top and left views as well as inside.

Like transistors, relays are electronic switches. Electromechanical relays contain a small coil that, when energized, creates a magnetic field that moves a small metal armature to open or close an electrical contact. Relays can handle higher current than transistors and can be used for AC or DC loads. However, because they rely on a physical mechanism, they are slower and more prone to wearing out. If you want to control a relay with the Arduino, you will need to use a transistor as an intermediary because most relays draw more current than the Arduino’s output pins can supply.

Relays come in many packages. The ones shown in Figure 28 are for controlling relatively low power loads. For more on relays, see the Transistors, Relays, and Controlling High-Current Loads topic page.

Screw Terminal

These components have a small round depression on the top, inside of which is a screw. On the side there is a square hole into which you can insert a wire. On the bottom, there is a pin connected to the square socket. There is one screw, socket, and pin per connection.
Figure 29. Two-contact screw terminal

Screw terminals, as seen in Figure 29, are electrical connectors that hold wires in place with a clamping screw. They allow for a more secure connection than female headers and more flexibility than soldering a wire in place. There is one screw, socket, and pin per connection.

Sensor Modules

Increasingly, sensors are no longer just simple components that output a changing resistance or capacitance. Sensor modules are application-specific integrated circuits (ASICs) which read a particular physical property and give you a measurement via a synchronous serial communications channel like I2C.

Figure 30 shows four different I2C sensors: a ten-channel spectrometer, at the top, which measures the intensity of light in ten different frequencies; An accelerometer, on the right (read below for more); a time-of-flight distance ranging sensor, that measures distance using an infrared low-power laser, on the bottom; and a light sensor that functions as both a particle sensor and a pulse oximeter, on the left, by measuring the change in color of your blood through the skin of your finger.

These are only a few of the many sensor modules available that can be connected to a microcontroller via I2C. You’ll see color and gesture sensors, temperature and humidity sensors, and many more. They are often available as breadboard-friendly breakout board modules, like the ones shown here, that are typically a circuit board that’s a few centimeters square, with holes on one side spaced 0.1″ apart so you can attach pins to plug it into a breadboard.

Photo of four different I2C sensor modules
Figure 30. Various I2C sensors

Accelerometer

Photo of an accelerometer, model LIS3DH
Figure 31. Accelerometer, LIS3DH

Accelerometers are sensors which measure a changing acceleration (Figure 31). They are typically part of sensors called Inertial Measurement Units, or IMUs. They are useful for measuring the tilt of a body, or for measuring the force of an impact. They come in both digital and analog forms. A typical accelerometer measures acceleration along three axes, all perpendicular to each other. Accelerometers are increasingly built into microcontroller modules and other electronic devices. There is accelerometer and a gyrometer built into the Nano 33 IoT.

Infrared Distance Ranger

Sharp makes a line of infrared distance ranging sensors that measure distance in about a 1-meter range using infrared light. The one shown in Figure 32 has an analog voltage output.

Photo of an infrared distance sensor. It has two lenses on top, one for the light and one for the sensor, and three pins on the side, to plug into a solderless breadboard.
Figure 32. IR distance ranger

Ultrasonic Distance Ranger

Ultrasonic distance rangers measure distance by emitting pulsed ultrasonic waves and listening for the echo from a distant object. These are sometimes used in cars to aid in detecting the distance of objects behind the rear bumper. The one shown in Figure 33 outputs a digital pulse whose pulse width varies with the distance from the target object.

Ultrasonic sensor model HC-SR04
Figure 33. An Ultrasonic sensor, model HC-SR04. The sensor has two cylindrical transducers, and four pins at the bottom of the board, labeled from left to right: Vcc, Trig., Echo, Ground.

Temperature and Humidity Sensors

There are dozens of temperature and humidity sensors on the market, with many different interfaces. The one shown in Figure 34, the DHT22, is very popular because it’s simple to use, reliable with a long track record, and inexpensive. It uses a one-wire interface.

Figure 34. a DHT-22 temperature and humidity sensor

Speaker

Photo of an 8 ohm speaker
Figure 35. Photo of an 8 ohm speaker

A speaker is a paper or plastic cone mounted to a coil of wire. The coil is mounted next to a magnet. When a current is passed through the wire, it induces a magnetic field, which attracts or repulses the magnet. This makes the cone vibrate, and produce sound. The speaker shown in Figure 35 is an 8-ohm speaker.