Designing Circuits - Covering the Basics - BeagleBone For Dummies (2015)

BeagleBone For Dummies (2015)

Part II

Covering the Basics

Chapter 5

Designing Circuits

In This Chapter

Getting to know electricity

Knowing the mathematical relationships for controlling electronic components

Working with circuit diagrams, color coding, and datasheets

This chapter gets you up to speed regarding the most basic principles of electricity so that you can understand what is happening on the circuits you build to interact with your BeagleBone. It introduces you to the fundamentals of electricity. We explain new techniques, rules, and/or new circuit components and their respective symbols throughout the remainder of the book where those concepts are most appropriate.

The study of the phenomena that deal with electricity is complex and vast. Deep down, things such as your phone, your computer, and your BeagleBone are nothing but a great deal of electric components manipulating electricity. You don’t need to understand how these components work to use those devices. Because you’ll make electronic circuits of your own that use the BeagleBone as support, however, you should understand some basic principles of electricity.

Introducing Electricity

Ah, electricity. Most people know what it is but have no idea what it really is. It’s been around since the dawn of the universe, and some sources say that the ancients actually believed it was some kind of magic. Thunder is a manifestation of electricity. Rubbing a pencil on your hair and then using it to attract pieces of paper is also electricity. When you press a few keys on your keyboard, what makes them show up on your screen? Again, electricity.

Electricity appears as a form of energy due to the existence of electrically charged particles (protons and electrons; see Figure 5-1) on the structure of an atom — the foundation of all matter.

Figure 5-1: The structure of an atom.

Voltage, current, and resistance

This energy can appear as a static accumulation of electrical charge — an electric potential or voltage — or as a dynamic flow of electrons — an electric current (see Figure 5-2).

Figure 5-2: Electric current on an atomic level.

An electric current is basically electrons bumping from atom to atom. This phenomenon happens only in some materials. The atoms that make up rubber, for example, are too posh to engage in this kind of behavior. Copper atoms, however, are party animals that get down on the dance floor for some bumping action with just the slightest motivation. Elements such as copper are defined as good conductors. They still need some motivation, though, some sort of energy to get them moving. That energy is known as voltage, and thus there must be a voltage source to provide that energy. In a sense, voltage is the force that pushes the electric current forward.

Generally, you don’t need to know any of this mumbo-jumbo about how voltage and current exists. Long story short, applying a voltage to a conductive material gets an electrical current flowing. You do need to know how voltage and current behave and how they can be manipulated, however.

The electrical wires mentioned in Chapter 1 usually have copper in them to get the current flowing. This copper is covered by a nonconductive material — an insulator — so that the copper where the current flows is protected.

The third concept you need to be aware of is electrical resistance. All electronic components exhibit some sort of resistance, which is a material’s capacity to resist electric current. For the current to get through this material, the current needs to be pushed through; it needs a voltage. What we call a voltage drop occurs at the resistive component.

In the next section, you find out about mathematizing these values by using three very simple equations, so it’s important to know the following:

· Voltage is measured in volts (V). A 1.5V AA battery, for example, is a 1.5V voltage source.

· Current is measured in amperes, or amps for short (A). The variable used to represent it, however, is often I (from current intensity).

· Resistance is measured in ohms (Ω) and is represented as R.

The symbol for resistance, Ω, is the uppercase Greek letter omega. One of the side effects of taking an electronics course is that you may end up knowing pretty much the entire Greek alphabet.

The water analogy

It’s much easier to understand electrical phenomena when you compare electric current with water flow. Imagine a system of plumbing pipes through which water flows. Some sort of force has to drive the water, such as a water pump, which is analogous to a voltage source. Also imagine that one section of the pipes has a much smaller diameter than the rest of the system. This section exhibits much higher resistance to the flow of water, so for the water current to pass at the same speed, more force is required.

A basic circuit example

The simple circuit shown in Figure 5-3 consists of a voltage source, a resistor, and a light-emitting diode (LED) connected with wires made of copper or any other conductive material.

Figure 5-3: A basic circuit that lights up an LED.

The voltage source — typically, a battery, such as the 9V battery in Figure 5-3 — supplies voltage to the circuit, which draws current from the battery. The relationship between the value of the battery and the current that’s drawn from it is called power, which is measured in watts (W).

All electronic circuits are … well, circuits: They’re always a closed loop. Current must always return to its source. That said, the voltage supplied by the battery drops along the circuit. Each component eats up a slice of those tasty 9V due to the resistance they exhibit, and the voltage dropped along the entire circuit must always equal the amount of voltage supplied.

Copper wires exhibit resistance, but that resistance is so ridiculously low that you can pretend it isn’t there at all for most applications. Consequently, you can assume that no voltage drop whatsoever occurs along the wires.

