- Building an Arduino Sketch
- Creating Your First Sketch
- Interfacing with Electronic Circuits
- Summary
- Workshop
Interfacing with Electronic Circuits
While getting your sketch uploaded to the Arduino and running is a significant accomplishment, most likely you’ll want to do more in your Arduino projects than just watch the L LED blink. That’s where you’ll need to incorporate some type of external electronic circuits into your projects. This section covers the basics of what you need to know to add external electronic circuits to your Arduino sketches.
Using the Header Sockets
The main use of the Arduino is to control external electronic circuits using the input and output signals. To do that, you need to interface your electronic circuits with the Arduino analog and digital signals. This is where the header sockets come into play.
If you remember from Hour 1, “Introduction to the Arduino,” the header sockets are the two rows of sockets at the top and bottom of the Arduino Uno circuit board. (Some more advanced Arduino units, such as the Arduino Mega, also include a third header socket on the right side of the board to support additional ports.) You’ll plug your electronic circuits into the sockets to gain access to the Arduino input and output signals, as well as the power from the Arduino.
The basic Arduino Uno unit that we’re using for our experiments uses the standard Arduino tworow header socket format. Figure 4.5 shows the layout of the upper and lower header sockets.
FIGURE 4.5 The Arduino Uno upper and lower header sockets.
The lower header socket has 13 ports on it, as described in Table 4.1.
TABLE 4.1 The Arduino Uno Lower Header Socket Ports
Label |
Description |
IOREF |
Provides the reference voltage used by the microcontroller if not 5V. |
RESET |
Resets the Arduino when set to LOW. |
3.3V |
Provides a reduced 3.3V for powering low-voltage external circuits. |
5V |
Provides the standard 5V for powering external circuits. |
GND |
Provides the ground connection for external circuits. |
GND |
A second ground connection for external circuits. |
Vin |
An external circuit can supply 5V to this pin to power the Arduino, instead of using the USB or power jacks. |
A0 |
The first analog input interface. |
A1 |
The second analog input interface. |
A2 |
The third analog input interface. |
A3 |
The fourth analog input interface. |
A4 |
The fifth analog input interface, also used as the SDA pin for TWI communications. |
A5 |
The sixth analog input interface, also used as the SCL pin for TWI communications. |
The upper header socket has 16 ports on it, as described in Table 4.2
TABLE 4.2 The Arduino Uno Upper Header Socket Ports
Label |
Description |
AREF |
AREF Alternative reference voltage used by the analog inputs (by default, 5V). |
GND |
The Arduino ground signal. |
13 |
Digital port 13, and the SCK pin for SPI communication. |
12 |
Digital port 12, and the MISO pin for SPI communication. |
–11 |
Digital port 11, a PWM output port, and the MOSI pin for SPI communications. |
–10 |
Digital port 10, a PWM output port, and the SS pin for SPI communication. |
–9 |
Digital port 9, and a PWM output port. |
8 |
Digital port 8. |
7 |
Digital port 7. |
–6 |
Digital port 6, and a PWM output port. |
–5 |
Digital port 5, and a PWM output port. |
4 |
Digital port 4. |
–3 |
Digital port 3, and a PWM output port. |
2 |
Digital port 2. |
TX ->1 |
Digital port 1, and the serial interface transmit port. |
RX <- 0 |
Digital port 0, and the serial interface receive port. |
For our test sketch, we need to access the digital port 13 socket, in addition to a GND socket, to complete the electrical connection to power our electronic devices.
To access the sockets, you can plug wires directly into the socket ports. To make it easier, you can use jumper wires, which you can easily remove when you finish experimenting.
Building with Breadboards
When you build an electronic circuit, the layout is usually based on a schematic diagram that shows how the components should be connected. The schematic shows a visual representation of which components are connected to which, using standard symbols to represent the different components, such as resistors, capacitors, transistors, switches, relays, sensors, and motors.
Your job is to build the electronic circuit to mimic the layout and connections shown in the schematic diagram. In a permanent electronic circuit, you use a printed circuit board (called PCB) to connect the components according to the schematic.
In a PCB, connections between the electronic components are etched into the PCB using a metallic conductor. To place the electronic components onto the PCB, you must solder the leads of the components onto the PCB.
The downside to using a PCB for your electronic project is that because it’s intended to be permanent, you can’t easily make changes. Although that’s fine for final circuits, when you’re developing a new system and experimenting with different circuit layouts, it’s somewhat impractical to build a new PCB layout for each test.
This is where breadboards come in handy. A breadboard provides an electronic playground for you to connect and reconnect electronic components as you need. Figure 4.6 shows a basic breadboard layout.
FIGURE 4.6 A basic breadboard.
Breadboards come in many different sizes and layouts, but most breadboards have these features:
- A long series of sockets interconnected along the ends of the breadboard. These are called buses (or sometimes rails), and are often used for the power and ground voltages. The sockets in the bus are all interconnected to provide easy access to power in the circuit.
- A short series of sockets (often around five) interconnected, and positioned across a gap in the center of the breadboard. Each group of sockets is interconnected to provide an electrical connection to the components plugged into the same socket group. The gap allows you to plug integrated circuit chips into the breadboard and have access to the chip leads.
The breadboard allows you to connect and reconnect your circuits as many times as you need to experiment with your projects. Once you get your circuit working the way you want, you can transfer the breadboard layout onto a PCB for a more permanent solution.
Adding a Circuit to Your Project
Now that you’ve seen how to add external electronic circuits to your Arduino project, let’s create a simple circuit to add to our Arduino sketch. Instead of using the L LED on your Arduino, let’s use an external LED.
For this project, you need the following parts:
- A standard breadboard (any size)
- A standard LED (any color)
- A 1000ohm resistor (color code brown, black, red)
- Jumper wires to connect the breadboard circuit to the Arduino
The circuit uses a 1000ohm resistor to limit the voltage that flows through the LED to help protect the LED. The LED doesn’t need the full 5V provided by the Arduino output, so by placing a resistor in series with the LED, the resistor helps absorb some of the voltage, leaving less for the LED. If you don’t have a 1000ohm resistor handy, you can use any other resistor value to help lessen the voltage applied to the LED.
Figure 4.7 shows connecting the resistor and LED to the GND and digital pin 13 ports on your Arduino Uno unit.
FIGURE 4.7 Circuit diagram for the sample project.
Just follow these steps to create your electronic circuit for the project.
Now you should be ready to test things out. Power up the Arduino, either by connecting it to the USB port of your workstation or by connecting it to an external power source. Because the Arduino maintains the sketch in flash memory, you don’t need to reload your sketch; it should start running automatically.
If things are working, you should see the LED on the breadboard blink once per second. If not, double-check your wiring to ensure that you have everything plugged together correctly on the breadboard and that the wires are plugged into the proper socket ports on the Arduino.