When a circuit has no resistive components, the voltage can’t drop before the current goes back into the battery again. This type of circuit is called a short-circuit and is often harmful to your circuit and its components. Don’t test this at home, but if you connect a battery’s positive (+) pole to its negative (-) pole with a wire, the battery would become really hot and lose all its energy very quickly. Such is the effect of a short-circuit.

Some components are very specific to the amount of voltage that they need to work, which is why it’s important to understand the concepts presented in this chapter. If you apply the 9V directly to the LED, the LED would blow up. Well, actually, just the filament inside would burn up, so the event really wouldn’t be a fun one. The LED would light up for a brief moment; then there would be some smoke and a nasty smell. On the other hand, if you apply less voltage to the LED than is specified, the light won’t reach its full brightness or may even not light at all. That’s why a resistor is close to it. If the LED needs 2V and draws about 0.03A to work properly, the circuit somehow needs to get rid of the extra 7V that come from the battery. Determining these values is what the next section is about.

The current along a closed loop is the same through all components. The voltage drop varies from component to component in the circuit.

Examining the Equations

This section describes the equations that govern the electrical phenomena that are introduced in this chapter. If math is generally a nightmare for you, do not worry; these are all pretty straightforward calculations.

Ohm’s Law

Ohm’s Law — the bread and butter of all things electric — describes the mathematical relationship among voltage, current, and resistance. Its name derives from the German physicist who discovered it in 1827: Georg Simon Ohm. The equation for Ohm’s Law is

The relationship is a simple one: The voltage drop on a resistive component is proportional to its resistance and the current flowing through it.

Suppose that you want to get a current of 2A through two different resistances: one with the value of 1 Ω and another with the value of 3 Ω. Because the second resistance has a higher value, it resists the current in a more significant way. Thus, you need more force to push the current through; you need a higher voltage. Here are the equations for those two situations:

Using algebra, you can rearrange the equation of Ohm’s Law to obtain any value provided that you know the other two.

To know how much current will go through a resistance when you know the voltage drop, you use this equation:

To find out the resistance you need to get a specific value for voltage drop and current, use this equation:

To figure out the value of the resistor that would get rid of the extra 7V (9V from the voltage source minus 2V that the LED needs) from the earlier example, the equation is this:

The equal sign with the wiggly dashes, ≈, means approximately equal to.

Power calculations

Power (P) is the amount of energy per second that your circuit consumes. It’s calculated as follows:

Naturally, you can rearrange this equation with algebra, leading to the following alternatives:

The power provided by a voltage source must always be used up in its entirety throughout the circuit. Mathematically, this means that for the circuit example, the power dissipated at the resistance plus the power dissipated at the LED equals the power supplied by the voltage source:

A voltage supply provides power; circuit components use it.

Joule’s Law

A few years after Ohm came up with his law relating resistance, current, and voltage, the English physicist James Prescott Joule decided to relate Ohm’s Law to the concept of power. Joule’s Law was derived as

and

Thus,

Joule’s Law can be rearranged as

By using any of the rearranged forms of Ohm’s Law and the equation for power calculation, you can find out different relationships. In the end, though, the values must always be the same:

and

Thus,

which can be rearranged as

Units of measurement

In the world of electronics, you often deal with very small numbers, such as currents of 0.0001A, or resistances of very high values, such as 1000000Ω.

For convenience, these numbers can be shortened with prefixes, as shown in Table 5-1.

Table 5-1 Units of Measurement

Prefix

Symbol

Multiplier

Tera

T

1012

Giga

G

109

Mega

M

106

Kilo

K

103

Mili

M

10-3

Micro

µ

10-6

Nano

N

10-9

Pico

P

10-12

The two values used in this section’s introduction could be written like so:

· 0.0001A = 100 µA

· 1000000 Ω = 1 MΩ

Working with Circuits

This section explains the different basic electrical components, as well as the rules and standards on how to represent them in an electric circuit.

Circuit diagrams

Circuit diagrams are collections of standardized symbols and sets of rules used throughout the world of electronics to represent electronic circuits. Figure 5-3, earlier in this chapter, shows an example of a circuit diagram. This section explains the symbols in the diagrams.

DC Voltage source/DC power supply/battery

The DC voltage source (which can also be called the DC power supply or battery) powers up your circuit, feeding it the current that it needs for operation. The required voltage depends on the application. An electric DC motor usually requires a larger amount of voltage than lighting an LED, for example. The symbol for the DC voltage source is shown in Figure 5-4.

Figure 5-4: DC Voltage source.

Resistor

The resistor is the most basic, most common electronic component of simple electronic circuits. It’s there to control the voltage and current supplied to the components that use the energy to do something, such as lighting up. Figure 5-5 shows the symbol for a resistor.

Figure 5-5: Resistor.

Diodes

Diodes are components used to force the current to flow in only one direction, which is why the circuit symbol displays an arrow, as shown on the left side of Figure 5-6. An LED is simply a diode that also happens to light up. The circuit symbols for the two are very similar except for the two arrows on an LED, as shown on the right side of Figure 5-6.

Figure 5-6: The symbol on the left is for a diode. On the right is the symbol for an LED.

Unlike resistors, diodes have polarities, and the direction of current flow is always from the anode (+) pin to the cathode (-) pin. Therefore, the tip of the arrow is the (-) side of the diode. Figure 5-7 illustrates diode polarity on an LED.

Figure 5-7: LED polarity.

If you slightly change the circuit in Figure 5-3 by flipping the LED around as shown in Figure 5-8, the circuit wouldn’t work. The LED wouldn’t light up because it would be blocking current flow. Remember that the current supplied by the battery goes from its (+) to its (-) pin. Be careful whenever you work with components that have polarities!

Figure 5-8: A nonfunctioning circuit, with its LED orientation reversed.

The alternative configuration shown in Figure 5-9 — in which the battery has been inverted — does work.

Nothing is wrong with the configuration in Figure 5-9 as far as science is concerned, but having the power source’s (+) pin pointing upward has been known as a good practice for organization for a very long time. Generally, you want your circuit’s current to go around in a clockwise fashion.

Figure 5-9: A functioning circuit, in which the LED and the battery orientations have been reversed.

Switches

The example circuit has a somewhat significant issue: Unless you unplug the battery, the LED will always be lit until the battery discharges. A very simple, yet quite useful way to add control to your circuit is to use switches, as shown in Figure 5-10.

Figure 5-10: Adding a switch to the circuit.

When you use a switch, you either make a metallic connection (enabling current to go through) or you break one. In the example circuit, the switch functions as an on/off switch.

When it comes to drawing a circuit diagram, the term switch refers to pushbuttons as well as actual switches.

Capacitors

We state earlier in this chapter that resistors are the most common components of electronic circuits. Capacitors run a close second. Capacitors are electronic components that can store energy electrostatically. The mathematics and possible applications of this capability go beyond the scope of this book, but because capacitors are such common components of circuits, we needed to at least expose you to its symbol, shown in Figure 5-11. It’s just a matter of time until you meet a schematic that features this symbol.

Figure 5-11: The two equivalent circuit symbols for a capacitor.

Capacitors come in two main types: ceramic and electrolytic (see Figure 5-12). An electrolytic capacitor exhibits polarity in the same way that diodes do. Generally, you want to connect the (+) pin to the side that current is coming from.

Figure 5-12: Ceramic capacitor (left) and electrolytic capacitor (right).

To know which pin is the anode (+) and which pin is the cathode (-), you have two options:

· The (-) pin should always be the shorter leg. One of the legs may have been trimmed, however, so this feature isn’t the most reliable determinant.

· The (-) pin is the one below the band white stripe as shown in Figure 5-13.

Figure 5-13: The cathode (-) on an electrolytic capacitor.

The capacitance of a capacitor is measured in farads, and the most common values are on the order of µF (microfarads), nF (nanofarads), and pF (picofarads).

Integrated circuit (IC) chips

You can combine electrical components in a million ways to achieve different results. At their core, your calculator, your car, your computer, and your BeagleBone all boil down to the same thing: a great many transistors along with some resistors, capacitors, and whatever other basic components they need. In that sense, integrated circuit (IC) chips appeared on the scene to simplify matters. An integrated circuit is a fully functioning circuit inside a small plate of (normally) silicon. It can feature up to several billion transistors along with other components while being the size of your fingernail. Figure 5-14 shows just one example.

The black squares on your BeagleBone are IC chips. Each one is responsible for a different task on the board.

Color coding

Color coding is an important technique in building an electronic circuit, especially the further you progress in terms of complexity. As you may have noticed, wires come in different colors, albeit there is absolutely no difference among them in purely electric terms. The colors exist to help you with organizing your circuit, which is really, really handy if the wiring on it is abundant. Also, if you’re working on a project with some other person, establishing a code can greatly help each of you understand what each person has done without much of a headache.


Transistors

The transistor is a tiny electric component featuring three pins rather than two. The voltage between a pair of these pins controls the current flowing through the other two. It’s funny that this simple capability makes it the heart of all modern electronics.

The first computer created was the size of a football stadium. The development of the transistor made it possible to shrink computers to the size of your desk or even your palm.

To be honest, you most likely won’t ever feature a transistor on the circuits you build, but that’s because someone already did all the hard work for you. The BeagleBone is made up of billions of transistors. Even though you don’t really need to know about the transistor to carry on using this book, we think it’s important that you at least know what it is. The things we talk about in this book wouldn’t even exist if not for the transistor.


Figure 5-14: A dual full-bridge motor driver IC (model number MTS2916A-HGC1).

You can use whatever color code you want. Following is a common standard:

· Red for positive power supply (+)

· Black/white for circuit ground (-)

· A different color for every part of your circuit

You can call a part of a circuit whatever you want and organize accordingly. Here are a few examples:

· All wires that come directly from a BeagleBone pin are blue; everything else (apart from the power supply) is green.

· The wires that deal with the resistive network of the circuit are yellow, whereas those related to the left DC motor are green, and those related to the right DC motor are white.

· The wires that come into the Bluetooth device are blue; those that come out of the device are green; all wires related to the LCD display are yellow.

For very simple circuits, this technique doesn’t make much of a difference, but it’s a good idea for you to start having it in mind. When you reach a higher degree of complexity, you’ll be able to work with a procedure with which you’re already comfortable. Organization, communication with a partner, and debugging become much simpler.

Resistor color charts

The resistance of a resistor is determined by the color bands that appear along it. The bands are read from left to right. What is left, though, and what is right? In Figure 5-15, the three bands on the right are separated by gaps of equal size, whereas the separation to the fourth band is larger. This arrangement means that you should flip your resistor. The order of the bands in Figure 5-15 is Red Red Red Gold — not Gold Red Red Red!

Figure 5-15: A resistor.

The first two bands represent the numbers of the first two digits, whereas the third represents the number of zeros after those digits — its multiplier. The fourth band is the tolerance of this value.

Table 5-2 provides an explanation of the color codes.

In Figure 5-15, in which the code is Red Red Red Gold, the value is determined as follows:

The tolerance means that the value isn’t precisely 2200 Ω, but somewhere between 2200 × (1+0.05) = 2310 Ω and 2200 × (1-0.05) = 2090 Ω.

Keep yourself organized! As you may have noticed, finding out the value of a resistor can be somewhat tedious. Keeping different resistors separated and labeled may save you some time. The same applies to other components, such as capacitors.

Because resistor values are based on a color code, naturally, it’s hard to have every single resistance value available. If you use Ohm’s Law for some application and realize you need a resistor value that doesn’t exist, using the closest existing value shouldn’t be an issue. If your calculations lead you to a resistance value of 233 Ω, a 220 Ω or 270 Ω resistor should be okay — the 270 Ω value is preferred to avoid feeding more current than you should; values other than these may not work for your circuit.

If you find yourself looking at a circuit diagram that needs a specific value for a resistor that you don’t have at the moment, you have two options:

· Make a trip to your closest electronics store.

· Combine the resistors that you have handy.

If you have to exercise the option of combining resistors, you can connect them in two different ways so that their equivalent resistance, which is labeled Req, will either increase (series connection) or decrease (parallel connection), as shown in Figure 5-16 and Figure 5-17.

Figure 5-16: Connecting resistors in series.

Figure 5-17: Connecting resistors in parallel.

You can see these techniques at work in the following examples:

· Series connection: A 270 Ω resistor connected in series with a 220 Ω is exactly the same as if you’d used a single 490 Ω resistor.

· Parallel connection: A 1200 Ω resistor connected in parallel with a 800 Ω is exactly the same as if you’d used a single 720 Ω resistor.

Datasheets

A datasheet is basically — you guessed it! — a sheet containing data about a certain electrical component.

Datasheets are particularly useful when you use an IC because you don’t need to know about the circuit inside it. Circuits for which you don’t need to know what is going on inside is what electronic enthusiasts normally call a black box. You simply need to know what goes in (the input pins) and what comes out (the output pins), which you do by consulting its datasheet. Consider Figure 5-18.

Figure 5-18: An ATMEGA328P-PU IC chip.

The simplest way to access a component’s datasheet is to do an online search for something along the lines of “ATMEGA328P-PU datasheet,” where ATMEGA328P-PU is the model number. Some PDF files should be among the results of the search; open one to access a great deal of information about your chip.

A datasheet needs to be extremely detailed, featuring things like the circuit inside the IC chip and the highest level of humidity that the device can handle. Generally, you don’t need to worry about these details unless you’re working on some high-end, very specific project. Often, you need to be concerned only about the page that contains the pinout: the information about the IC’s pins.

It’s important to note that we’ve merely scratched the surface of the theory of circuit design. For a more detailed approach, feel free to consult Electronics For Dummies, by Gordon McComb and Earl Boysen (John Wiley & Sons, Inc.).