Make - Electronics 3rd Edition PDF
Make - Electronics 3rd Edition PDF
Make - Electronics 3rd Edition PDF
Make: Electronics
Learning by Discovery
Charles Platt
with photographs and illustrations by the author
Print History:
December 2009: First Edition.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Many of the designations used by manufacturers and
sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly
Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility
for errors or omissions, or for damages resulting from the use of the information contained herein.
ISBN: 978-0-596-15374-8
[TI]
For my dearest Erico
Contents
Preface.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1. Experiencing Electricity.. . . . . . . . . . . . . . . . . . . . . 1
Shopping List: Experiments 1 Through 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Experiment 1: Taste the Power!.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Experiment 2: Let’s Abuse a Battery!.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Experiment 3: Your First Circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Experiment 4: Varying the Voltage.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Experiment 5: Let’s Make a Battery.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
vii
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
viii Contents
Preface
Learning by Discovery
Most introductory guides begin with definitions and facts, and gradually get
to the point where you can follow instructions to build a simple circuit.
This book works the other way around. I want you to start putting components
together right away. After you see what happens, you’ll figure out what’s go-
ing on. I believe this process of learning by discovery creates a more powerful
and lasting experience.
ix
How Hard Will It Be?
Figure P-1. Learning by discovery allows you to start building simple circuits right away,
using a handful of cheap components, a few batteries, and some alligator clips.
x Preface
Fundamentals
Fundamentals
Mail-ordering components and tools
Here are the primary mail-order sources that I use myself online:
http://www.radioshack.com
RadioShack, a.k.a. The Shack. For tools and components. Not always the
cheapest, but the site is easy and convenient, and some of the tools are
exactly what you need.
http://www.mouser.com
Mouser Electronics.
http://www.digikey.com
Digi-Key Corporation.
Preface xi
Fundamentals
http://www.newark.com
Newark.
Mouser, Digi-Key, and Newark are all good sources for components, usually
requiring no minimum quantities.
http://www.allelectronics.com
All Electronics Corporation. A narrower range of components, but specifi-
cally aimed at the hobbyist, with kits available.
http://www.ebay.com
You can find surplus parts and bargains here, but you may have to try
several eBay Stores to get what you want. Those based in Hong Kong are
often very cheap, and I’ve found that they are reliable.
http://www.mcmaster.com
McMaster-Carr. Especially useful for high-quality tools.
Lowe’s and Home Depot also allow you to shop online.
Figure P-2. You’ll find no shortage of parts, tools, kits, and gadgets online.
xii Preface
Safari® Books Online
Companion Kits
Maker Shed (www.makershed.com) offers a
number of Make: Electronics companion kits,
both toolkits and bundles of the various
components used in the book’s experi-
ments. This is a simple, convenient, and cost-effective way of getting all the
tools and materials you need to do the projects in this book.
Preface xiii
Experiencing Electricity 1
I want you to get a taste for electricity—literally!—in the first experiment. This In this chapter
first chapter of the book will show you:
Shopping List: Experiments 1 Through 5
• How to understand and measure electricity and resistance Experiment 1: Taste the Power!
• How to handle and connect components without overloading, damaging, Experiment 2: Let’s Abuse a Battery!
or destroying them Experiment 3: Your First Circuit
Even if you have some prior knowledge of electronics, you should try these Experiment 4: Varying the Voltage
experiments before you venture on to the rest of the book. Experiment 5: Let’s Make a Battery
Tools
Small pliers
RadioShack Kronus 4.5-inch, part number 64-2953 or Xcelite 4-inch mini
long-nose pliers, model L4G.
Or similar. See Figures 1-1 through 1-3. Look for these tools in hardware
stores and the sources listed in the preface. The brand is unimportant.
After you use them for a while, you’ll develop your own preferences. In
particular, you have to decide whether you like spring-loaded handles. If
you decide you don’t, you’ll need a second pair of pliers to pull the springs
out of the first.
1
Shopping List: Experiments 1 Through 5
Wire cutters
RadioShack Kronus 4.5-inch, part number 64-2951, or Stanley 7-inch
model 84-108.
Or similar. Use them for cutting copper wire, not harder metals (Figure 1-4).
Figure 1-1. Generic long-nosed Figure 1-2. Longer-nosed pliers: Figure 1-3. Sharp-pointed pliers Figure 1-4. Wire cutters, some-
pliers are your most fundamen- these are useful for reaching into are designed for making jewelry, times known as side cutters, are
tal tool for gripping, bending, tiny spaces. but are also useful for grabbing essential.
and picking things up after you tiny components.
drop them.
Multimeter
Extech model EX410 or BK Precision model 2704-B or Amprobe model
5XP-A.
Or similar. Because electricity is invisible, we need a tool to visualize the
pressure and flow, and a meter is the only way. A cheap meter will be suf-
ficient for your initial experiments. If you buy online, try to check customer
reviews, because reliability may be a problem for cheap meters. You can
shop around for retailers offering the best price. Don’t forget to search on
eBay.
The meter must be digital—don’t get the old-fashioned analog kind with
a needle that moves across a set of printed scales. This book assumes that
you are looking at a digital display.
I suggest that you do not buy an autoranging meter. “Autoranging” sounds
useful—for example, when you want to check a 9-volt battery, the meter
figures out for itself that you are not trying to measure hundreds of volts,
nor fractions of a volt. The trouble is that this can trick you into making
errors. What if the battery is almost dead? Then you may be measuring
a fraction of a volt without realizing it. The only indication will be an eas-
ily overlooked “m” for “millivolts” beside the large numerals of the meter
display.
Download at WoweBook.com
2 Chapter 1
Shopping List: Experiments 1 Through 5
On a manual-ranging meter, you select the range, and if the source that
you are measuring is outside of that range, the meter tells you that you
made an error. I prefer this. I also get impatient with the time it takes for
the autoranging feature to figure out the appropriate range each time I
make a measurement. But it’s a matter of personal preference. See Figures
1-5 through 1-7 for some examples of multimeters.
Figure 1-5. You can see by the wear and Figure 1-6. Mid-priced RadioShack meter, Figure 1-7. An autoranging meter from
tear that this is my own favorite meter. which has the basic features; however, Extech offers basic functions, plus a tem-
It has all the necessary basic features the dual purpose for each dial position, perature probe, which may be useful to
and can also measure capacitance (the selected with the SELECT button, may be check whether components such as power
F section, for Farads). It can also check confusing. This is an autoranging meter. supplies are running unduly hot.
transistors. You have to choose the ranges
manually.
Supplies
Batteries
9-volt battery. Quantity: 1.
AA batteries, 1.5 volts each. Quantity: 6.
The batteries should be disposable alkaline, the cheapest available, be-
cause we may destroy some of them. You should absolutely not use re-
chargeable batteries in Experiments 1 and 2.
Figure 1-8. Snap connector for a 9-volt
Battery holders and connectors battery.
Snap connector for 9-volt battery, with wires attached (Figure 1-8).
Quantity: 1. RadioShack part number 270-325 or similar. Any snap con-
nector that has wires attached will do.
Battery holder for single AA cell, with wires attached (Figure 1-9). Quan-
tity: 1. RadioShack part number 270-401 or Mouser.com catalog number
12BH410-GR, or similar; any single-battery holder that has thin wires at-
tached will do.
Figure 1-9. Single AA-sized battery carrier
with wires.
Experiencing Electricity 3
Shopping List: Experiments 1 Through 5
Battery holder for four AA cells, with wires attached (Figure 1-10). Quan-
tity: 1. All Electronics catalog number BH-342 or RadioShack part 270-391
or similar.
Alligator clips
Vinyl-insulated. Quantity: at least 6. All Electronics catalog number ALG-28
or RadioShack part number 270-1545 or similar (Figure 1-11).
Components
Figure 1-10. Battery carrier for four AA
You may not know what some of these items are, or what they do. Just look
cells, to be installed in series, delivering 6 for the part numbers and descriptions, and match them with the photographs
volts. shown here. Very quickly, in the learning by discovery process, all will be revealed.
Fuses
Automotive-style, mini-blade type, 3 amps. Quantity: 3. RadioShack part
number 270-1089, or Bussmann part ATM-3, available from automotive
parts suppliers such as AutoZone (Figure 1-12).
Or similar. A blade-type fuse is easier to grip with alligator clips than a
round cartridge fuse.
Figure 1-13. Potentiometers come in many Figure 1-14. Typical 5-mm diameter light- Figure 1-15. Jumbo-sized LED (1 cm
shapes and sizes, with different lengths of emitting diode (LED). diameter) is not necessarily brighter or
shafts intended for different types of knobs. more expensive. For most of the experi-
For our purposes, any style will do, but the ments in this book, buy whatever LEDs
larger-sized ones are easier to play with. you like the look of.
4 Chapter 1
Experiment 1: Taste the Power!
Tools
Setting up your meter
Check the instructions that came with the meter to find out whether you have
to install a battery in it, or whether a battery is preinstalled. Figure 1-16. Step 1 in the process of learn-
ing by discovery: the 9-volt tongue test.
Most meters have removable wires, known as leads (pronounced “leeds”).
Most meters also have three sockets on the front, the leftmost one usually be-
ing reserved to measure high electrical currents (flows of electricity). We can
ignore that one for now.
The leads will probably be black and red. The black wire plugs into a socket
labeled “COM” or “Common.” Plug the red one into the socket labeled “V” or
“volts.” See Figures 1-17 through 1-20.
The other ends of the leads terminate in metal spikes known as probes, which
you will be touching to components when you want to make electrical mea-
surements. The probes detect electricity; they don’t emit it in significant quan-
tities. Therefore, they cannot hurt you unless you poke yourself with their
sharp ends.
If your meter doesn’t do autoranging, each position on the dial will have a
number beside it. This number means “no higher than.” For instance if you
want to check a 6-volt battery, and one position on the voltage section of the Figure 1-17. The black lead plugs into
dial is numbered 2 and the next position is numbered 20, position 2 means the Common (COM) socket, and the
“no higher than 2 volts.” You have to go to the next position, which means “no red lead plugs into the red socket that’s
higher than 20 volts.” almost always on the righthand side of a
multimeter.
Experiencing Electricity 5
Experiment 1: Taste the Power!
If you make a mistake and try to measure something inappropriate, the meter
will show you an error message such as “E” or “L.” Turn the dial and try again.
Fundamentals
Ohms
We measure distance in miles or kilometers, weight in pounds A material that has very high resistance to electricity is
or kilograms, temperature in Fahrenheit or Centigrade—and known as an insulator. Most plastics, including the colored
electrical resistance in ohms. The ohm is an international unit. sheaths around wires, are insulators.
The Greek omega symbol (Ω) is used to indicate ohms, as A material with very low resistance is a conductor. Metals
shown in Figures 1-21 and 1-22. Letter K (or alternatively, such as copper, aluminum, silver, and gold are excellent
KΩ) means a kilohm, which is 1,000 ohms. Letter M (or MΩ) conductors.
means a megohm, which is 1,000,000 ohms.
6 Chapter 1
Experiment 1: Taste the Power!
Procedure
We’re going to use the meter to discover the electrical resistance of your
tongue. First, set your meter to measure resistance. If it has autoranging, look
to see whether it is displaying a K, meaning kilohms, or M, meaning megohms.
If you have to set the range manually, begin with no less than 100,000 ohms
(100K). See Figures 1-23 through 1-25.
Touch the probes to your tongue, about an inch apart. Note the reading,
which should be around 50K. Now put aside the probes, stick out your tongue,
and use a tissue to dry it very carefully and thoroughly. Without allowing your
tongue to become moist again, repeat the test, and the reading should be
higher. Finally, press the probes against the skin of your hand or arm: you may Figure 1-23
get no reading at all, until you moisten your skin.
When your skin is moist (for instance, if you perspire), its electrical resistance de-
creases. This principle is used in lie detectors, because someone who knowingly tells
a lie, under conditions of stress, tends to perspire.
Experiencing Electricity 7
Experiment 1: Taste the Power!
Background
The man who discovered resistance
Georg Simon Ohm, pictured in Figure
1-27, was born in Bavaria in 1787 and
worked in obscurity for much of his
life, studying the nature of electricity
using metal wire that he had to make
for himself (you couldn’t truck on
down to Home Depot for a spool of
hookup wire back in the early 1800s).
Despite his limited resources and in-
adequate mathematical abilities, Ohm
was able to demonstrate in 1827 that
the electrical resistance of a conduc-
tor such as copper varied in propor-
tion with its area of cross-section,
and the current flowing through it is
proportional to the voltage applied to
it, as long as temperature is held con-
stant. Fourteen years later, the Royal Figure 1-27. Georg Simon Ohm, after
Society in London finally recognized being honored for his pioneering work,
the significance of his contribution most of which he pursued in relative
and awarded him the Copley Medal. obscurity.
Figure 1-28. Modifying the tongue test to
show that a shorter distance, with lower Today, his discovery is known as
resistance, allows greater flow of electric- Ohm’s Law.
ity, and a bigger zap.
Further Investigation
Attach the snap-on terminal cap (shown earlier in Figure 1-8) to the 9-volt bat-
tery. Take the two wires that are attached to the cap and hold them so that the
bare ends are just a few millimeters apart. Touch them to your tongue. Now
separate the ends of the wires by a couple of inches, and touch them to your
tongue again. (See Figure 1-28.) Notice any difference?
Use your meter to measure the electrical resistance of your tongue, this time
varying the distance between the two probes. When electricity travels through
a shorter distance, it encounters less total resistance. As a result, the current
(the flow of electricity per second) increases. You can try a similar experiment
on your arm, as shown in Figure 1-29.
Use your meter to test the electrical resistance of water. Dissolve some salt in
Figure 1-29. Moisten your skin before trying the water, and test it again. Now try measuring the resistance of distilled water
to measure its resistance. You should find (in a clean glass).
that the resistance goes up as you move
the meter probes farther apart. The resis- The world around you is full of materials that conduct electricity with varying
tance is proportional to the distance. amounts of resistance.
8 Chapter 1
Experiment 2: Let’s Abuse a Battery!
Short Circuits
Short circuits can be dangerous. Do not short out a power outlet in your home:
there’ll be a loud bang, a bright flash, and the wire or tool that you use will be par- Figure 1-30. Anyone who has dropped an
tially melted, while flying particles of melted metal can burn you or blind you. adjustable wrench across the bare termi-
nals of a car battery will tell you that short
If you short out a car battery, the flow of current is so huge that the battery might circuits can be dramatic at a “mere” 12
even explode, drenching you in acid (Figure 1-30). volts, if the battery is big enough.
Lithium batteries are also dangerous. Never short-circuit a lithium battery: it can
catch fire and burn you (Figure 1-31).
Use only an alkaline battery in this experiment, and only a single AA cell (Figure
1-32). You should also wear safety glasses in case you happen to have a defective
battery.
Procedure
Use an alkaline battery. Do not use any kind of rechargeable battery.
Put the battery into a battery holder that’s designed for a single battery and
has two thin insulated wires emerging from it, as shown in Figure 1-32. Do not
use any other kind of battery holder.
Use an alligator clip to connect the bare ends of the wires, as shown in Figure
1-32. There will be no spark, because you are using only 1.5 volts. Wait one
minute, and you’ll find that the wires are getting hot. Wait another minute, and Figure 1-32. Shorting out an alkaline bat-
the battery, too, will be hot. tery can be safe if you follow the directions
precisely. Even so, the battery is liable to
become too hot to touch comfortably.
Don’t try this with any type of recharge-
able battery.
Experiencing Electricity 9
Experiment 2: Let’s Abuse a Battery!
The heat is caused by electricity flowing through the wires and through the
electrolyte (the conductive fluid) inside the battery. If you’ve ever used a hand
pump to force air into a bicycle tire, you know that the pump gets warm. Elec-
tricity behaves in much the same way. You can imagine the electricity being
composed of particles (electrons) that make the wire hot as they push through
it. This isn’t a perfect analogy, but it’s close enough for our purposes.
Water level Chemical reactions inside the battery create electrical pressure. The correct
name for this pressure is voltage, which is measured in volts and is named after
Alessandro Volta, an electrical pioneer.
Voltage Going back to the water analogy: the height of the water in a tank is propor-
(pressure) Amperage
(flow)
tionate to the pressure of the water, and comparable to voltage. Figure 1-33
may help you to visualize this.
But volts are only half of the story. When electrons flow through a wire, the
Resistance
flow is known as amperage, named after yet another electrical pioneer, André-
Marie Ampère. The flow is also generally known as current. It’s the current—
Figure 1-33. Think of voltage as pressure,
the amperage—that generates the heat.
and amperes as flow.
Background
Why didn’t your tongue get hot?
When you touched the 9-volt battery to your tongue, you felt a tingle, but no
perceptible heat. When you shorted out a battery, you generated a noticeable
amount of heat, even though you used a lower voltage. How can we explain
this?
The electrical resistance of your tongue is very high, which reduces the flow of
electrons. The resistance of a wire is very low, so if there’s only a wire connect-
ing the two terminals of the battery, more current will pass through it, creating
more heat. If all other factors remain constant:
• Lower resistance allows more current to flow (Figure 1-34).
• The heat generated by electricity is proportional to the amount of electric-
ity (the current) that flows.
Here are some other basic concepts:
• The flow of electricity per second is measured in amperes, or amps.
• The pressure of electricity causes the flow, measured in volts.
• The resistance to the flow is measured in ohms.
Figure 1-34. Larger resistance results in • A higher resistance restricts the current.
smaller flow—but if you increase the pres- • A higher voltage overcomes resistance and increases the current.
sure, it may overcome the resistance and
increase the flow.
If you’re wondering exactly how much current flows between the terminals
of a battery when you short it out, that’s a difficult question to answer. If you
try to use your multimeter to measure it, you’re liable to blow the fuse inside
the meter. Still, you can use your very own 3-amp fuse, which we can sacrifice
because it didn’t cost very much.
10 Chapter 1
Experiment 2: Let’s Abuse a Battery!
First inspect the fuse very carefully, using a magnifying glass if you have one.
You should see a tiny S-shape in the transparent window at the center of the
fuse. That S is a thin section of metal that melts easily.
Remove the battery that you short-circuited. It is no longer useful for anything,
and should be recycled if possible. Put a fresh battery into the battery carrier,
connect the fuse as shown in Figure 1-35, and take another look. You should
see a break in the center of the S shape, where the metal melted almost in-
stantly. Figure 1-36 shows the fuse before you connected it, and Figure 1-37
depicts a blown fuse. This is how a fuse works: it melts to protect the rest of
the circuit. That tiny break inside the fuse stops any more current from flowing. Figure 1-35. When you attach both wires to
the fuse, the little S-shaped element inside
will melt almost instantly.
Fundamentals
Volt basics
Electrical pressure is measured in volts. The volt is an international unit. A millivolt
is 1/1,000 of a volt.
Experiencing Electricity 11
Experiment 2: Let’s Abuse a Battery!
Background Fundamentals
Inventor of the battery Direct and alternating current
Alessandro Volta (Figure 1-38) was The flow of current that you get from a battery is known as direct current, or DC.
born in Italy in 1745, long before Like the flow of water from a faucet, it is a steady stream, in one direction.
science was broken up into spe-
The flow of current that you get from the “hot” wire in a power outlet in your
cialties. After studying chemistry
home is very different. It changes from positive to negative 50 times each
(he discovered methane in 1776),
second (in Great Britain and some other nations, 60 times per second). This is
he became a professor of physics
known as alternating current, or AC, which is more like the pulsatile flow you get
and became interested in the so-
from a power washer.
called galvanic response, whereby
a frog’s leg will twitch in response Alternating current is essential for some purposes, such as cranking up voltage
to a jolt of static electricity. so that electricity can be distributed over long distances. AC is also useful in
motors and domestic appliances. The parts of an American power outlet are
Using a wine glass full of salt
shown in Figure 1-39. A few other nations, such as Japan, also use American-
water, Volta demonstrated that the
style outlets.
chemical reaction between two
electrodes, one made of copper, For most of this book I’m going to be talking about DC, for two reasons: first,
the other of zinc, will generate a most simple electronic circuits are powered with DC, and second, the way it
steady electric current. In 1800, he behaves is much easier to understand.
refined his apparatus by stacking
plates of copper and zinc, sepa- I won’t bother to mention repeatedly that I’m dealing with DC. Just assume that
rated by cardboard soaked in salt everything is DC unless otherwise noted.
and water. This “voltaic pile” was
the first electric battery. B
12 Chapter 1
Experiment 3: Your First Circuit
Setup
It’s time to get acquainted with the most fundamental component we’ll be us-
ing in electronic circuits: the humble resistor. As its name implies, it resists the
Figure 1-40. Andre-Marie Ampere
flow of electricity. As you might expect, the value is measured in ohms. found that an electric current run-
ning through a wire creates a mag-
If you bought a bargain-basement assortment package of resistors, you netic field around it. He used this
may find nothing that tells you their values. That’s OK; we can find out easily principle to make the first reliable
enough. In fact, even if they are clearly labeled, I want you to check their values measurements of what came to be
yourself. You can do it in two ways: known as amperage.
Experiencing Electricity 13
Experiment 3: Your First Circuit
Fundamentals
Decoding resistors
Some resistors have their value clearly stated on them in microscopic print that
you can read with a magnifying glass. Most, however, are color-coded with
stripes. The code works like this: first, ignore the color of the body of the resis-
tor. Second, look for a silver or gold stripe. If you find it, turn the resistor so that
the stripe is on the righthand side. Silver means that the value of the resistor
is accurate within 10%, while gold means that the value is accurate within 5%.
If you don’t find a silver or gold stripe, turn the resistor so that the stripes are
clustered at the left end. You should now find yourself looking at three colored
stripes on the left. Some resistors have more stripes, but we’ll deal with those in
a moment. See Figures 1-41 and 1-42.
Figure 1-41. Some modern resistors have Figure 1-42. From top to bottom, these
their values printed on them, although resistor values are 56,000 ohms (56K),
you may need a magnifier to read them. 5,600 ohms (5.6K), and 560 ohms. The
This 15K resistor is less than half an size tells you how much power the resis-
inch long. tor can handle; it has nothing to do with
the resistance. The smaller components
are rated at 1/4 watt; the larger one in
the center can handle 1 watt of power.
Starting from the left, the first and The third stripe has a different mean-
second stripes are coded according to ing: It tells you how many zeros to
this table: add, like this:
14 Chapter 1
Experiment 3: Your First Circuit
Fundamentals
Decoding resistors (continued)
Note that the color-coding is consistent, so that green, for instance, means
either a value of 5 (for the first two stripes) or 5 zeros (for the third stripe). Also,
the sequence of colors is the same as their sequence in a rainbow.
So, a resistor colored brown-red-green would have a value of 1-2 and five zeros,
making 1,200,000 ohms, or 1.2MΩ. A resistor colored orange-orange-orange
would have a value of 3-3 and three zeros, making 33,000 ohms, or 33KΩ. A
resistor colored brown-black-red would have a value of 1-0 and two additional
zeros, or 1KΩ. Figure 1-43 shows some other examples.
Figure 1-43. To read the value of a resistor, first turn it so that the silver or gold stripe
is on the right, or the other stripes are clustered on the left. From top to bottom:
The first resistor has a value of 1-2 and five zeros, or 1,200,000, which is 1.2MΩ. The
second is 5-6 and one zero, or 560Ω. The third is 4-7 and two zeros, or 4,700, which is
4.7KΩ. The last is 6-5-1 and two zeros, or 65,100Ω, which is 65.1KΩ.
If you run across a resistor with four stripes instead of three, the first three
stripes are digits and the fourth stripe is the number of zeros. The third numeric
stripe allows the resistor to be calibrated to a finer tolerance.
Confusing? Absolutely. That’s why it’s easier to use your meter to check the values.
Just be aware that the meter reading may be slightly different from the claimed
value of the resistor. This can happen because your meter isn’t absolutely accu-
rate, or because the resistor is not absolutely accurate, or both. As long as you’re
within 5% of the claimed value, it doesn’t matter for our purposes.
Experiencing Electricity 15
Experiment 3: Your First Circuit
Lighting an LED
Now take a look at one of your LEDs. An old-fashioned lightbulb wastes a lot
of power by converting it into heat. LEDs are much smarter: they convert al-
most all their power into light, and they last almost indefinitely—as long as
you treat them right!
An LED is quite fussy about the amount of power it gets, and the way it gets it.
Always follow these rules:
• The longer wire protruding from the LED must receive a more positive volt-
age than the shorter wire.
• The voltage difference between the long wire and the short wire must not
exceed the limit stated by the manufacturer.
• The current passing through the LED must not exceed the limit stated by
the manufacturer.
What happens if you break these rules? Well, we’re going to find out!
Make sure you are using fresh batteries. You can check by setting your multi-
meter to measure volts DC, and touching the probes to the terminals of each
battery. You should find that each of them generates a pressure of at least
1.5 volts. If they read slightly higher than this, it’s normal. A battery starts out
above its rated voltage, and delivers progressively less as you use it. Batteries
also lose some voltage while they are sitting on the shelf doing nothing.
Load your battery holder (taking care that the batteries are the right way
around, with the negative ends pressing against the springs in the carrier).
Use your meter to check the voltage on the wires coming out of the battery
carrier. You should have at least 6 volts.
Now select a 2KΩ resistor. Remember, “2KΩ” means “2,000 ohms.” If it has col-
ored stripes, they should be red-black-red, meaning 2-0 and two more zeros.
Because 2.2K resistors are more common than 2K resistors, you can substitute
one of them if necessary. It will be colored red-red-red.
Wire it into the circuit as shown in Figures 1-44 and 1-45, making the connec-
tions with alligator clips. You should see the LED glow very dimly.
16 Chapter 1
Experiment 3: Your First Circuit
Now swap out your 2K resistor and substitute a 1K resistor, which will have
brown-black-red stripes, meaning 1-0 and two more zeros. The LED should
glow more brightly.
Swap out the 1K resistor and substitute a 470Ω resistor, which will have yel-
low-violet-brown stripes, meaning 4-7 and one more zero. The LED should be
brighter still.
This may seem very elementary, but it makes an important point. The resistor
blocks a percentage of the voltage in the circuit. Think of it as being like a kink
or constriction in a flexible hose. A higher-value resistor blocks more voltage,
leaving less for the LED. Figure 1-44. The setup for Experiment 3,
showing resistors of 470Ω, 1KΩ, and 2KΩ.
LED Apply alligator clips where shown, to make
a secure contact, and try each of the resis-
tors one at a time at the same point in the
circuit, while watching the LED.
On your battery
IP
6v Battery Pack
Figure 1-45. Here’s how it actually looks, using a large LED. If you start with the highest
value resistor, the LED will glow very dimly as you complete the circuit. The resistor drops
most of the voltage, leaving the LED with insufficient current to make it shine brightly.
Experiencing Electricity 17
Experiment 4: Varying the Voltage
18 Chapter 1
Experiment 4: Varying the Voltage
possesses some resistance (a total of 2K in this instance), and as you turn the
shaft of the potentiometer, a wiper rubs against the resistance, giving you a
shortcut to any point from the center terminal. Ohms
You can try to put it back together, but if it doesn’t work, use your backup
potentiometer instead.
To test your potentiometer, set your meter to measure resistance (ohms) and
touch the probes while turning the potentiometer shaft to and fro, as shown
in Figure 1-49.
On your battery
IP
6v Battery Pack
Figure 1-50. The setup for Experiment 4. Rotating the shaft of the 2K potentiometer varies Figure 1-51. The LED in this photo is dark
its resistance from 0 to 2,000Ω. This resistance protects the LED from the full 6 volts of because I turned the potentiometer up
the battery. just a little bit too far.
Experiencing Electricity 19
Experiment 4: Varying the Voltage
While the batteries are connected to the circuit, set your meter to measure volts
DC as shown in Figures 1-52 through 1-54. Now touch the probes either side of
the LED. Try to hold the probes in place while you turn the potentiometer up
a little, and down a little. You should see the voltage pressure around the LED
changing accordingly. We call this the potential difference between the two
wires of the LED.
If you were using a miniature old-fashioned lightbulb instead of an LED, you’d
see the potential difference varying much more, because a lightbulb behaves
like a “pure” resistor, whereas an LED self-adjusts to some extent, modifying its
resistance as the voltage pressure changes.
Now touch the probes to the two terminals of the potentiometer that we’re
using, so that you can measure the potential difference between them. The
Figure 1-52 potentiometer and the LED share the total available voltage, so when the po-
tential difference (the voltage drop) around the potentiometer goes up, the
potential difference around the LED goes down, and vice versa. See Figures
1-55 through 1-57. A few things to keep in mind:
• If you add the voltage drops across the devices in the circuit, the total is
the same as the voltage supplied by the batteries.
• You measure voltage relatively, between two points in a circuit.
• Apply your meter like a stethoscope, without disturbing or breaking the
connections in the circuit.
Use your meter to
measure the voltage
between these two
points.
Figure 1-53
Then compare
the voltage between
Figure 1-54. Each meter has a different these two points.
way to measure volts DC. The manually
adjusted meter (top) requires you to move
a slider switch to “DC” and then choose
the highest voltage you want to measure:
In this case, the selected voltage is 20
(because 2 would be too low). Using the
6v Battery Pack
autoranging RadioShack meter, you set it
to “V” and the meter will figure out which
range to use. Figure 1-55. How to measure voltage in a simple circuit.
20 Chapter 1
Experiment 4: Varying the Voltage
Volts Volts
Figure 1-56. The meter shows how much voltage the LED takes. Figure 1-57. The meter shows how much voltage the potentiometer
takes.
Experiencing Electricity 21
Experiment 4: Varying the Voltage
Figure 1-58. Any meter will blow its internal Figure 1-59 Figure 1-60
fuse if you try to make it measure too high
an amperage. In our circuit, this is not a
risk as long as you keep the potentiometer
in the middle of its range. Choose “mA” for
milliamps and remember that the meter
displays numbers that mean thousandths
of an amp.
Figure 1-61. A manual meter such as the one here may require you to shift the red lead to
a different socket, to measure milliamps. Most modern meters don’t require this until you
are measuring higher currents.
Insert your meter into the circuit, as shown in Figure 1-62. Don’t turn the po-
tentiometer more than halfway up. The resistance in the potentiometer will
protect your meter, as well as the LED. If the meter gets too much current,
you’ll find yourself replacing its internal fuse.
As you adjust the potentiometer up and down a little, you should find that the
varying resistance in the circuit changes the flow of current—the amperage.
This is why the LED burned out in the previous experiment: too much current
made it hot, and the heat melts it inside, just like the fuse in the previous ex-
periment. A higher resistance limits the flow of current, or amperage.
Now insert the meter in another part of the circuit, as shown in Figure 1-63. As
you turn the potentiometer up and down, you should get exactly the same re-
sults as with the configuration in Figure 1-64. This is because the current is the
same at all points in a similar circuit. It has to be, because the flow of electrons
has no place else to go.
22 Chapter 1
Experiment 4: Varying the Voltage
It’s time now to nail this down with some numbers. Here’s one last thing to
try. Set aside the LED and substitute a 1KΩ resistor, as shown in Figure 1-64.
The total resistance in the circuit is now 1KΩ plus whatever the resistance the
potentiometer provides, depending how you set it. (The meter also has some
resistance, but it’s so low, we can ignore it.)
Amps
Amps
Figure 1-62. To measure amps, as illustrated here and in Figure Figure 1-63
1-63, the current has to pass through the meter. When you
increase the resistance, you restrict the current flow, and the
lower flow makes the LED glow less brightly.
Experiencing Electricity 23
Experiment 4: Varying the Voltage
Amps
6v Battery Pack
Figure 1-64. If you substitute a resistor instead of the LED, you can confirm that the cur-
rent flowing through the circuit varies with the total resistance in the circuit, if the voltage
stays the same.
Turn the potentiometer all the way counterclockwise, and you have a total of
3K resistance in the circuit. Your meter should show about 2 mA flowing. Now
turn the potentiometer halfway, and you have about 2K total resistance. You
should see about 3 mA flowing. Turn the potentiometer all the way clockwise,
so there’s a total of 1K, and you should see 6 mA flowing. You may notice that
if we multiply the resistance by the amperage, we get 6 each time—which just
happens to be the voltage being applied to the circuit. See the following table.
24 Chapter 1
Experiment 4: Varying the Voltage
Fundamentals
Series and parallel
Before we go any further, you should know how resistance 3 volts
3 volts
in a circuit increases when you put resistors in series or in
parallel. Figures 1-65 through 1-67 illustrate this. Remember:
• Resistors in series are oriented so that one follows the 1,000 ohms
other. 6 volts 1,000 ohms
500 ohms
1,000 ohms circuit resistance
circuit resistance
12mA current
6mA current
Figure 1-67. When two resistors are in parallel, each is exposed
Figure 1-65. One resistor takes the entire voltage, and according to the full voltage, so each of them takes 6 volts. The electric-
to Ohm’s Law, it draws v/R = 6/1,000 = 0.006 amps = 6mA of ity can now flow through both at once, so the total resistance
current. of the circuit is half as much as before. According to Ohm’s
Law, the circuit draws v/R = 6/500 = 0.012 amps = 12mA of
current.
Experiencing Electricity 25
Experiment 4: Varying the Voltage
Letter I is used because origi- High Efficiency LED in 5 mm Tinted Diffused Package
nally current was measured by its
inductance, meaning the ability to
induce magnetic effects. It would Description
The TLH.54.. series was developed for standard
be much less confusing to use A applications like general indicating and lighting pur-
for amps, but unfortunately it’s too poses.
It is housed in a 5 mm tinted diffused plastic package.
late for that to happen. The wide viewing angle of these devices provides a
Pb
high on-off contrast.
Several selection types with different luminous inten-
sities are offered. All LEDs are categorized in lumi-
19223
e2 Pb-free
nous intensity groups. The green and yellow LEDs
are categorized additionally in wavelength groups.
Figure 1-68. The beginning of a typical data sheet, which includes all relevant specifica-
tions for the product, freely available online.
26 Chapter 1
Experiment 4: Varying the Voltage
Background
How much voltage does a wire consume?
Normally, we can ignore the resistance in electric wires, such as the little leads
of wire that stick out of resistors, because it’s trivial. However, if you try to force
large amounts of current through long lengths of thin wire, the resistance of
the wire can become important.
How important? Once again, we can use Ohm’s Law to find out.
Suppose that a very long piece of wire has a resistance of 0.2Ω. And we want to
run 15 amps through it. How much voltage will the wire steal from the circuit,
because of its resistance?
Once again, you begin by writing down what you know:
R = 0.2
I = 15
We want to know V, the potential difference, for the wire, so we use the version
of Ohm’s Law that places V on the left side:
V=I×R
Now plug in the values:
V = 15 × 0.2 = 3 volts
Three volts is not a big deal if you have a high-voltage power supply, but if you
are using a 12-volt car battery, this length of wire will take one-quarter of the
available voltage.
Now you know why the wiring in automobiles is relatively thick—to reduce its
resistance well below 0.2Ω. See Figure 1-69.
Some kind of
electrical
device
Figure 1-69. When a 12-volt car battery runs some kind of electrical device through
a long piece of thin wire, the resistance of the wire steals some of the voltage and
dissipates it as heat.
Experiencing Electricity 27
Experiment 4: Varying the Voltage
Here’s an example. Suppose I want a red LED, such as the Vishay part TLHR5400,
Background which has become such a common item that I can buy them individually for 9
cents apiece. I click the link to the data sheet maintained by the manufacturer,
The origins of wattage Vishay Semiconductor. Almost immediately I have a PDF page on my screen.
James Watt (Figure 1-70) is known This data sheet is for TLHR, TLHG, and TLHY types of LED, which are red, green,
as the inventor of the steam and yellow respectively, as suggested by the R, G, and Y in the product codes.
engine. Born in 1736 in Scotland, I scroll down and look at the “Optical and Electrical Characteristics” section.
he set up a small workshop in the It tells me that under conditions of drawing a current of 20 mA, the LED will
University of Glasgow, where he enjoy a “Typ,” meaning, typical, “forward voltage” of 2 volts. The “Max,” meaning
struggled to perfect an efficient maximum, is 3 volts.
design for using steam to move a
piston in a cylinder. Financial prob- Let’s look at one other data sheet, as not all of them are written the same way.
lems and the primitive state of I’ll choose a different LED, the Kingbright part WP7113SGC. Click on the link
the art of metal working delayed to the manufacturer’s site, and I find on the second page of the data sheet a
practical applications until 1776. typical forward voltage of 2.2, maximum 2.5, and a maximum forward current
Despite difficulties in obtaining of 25 mA. I also find some additional information: a maximum reverse voltage
patents (which could only be of 5 and maximum reverse current of 10 uA (that’s microamps, which are 1,000
granted by an act of parliament times smaller than milliamps). This tells us that you should avoid applying ex-
in those times), Watt and his cessive voltage to the LED the wrong way around. If you exceed the reverse
business partner eventually made voltage, you risk burning out the LED. Always observe polarity!
a lot of money from his innova-
tions. Although he predated the Kingbright also warns us how much heat the LED can stand: 260° C (500° F) for
pioneers in electricity, in 1889 (70 a few seconds. This is useful information, as we’ll be putting aside our alligator
years after his death), his name clips and using hot molten solder to connect electrical parts in the near future.
was assigned to the basic unit of Because we have already destroyed a battery, a fuse, and an LED in just four ex-
electric power that can be defined periments, maybe you won’t be surprised when I tell you that we will destroy
by multiplying amperes by volts. at least a couple more components as we test their limits with a soldering iron.
See the Fundamentals section,
“Watt Basics,” on page 31. Anyway, now we know what an LED wants, we can figure out how to supply
it. If you have any difficulties dealing with decimals, check the Fundamentals
section “Decimals,” on the next page, before continuing.
28 Chapter 1
Experiment 4: Varying the Voltage
We want to know R, the resistance. So, we use the version of Ohm’s Law that
puts R on the left side:
R= V/I
Now plug in the values:
R = 3.5/0.02
Run this through your pocket calculator if you find decimals confusing. The
answer is:
R = 175Ω
It so happens that 175Ω isn’t a standard value. You may have to settle for 180
or 220Ω, but that’s close enough.
Evidently the 470Ω resistor that you used in Experiment 3 was a very conserva-
tive choice. I suggested it because I said originally that you could use any LED
at all. I figured that no matter which one you picked, it should be safe with
470Ω to protect it.
Fundamentals
Decimals
Legendary British politician Sir Winston Churchill is famous for complain-
ing about “those damned dots.” He was referring to decimal points. Because
Churchill was Chancellor of the Exchequer at the time, and thus in charge of all
government expenditures, his difficulty with decimals was a bit of a problem.
Still, he muddled through in time-honored British fashion, and so can you.
You can also use a pocket calculator—or follow two basic rules.
Experiencing Electricity 29
Experiment 4: Varying the Voltage
Theory
Doing the math on your tongue
I’m going to go back to the question I asked in the previous That’s 100,000 times the current that may have passed
experiment: why didn’t your tongue get hot? through your tongue, which would have generated much
more heat, even though the voltage was lower.
Now that you know Ohm’s Law, you can figure out the
answer in numbers. Let’s suppose the battery delivered Could that tiny little battery really pump out 15 amps?
its rated 9 volts, and your tongue had a resistance of 50K, Remember that the battery got hot, as well as the wire. This
which is 50,000 ohms. Write down what you know: tells us that the electrons may have met some resistance
V=9 inside the battery, as well as in the wire. (Otherwise, where
else did the heat come from?) Normally we can forget about
R = 50,000
the internal resistance of a battery, because it’s so low. But at
We want to know the current, I, so we use the version of high currents, it becomes a factor.
Ohm’s Law that puts this on the left:
I was reluctant to short-circuit the battery through a meter,
I = V/R to try to measure the current. My meter will fry if the current
Plug in the numbers: is greater than 10A. However I did try putting other fuses
into the circuit, to see whether they would blow. When I
I = 9/50,000 = 0.00018 amps
tried a 10A fuse, it did not melt. Therefore, for the brand of
Move the decimal point three places to convert to milliamps: battery I used, I’m fairly sure that the current in the short
I = 0.18 mA circuit was under 10A, but I know it was over 3A, because
the 3A fuse blew right away.
That’s a tiny current that will not produce much heat at 9
volts. The internal resistance of the 1.5-volt battery prevented
the current in the short circuit from getting too high. This
What about when you shorted out the battery? How much
is why I cautioned against using a larger battery (especially
current made the wires get hot? Well, suppose the wires had
a car battery). Larger batteries have a much lower internal
a resistance of 0.1 ohms (probably it’s less, but I’ll start with
resistance, allowing dangerously high currents which gener-
0.1 as a guess). Write down what we know:
ate explosive amounts of heat. A car battery is designed to
V = 1.5 deliver literally hundreds of amps when it turns a starter
R = 0.1 motor. That’s quite enough current to melt wires and cause
nasty burns. In fact, you can weld metal using a car battery.
Once again we’re trying to find I, the current, so we use:
I = V/R Lithium batteries also have low internal resistance, making
them very dangerous when they’re shorted out. High cur-
Plug in the numbers: rent can be just as dangerous as high voltage.
I = 1.5/0.1 = 15 amps
30 Chapter 1
Experiment 4: Varying the Voltage
Fundamentals Theory
Watt basics Power assessments
So far I haven’t mentioned a unit that everyone is familiar with: watts. I mentioned earlier than resistors
are commonly rated as being
A watt is a unit of work. Engineers have their own definition of work—they say
capable of dealing with 1/4 watt,
that work is done when a person, an animal, or a machine pushes something to
1/2 watt, 1 watt, and so on. I sug-
overcome mechanical resistance. Examples would be a steam engine pulling a
gested that you should buy resis-
train on a level track (overcoming friction and air resistance) or a person walk-
tors of 1/4 watt or higher. How did
ing upstairs (overcoming the force of gravity).
I know this?
When electrons push their way through a circuit, they are overcoming a kind
Go back to the LED circuit. Re-
of resistance, and so they are doing work, which can be measured in watts. The
member we wanted the resistor to
definition is easy:
drop the voltage by 3.5 volts, at a
watts = volts × amps current of 20 mA. How many watts
Or, using the symbols customarily assigned, these three formulas all mean the of power would this impose on
same thing: the resistor?
Experiencing Electricity 31
Experiment 5: Let’s Make a Battery
32 Chapter 1
Experiment 5: Let’s Make a Battery
Theory
The nature of electricity
To understand electricity, you have to start with some basic promptly imitate their predecessors and try to get away
information about atoms. Each atom consists of a nucleus from each other by running away down the wire. The
at the center, containing protons, which have a positive process continues until the zinc-acid reaction grinds to a
charge. The nucleus is surrounded by electrons, which carry halt, usually because it creates a layer of a compound such
a negative charge. as zinc oxide, which won’t react with acid and prevents the
acid from reacting with the zinc underneath. (This is why
Breaking up the nucleus of an atom requires a lot of energy,
your zinc electrode may have looked sooty when you pulled
and can also liberate a lot of energy—as happens in a
it out of the acidic electrolyte.)
nuclear explosion. But persuading a couple of electrons to
leave an atom (or join an atom) takes very little energy. For
instance, when zinc reacts chemically with an acid, it can
liberate electrons. This is what happens at the zinc electrode
of the chemical battery in Experiment 5.
The reaction soon stops, as electrons accumulate on the
zinc electrode. They feel a mutual force of repulsion, yet
they have nowhere to go. You can imagine them like a
crowd of hostile people, each one wanting the others to
leave, and refusing to allow new ones to join them, as
shown in Figure 1-73.
Now that the population of electrons on the zinc electrode In a rechargeable battery, also known as a secondary bat-
has been reduced, the zinc-acid reaction can continue, tery, a smarter choice of electrodes and electrolyte does
replacing the missing electrodes with new ones—which allow the chemical reactions to be reversed.
Experiencing Electricity 33
Experiment 5: Let’s Make a Battery
How much current is being generated in your lemon battery? Set your meter
to measure milliamps, and connect it between the nail and the penny. I mea-
sured about 2mA, but got 10mA when I used some #10 stranded copper wire
instead of a penny and a large mending plate instead of a roofing nail, im-
mersed in a cup of grapefruit juice. When a larger surface area of metal makes
better contact with the electrolyte, you get a greater flow of current. (Don’t
ever connect your meter to measure amps directly between the terminals of
a real battery. The current will be too high, and can blow the fuse inside your
meter.)
What’s the internal resistance of your lemon? Put aside the copper and zinc
electrodes and insert your nickel-plated meter probes into the juice. I got a
reading of around 30K when both probes were in the same segment of the
lemon, but 40K or higher if the probes were in different segments. Is the resis-
tance lower when you test liquid in a cup?
Here are a couple more questions that you may wish to investigate. For how
long will your lemon battery generate electricity? And why do you think your
zinc-plated electrode becomes discolored after it has been used for a while?
Electricity is generated in a battery by an exchange of ions, or free electrons, be-
tween metals. If you want to know more about this, check the section “Theory:
The nature of electricity” on the previous page.
34 Chapter 1
Experiment 5: Let’s Make a Battery
Background
Positive and negative
If electricity is a flow of electrons, which have a negative these components should be placed—and the arrows all
charge, why do people talk as if electricity flows from the point from positive to negative, even though that’s not the
positive terminal to the negative terminal of a battery? way things really work at all! Ben Franklin would have been
surprised to learn that although most lightning strikes occur
The answer lies in a fundamental embarrassment in the
when a negative charge in clouds discharges to neutralize
history of research into electricity. For various reasons, when
a positive charge on the ground, some forms of lightning
Benjamin Franklin was trying to understand the nature of
are actually a flow of electrons from the negatively charged
electric current by studying phenomena such as lightning
surface of the earth, up to a positive charge in the clouds.
during thunderstorms, he believed he observed a flow of
That’s right: someone who is “struck by lightning” may be
“electrical fluid” from positive to negative. He proposed this
hurt by emitting electrons rather than by receiving them, as
concept in 1747.
shown in Figure 1-75.
In fact, Franklin had made an unfortunate error that
remained uncorrected until after physicist J. J. Thomson
announced his discovery of the electron in 1897, 150 years
later. Electricity actually flows from an area of greater nega-
tive charge, to some other location that is “less negative”—
that is, “more positive.” In other words, electricity is a flow
of negatively charged particles. In a battery, they originate
from the negative terminal and flow to the positive terminal.
You might think that when this fact was established, every-
one should have discarded Franklin’s idea of a flow from
positive to negative. But when an electron moves through a
wire, you can still think of an equal positive charge flowing
in the opposite direction. When the electron leaves home,
it takes a small negative charge with it; therefore, its home
becomes a bit more positive. When the electron arrives at
its destination, its negative charge makes the destination a
bit less positive. This is pretty much what would happen if
an imaginary positive particle traveled in the opposite direc-
tion. Moreover, all of the mathematics describing electrical
behavior are still valid if you apply them to the imaginary
flow of positive charges.
As a matter of tradition and convenience we still retain Ben
Franklin’s erroneous concept of flow from positive to nega- Figure 1-75. In some weather conditions, the flow of electrons
tive, because it really makes no difference. In the symbols during a lightning strike can be from the ground, through your
that represent components such as diodes and transistors, feet, out of the top of your head, and up to the clouds. Benjamin
Franklin would have been surprised.
you will actually find arrows reminding you which way
Experiencing Electricity 35
Experiment 5: Let’s Make a Battery
Theory
Basic measurements
Electrical potential is measured by adding up the charges If electrons are just moving freely, they aren’t doing any
on individual electrons. The basic unit is the coulomb, equal work. If you had a loop of wire of zero resistance, and you
to the total charge on about 6,250,000,000,000,000,000 kick-started a flow of electrons somehow, they could just
electrons. go buzzing around forever. (This is what happens inside a
superconductor—almost.)
If you know how many electrons pass through a piece of
wire each second, this establishes the flow of electricity, Under everyday conditions, even a copper wire has some re-
which can be expressed in amperes. In fact 1 ampere can be sistance. The force that we need to push electrons through
defined as 1 coulomb per second. Thus: it is known as “voltage,” and creates a flow that can create
1 ampere = 1 coulomb/second heat, as you saw when you shorted out a battery. (If the wire
that you used had zero resistance, the electricity running
= about 6.25 quintillion electrons/second
through it would not have created any heat.) We can use the
There’s no way to “see” the number of electrons running heat directly, as in an electric stove, or we can use the elec-
through a conductor (Figure 1-76), but there are indirect trical energy in other ways—to run a motor, for instance.
ways of getting at this information. For instance, when an Either way, we are taking energy out of the electrons, to do
electron goes running through a wire, it creates a wave of some work.
electromagnetic force around it. This force can be measured,
and we can calculate the amperage from that. The electric One volt can be defined as the amount of pressure that you
meter installed at your home by the utility company func- need to create a flow of 1 ampere, which does 1 watt of
tions on this principle. work. As previously defined, 1 watt = 1 volt × 1 ampere, but
the definition actually originated the other way around:
1 volt = 1 watt/1 ampere
It’s more meaningful this way, because a watt can be de-
fined in nonelectrical terms. Just in case you’re interested,
we can work backward through the units of the metric
system like this:
1 watt = 1 joule/second
1 joule = a force of 1 newton acting through 1 meter
1 newton = the force required to accelerate 1 kilogram
by 1 meter per second, each second
On this basis, the electrical units can all be anchored with
observations of mass, time, and the charge on electrons.
Figure 1-76. If you could look inside an electric wire with a suf-
ficiently powerful magnifying device, and the wire happened
to be carrying 1 ampere of electron flow at the time, you might
hope to see about 6.25 quintillion electrons speeding past
each second.
36 Chapter 1
Experiment 5: Let’s Make a Battery
Practically Speaking
For practical purposes, an intuitive understanding of electricity can be more
useful than the theory. Personally I like the water analogies that have been
used for decades in guides to electricity. Figure 1-77 shows a tall tank half full
of water, with a hole punched in it near the bottom. Think of the tank as being
like a battery. The height of the water is comparable to voltage. The volume of
flow through the hole, per second, is comparable to amperage. The smallness
of the hole is comparable to resistance. See Figure 1-79 on the next page.
Where’s the wattage in this picture? Suppose we place a little water wheel
where it is hit by the flow from the hole. We can attach some machinery to
the water wheel. Now the flow is doing some work. (Remember, wattage is a
measurement of work.)
Maybe this looks as if we’re getting something for nothing, extracting work
from the water wheel without putting any energy back into the system. But
remember, the water level in the tank is falling. As soon as I include some help-
Figure 1-77. If you want to get work out of
ers hauling the waste water back up to the top of the tank (in Figure 1-78), you a system…
see that we have to put work in to get work out.
Similarly, a battery may seem to be giving power out without taking anything
in, but the chemical reactions inside it are changing pure metals into metallic
compounds, and the power we get out of a battery is enabled by this change
of state. If it’s a rechargeable battery, we have to push power back into it to
reverse the chemical reactions.
Going back to the tank of water, suppose we can’t get enough power out of it
to turn the wheel. One answer could be to add more water. The height of the
water will create more force. This would be the same as putting two batteries
end to end, positive to negative, in series, to double the voltage. See Figure
1-80. As long as the resistance in the circuit remains the same, greater voltage
will create more amperage, because amperage = voltage/resistance.
What if we want to run two wheels instead of one? We can punch a second
hole in the tank, and the force (voltage) will be the same at each of them. How-
ever, the water level in the tank will drop twice as fast. Really, we’d do better to
build a second tank, and here again the analogy with a battery is good. If you
wire two batteries side by side, in parallel, you get the same voltage, but for
twice as long. The two batteries may also be able to deliver more current than
if you just used one. See Figure 1-81. Figure 1-78. . . . somehow or other you have
to put work back into it.
Summing up:
• Two batteries in series deliver twice the voltage.
• Two batteries in parallel can deliver twice the current.
All right, that’s more than enough theory for now. In the next chapter, we’ll
continue with some experiments that will build on the foundations of knowl-
edge about electricity, to take us gradually toward gadgets that can be fun
and useful.
Experiencing Electricity 37
Experiment 5: Let’s Make a Battery
Higher
water level
Greater force
creates more flow,
Higher voltage because amperage =
voltage / resistance,
and the voltage has
gone up, while
the resistance
has remained
the same.
Same
resistance
Figure 1-79. Greater force generates more flow, as long as the resistance remains the
same.
1.5 volts
3 volts
38 Chapter 1
Switching Basics and More 2
The concept of switching is fundamental in electronics, and I’m not just talking In this chapter
about power switches. By “switching,” I mean using one flow of electricity to
switch, or control, another. This is such an important principle that no digital Shopping List: Experiments 6 Through 11
device can exist without it. Experiment 6: Very Simple Switching
Experiment 7: Relay-Driven LEDs
Today, switching is mostly done with semiconductors. Before I deal with them,
I’ll back up and illustrate the concept by introducing you to relays, which are Experiment 8: A Relay Oscillator
easier to understand, because you can see what’s going on inside them. And Experiment 9: Time and Capacitors
before I get to relays, I’ll deal with everyday on/off switches, which may seem Experiment 10: Transistor Switching
very simple—but we have to nail down the basics. Experiment 11: A Modular Project
Also in this chapter, I’ll deal with capacitance, because capacitance and resis-
tance are fundamental to electronic circuits. By the end of the chapter, you
should have a basic grounding in electronics and be able to build the noise-
making section of a simple intrusion alarm. This will be your first circuit that
does something genuinely useful!
Devices
• Power supply/universal AC adapter, 3 to 12 volts at 1A (1,000 mA). See Fig-
ure 2-1. Part number 273-029 from RadioShack, part PH-62092 by Philips,
or similar.
• Breadboard suitable for integrated circuits. Quantity: 1. See Figures 2-2
and 2-3. Part 276-002 from RadioShack, model 383-X1000 made by PSP,
part 923252-I by 3M, or similar. A breadboard that has screw terminals
mounted beside it will be a little easier to use but more expensive than Figure 2-1. This AC adapter delivers DC
one that does not have terminals. from 3 to 12 volts, and is ideal for electron-
ics projects.
39
Shopping List: Experiments 6 Through 11
Figure 2-2. This “breadboard” for quickly Figure 2-3. A breadboard without screw
constructing electronic circuits has a metal terminals is almost as convenient, and is
base, and screw terminals for attaching cheaper.
wires from a power supply.
Tools
Wire strippers
Ideal model 45-121 wire strippers for 16- to 26-gauge wire, or similar. See
Figure 2-4. (The “gauge” of the wire tells you how thick it is. A higher gauge
means a thinner wire. In this book, we will mainly be using thin wire of
20- to 24-gauge.)
You may also consider the Kronus Automatic Wire Strippers, part 64-
2981 from RadioShack, or GB Automatic Wire Strippers, part SE-92 from
Amazon.com. See Figure 2-5.
The Kronus and GB wire strippers are functionally identical. The advan-
tage of their design is that it enables you to strip insulation from a wire
with one hand. But they do not work well on really thin wire.
Figure 2-4. To use these wire strippers, Figure 2-5. These automatic wire strippers
insert a piece of insulated wire in the enable one-handed operation, but are not
appropriate-sized hole between the jaws, suitable for very small wire diameters. See
grip the handles, and pull a section of page 44.
insulation away. See page 45.
40 Chapter 2
Shopping List: Experiments 6 Through 11
Supplies
Hookup wire
Solid-conductor, 22-gauge, minimum 25 feet of each color. See Figure 2-6.
Part 278-1222 from RadioShack, catalog item 9948T17 from McMaster-
Carr, or check eBay for deals.
It’s easy to buy the wrong kind of wire. You need solid-core wire, which has
a single conductor inside the plastic insulation, not stranded, which has
multiple, thinner conductors. See Figures 2-7 and 2-8. You’re going to be
pushing wires into little holes in a “breadboard,” and stranded wire won’t
let you do this. You will also have problems if you buy wire thicker than
22-gauge. Remember: the lower the gauge number, the thicker the wire.
For a little extra money, you can buy an assortment of precut sections of
wire, with ends stripped and ready for use. Try catalog item JW-140 (jump-
er wire assortment) from All Electronics or search eBay for “breadboard
wire.” See Figure 2-9. Figure 2-6. Using hookup wire with differ-
ent colors of plastic insulation will help you
Patch cords to distinguish one wire from another in
Patch cords are not strictly necessary but very convenient. You don’t want your circuits.
audio or video patch cords, which have a plug on each end; you want
wires with alligator clips on each end, also sometimes referred to as “test
leads.” Try catalog item 461-1176-ND from Digi-Key or catalog item MTL-
10 from All Electronics. See Figure 2-10.
Figure 2-7. Solid-conductor wire of 22 or 24 Figure 2-8. Stranded is more flexible, but
gauge is suitable for most of the experi- cannot be used easily with breadboards.
ments in this chapter.
Figure 2-9. Precut wires with stripped ends Figure 2-10. Patch cords, sometimes known
can save a lot of time and trouble—if you as test leads, consist of wires preattached
don’t mind paying a little extra. to alligator clips. This is another of those
little luxuries that reduces the hassle factor
in hobby electronics.
Components
Pushbutton
Momentary-on, SPST, sometimes referred to as OFF-(ON) or (ON)-OFF
type. Must be PCB- or PC-mount, meaning is extremely small with thin
spiky contacts on the bottom. Quantity: 1. See Figure 2-11.
Examples are part number AB11AP by NKK, part MPA103B04 by Alco-
switch, or part EP11SD1CBE by C&K. If you have a choice, buy the cheap-
Figure 2-11. The terminals protruding from
this tiny pushbutton are spaced 0.2 inches est, as we’re going to switch very low current.
apart, making it ideal for the “breadboard”
that you’ll be using.
Switches
Toggle switch, single-pole, double-throw (SPDT), sometimes referred to
as ON-ON type. Quantity: 2. See Figure 2-12.
Model S302T-RO by NKK is ideal; it has screw terminals that will eliminate
the need for alligator clips. Other options are catalog item MTS-4PC from
All Electronics or part 275-603 from RadioShack.
We won’t be switching large currents or high voltages, so the exact type of
switch is unimportant. However, the terminals on larger-size switches are
spaced wider apart, which makes them easier to deal with.
Figure 2-12. This relatively large toggle Relays
switch made by NKK has screw terminals, DPDT, nonlatching, 12v DC. Quantity: 2.
which will reduce the inconvenience of
attaching it to hookup wire. It’s important to get the right kind of relay—one whose configuration
matches the pictures I’ll be using. Look for parts FTR-F1CA012V or FTR-
F1CD012V by Fujitsu, G2RL-24-DC12 by Omron, or OMI-SH-212D by Tyco.
Avoid substitutions.
Potentiometer
1 megohm linear potentiometer, Part number 271-211 from RadioShack,
part number 24N-1M-15R-R from Jameco, or similar.
Transistors
NPN transistor, general-purpose, such as 2N2222 by STMicroelectronics,
Figure 2-13. Transistors are commonly sold part PN2222 by Fairchild, or part 2N2222 from RadioShack. Quantity: 4.
either in little metal cans or sealed into
little lumps of plastic. For our purposes, See Figure 2-13.
the packaging makes no difference.
2N6027 programmable unijunction transistor manufactured by On Semi-
conductor or Motorola. Quantity: 4.
Capacitors
Electrolytic capacitors, assorted. Must be rated for a minimum of 25 volts
and include at least one capacitor of 1,000 μF (microfarads). If you search
on eBay, make sure you find electrolytic capacitors. If they’re rated for
higher voltages, that’s OK, although they will be physically larger than you
need. See Figure 2-14.
42 Chapter 2
Experiment 6: Very Simple Switching
Ceramic capacitors, assorted. Make sure you get at least one rated at
0.0047 μF (which can also be written as 47 nF). See Figure 2-15.
Resistors
If you bought only a minimal selection for experiments 1 through 5, now’s
the time to buy a larger assortment, so that you won’t be stuck needing
the one value that you don’t have. 1/4-watt minimum.
Loudspeaker Figure 2-15. Ceramic capacitors mostly
Any 8Ω, 1-inch miniature loudspeaker such as part 273-092 from RadioShack. look like this, although many of them are
round or bead-shaped instead of square.
See Figure 2-16. The packaging shape is unimportant to us.
Long
Short
LED lead
LED lead
6v Battery Pack
Figure 2-17. If the LED is on, flipping either of the switches will turn it off. If the LED is off, Figure 2-18. Full-size toggle switches with
either of the switches will turn it on. Use alligator clips to attach the wires to each other, screw terminals make it easy to hook up
and to the switches if your switches don't have screw terminals. Be careful that the clips this simple circuit.
don't touch each other.
Tools
If automatic wire strippers (Figure 2-19) don’t grip skinny 22-gauge wire very
effectively, try the Ideal brand of wire strippers shown back in Figure 2-4, or
use plain and simple wire cutters as shown in Figure 2-20. When using wire
cutters, you hold the wire in one hand and apply the tool in your other hand,
squeezing the handles with moderate pressure—just enough to bite into the
insulation, but not so much that you chop the wire. Pull the wire down while
you pull the cutters up, and with a little practice you can rip the insulation off
to expose the end of the wire.
Macho hardware nerds may use their teeth to strip insulation from wires. When
I was younger, I used to do this. I have two slightly chipped teeth to prove it.
Really, it’s better to use the right tool for the job.
Figure 2-19. Using automatic wire strip-
pers, when you squeeze the handles the
jaw on the left clamps the wire, the sharp
grooves on the right bite into the insula-
tion. Squeeze harder and the jaws pull
away from each other, stripping the insula-
tion from the wire.
44 Chapter 2
Experiment 6: Very Simple Switching
Figure 2-20. To remove insulation from Figure 2-21. Those who tend to misplace
the end of a thin piece of wire, you can tools, and feel too impatient to search for
also use wire cutters. This takes a little them, may feel tempted to use their teeth
practice. to strip insulation from wire. This may not
be such a good idea.
Connection Problems
Depending on the size of toggle switches that you are using, you may have
trouble fitting in all the alligator clips to hold the wires together. Miniature
toggle switches, which are more common than the full-sized ones these days,
can be especially troublesome (see Figure 2-22). Be patient: fairly soon we’ll
be using a breadboard, which will eliminate alligator clips almost completely.
Testing
Make sure that you connect the LED with its long wire toward the positive
source of power (the resistor, in this case). Now flip either of the toggle switch-
es. If the LED was on, it will go off, and if it was off, it will go on. Flip the other
toggle switch, and it will have the same effect. If the LED does not go on at all,
you’ve probably connected it the wrong way around. Another possibility is
that two of your alligator clips may have shorted out the battery.
Figure 2-22. Miniature toggle switches can
Assuming your two switches do work as I described them, what’s going on be used—ideally, with miniature alligator
here? It’s time to nail down some basic facts. clips—but watch out for short circuits.
Fundamentals
Figure 2-24. This primitive-looking single- Figure 2-25. A single-pole, single-throw Figure 2-26. A double-pole, single-throw
pole, double-throw switch does exactly switch makes only one connection with switch makes two separate on/off
the same thing as the toggle switches in one pole. Its two states are simply open connections.
Figures 2-23 and 2-27. and closed, on and off.
46 Chapter 2
Experiment 6: Very Simple Switching
Fundamentals
Double
Throw with SPDT DPDT 3PDT 4PDT
Center Off ON-OFF-ON ON-OFF-ON ON-OFF-ON ON-OFF-ON
Figure 2-28. This table summarizes all the various options for
toggle switches and pushbuttons.
Now, what about pushbuttons? When you press a door Figure 2-29. This evil mad scientist is ready to apply power to
bell, you’re making an electrical contact, so this is a type of his experiment. For this purpose, he is using a single-pole,
switch—and indeed the correct term for it is a momentary double-throw knife switch, conveniently mounted on the wall of
switch, because it makes only a momentary contact. Any his basement laboratory.
spring-loaded switch or button that wants to jump back to
Fundamentals
Checking a switch
Use the continuity-testing feature on your meter only on
You can use your meter to check a switch. Doing this helps circuits or components that have no power in them at the
you find out which contacts are connected when you turn time.
a switch one way or the other. It’s also useful if you have a
pushbutton and you can’t remember whether it’s the type
Figure 2-30 Figure 2-31 Figure 2-32. To check a circuit for conti-
nuity, turn the dial of your meter to the
symbol shown. Only use this feature
when there is no power in the compo-
nent or the circuit that you are testing.
Figure 2-33. When the switch connects two of its terminals, the meter shows zero
resistance between them and will beep if you have set it to verify continuity.
48 Chapter 2
Experiment 6: Very Simple Switching
Background
Figure 2-34. Charles E. Scribner invented the “jack-knife switch” to satisfy the
switching needs of telephone systems in the late 1800s. Today’s audio jacks still
work on the same basis.*
Audio connectors on guitars and amplifiers still work on the same principle, and
when we speak of them as being “jacks,” the term dates back to Scribner’s inven-
tion. Switch contacts still exist inside a jack socket.
Today, of course, telephone switchboards have become as rare as telephone
operators. First they were replaced with relays—electrically operated switches,
which I’ll talk about later in this chapter. And then the relays were superceded
by transistors, which made everything happen without any moving parts. Be-
fore the end of this chapter, you’ll be switching current using transistors.
* The photo on which this drawing is based first appeared in The History of the Telephone by
Herbert Newton Casson in 1910 (Chicago: A. C. McClurg & Co.).
Introducing Schematics
In Figure 2-35, I’ve redrawn the circuit from Experiment 6 in a simplified style
known as a “schematic.” From this point onward, I will be illustrating circuits
with schematics, because they make circuits easier to understand. You just
need to know a few symbols to interpret them.
Compare the schematic here with the drawing of the circuit in Figure 2-17.
Larger versions of all schematics and They both show exactly the same thing: Components, and connections be-
breadboard photos are available
tween them. The gray rectangles are the switches, the zigzag thing is the resis-
online at this book's website: http://
oreilly.com/catalog/9780596153748. tor, and the symbol with two diagonal arrows is the LED.
The schematic LED symbol includes two arrows indicating that it emits light,
because there are some kinds of diodes, which we’ll get to later, that don’t.
The triangle inside the diode symbol always points from positive to negative.
Trace the path that electricity can take through the circuit and imagine the
switches turning one way or the other. You should see clearly now why either
switch will reverse the state of the LED from on to off or off to on.
This same circuit is used in houses where you have a switch at the bottom of
a flight of stairs, and another one at the top, both controlling the same light-
bulb. The wires in a house are much longer, and they snake around behind the
walls, but because their connections are still the same, they could be repre-
sented with the same basic schematic. See Figure 2-36.
A schematic doesn’t tell you exactly where to put the components. It just tells
you how to join them together. One problem: Different people use slightly
different schematic symbols to mean the same thing. Check the upcoming
section, “Fundamentals: Basic schematic symbols,” for the details.
220
Figure 2-35. This schematic shows the
Figure 2-36. The two-switch circuit shown
same circuit as in Figure 2-17 and makes it
in Figures 2-17 and 2-35 is often found in
easier to see how the switches function.
house wiring, especially where switches
are located at the top and bottom of a
flight of stairs. This sketch shows what
you might find inside the walls. Wires are
joined with “wire nuts” inside boxes that
are hidden from everyday view.
50 Chapter 2
Experiment 6: Very Simple Switching
Fundamentals
S1B
Fundamentals
52 Chapter 2
Experiment 6: Very Simple Switching
Fundamentals
Figure 2-46. Sometimes an LED is shown with a circle around it; sometimes not. In this book, I will include the circle. The arrows
indicate emitted light.
Fundamentals
2K
220
2K
Figure 2-47. These three schematics all depict the same basic
circuit. It’s the circuit that you built with the potentiometer in
Experiment 4.
54 Chapter 2
Experiment 7: Relay-Driven LEDs
1. It’s important to make sure that your AC adapter is not plugged into the
wall!
2. Chop off the little plug at the end of its wire. See Figure 2-49.
3. Use a box cutter or utility knife or scissors to make a half-inch cut between
the two conductors, and then pull the conductors apart a couple of inches.
4. Use wire cutters to trim one of the conductors shorter than the other,
so that after you strip away a little of the insulation, the exposed copper
wires cannot easily touch each other. This is a precaution against short-
circuiting your AC adapter and burning it out.
5. Strip the two conductors using your wire strippers. Twist the copper
strands between finger and thumb so that there are no loose strands
sticking out. See Figure 2-50.
6. Make sure that the two wires are not touching each other, and plug your
AC adapter into a wall outlet. Set your meter to DC volts and apply the me-
ter probes to the wires from the adapter. If the voltage is preceded with
a minus sign, you have the probes the wrong way around. Reverse them
and the minus sign should go away. This tells you which wire is positive.
Figure 2-49. Preparing an AC adapter. First,
cut off the little low-voltage plug and throw
7. Mark the positive wire from the adapter. If the wire has white insulation,
it away. you can mark it with a red marker. If it has black insulation, you can tag it
with a label. The positive wire will remain positive regardless of which way
up you plug the AC adapter into a wall outlet.
The Relay
The type of relay that I want you to use has little spiky legs on the bottom, in
a standardized layout. If you buy some other kind of relay, you will have to
figure out for yourself which pins are connected to the coil inside, which pins
go to the poles of the switch inside it, and which go to the normally closed
and normally open contacts. You can check the manufacturer’s data sheet for
this purpose, but I strongly suggest you use one of the relays mentioned in the
shopping list, so that you can follow the instructions here more easily.
I asked you to buy two relays so that you can use one for investigational pur-
poses—meaning that you can break it open and take a look inside. If you do
this very, very carefully, the relay should still be usable afterward. If not, well,
you still have a spare.
The easiest way to open the relay is with a box cutter or utility knife. Figures
2-52, 2-53, and 2-54 show the technique. Shave the edges of the plastic shell
containing the relay, beveling them until you see just a hair-thin opening.
Figure 2-50. Second, strip the wires, mak- Don’t go any farther; the parts inside are very, very close to its housing. Now
ing one shorter than the other to reduce pop the top off. You can use needle-nosed pliers to nibble the rest of the shell
the risk of them touching. Color one of the away. Read the following section, “Fundamentals: Inside a relay,” and then ap-
adapter wires red with a marker, to identify
ply power to the relay to see how it works.
it as the positive one.
56 Chapter 2
Experiment 7: Relay-Driven LEDs
D
B
C
Figure 2-55
Figure 2-51. This is one way that the parts inside a relay can be arranged. The coil, A, gener-
ates a magnetic attraction pulling lever B downward. A plastic extension, C, pushes outward
against flexible metal strips and moves the poles of the relay, D, between the contacts.
Figure 2-52. To look inside a sealed relay, Figure 2-53. Insert the blade of your knife
shave the top edges of the plastic package to pry open the top, then repeat the proce-
with a utility knife til you open a thin crack. dure for the sides.
Fundamentals
Inside a relay
A relay contains a coil of wire wrapped around an iron core. The contacts are shown as little triangles. When there are
When electricity runs through the coil, the iron core exerts two poles instead of one, the coil activates both switches
a magnetic force, which pulls a lever, which pushes or pulls simultaneously.
a springy strip of metal, closing two contacts. So as long as
Most relays are nonpolarized, meaning that you can run
electricity runs through the coil, the relay is “energized” and
electricity through the coil in either direction, and the relay
its contacts remain closed.
doesn’t care. You should check the data sheet to make sure,
When the power stops passing through the coil, the relay though. Some relay coils work on AC voltage, but almost
lets go and the springy strip of metal snaps back into its all low-voltage relays use direct current—a steady flow of
original position, opening the contacts. (The exception to electricity, such as you would get from a battery. We’ll be
this rule is a latching relay, which requires a second pulse using DC relays in this book.
through a separate coil to flip it back to its original posi-
Relays suffer from the same limitations as switches: their
tion; but we won’t be using latching relays until later in the
contacts will be eroded by sparking if you try to switch too
book.)
much voltage. It’s not worth saving a few dollars by using
Relays are categorized like switches. Thus, you have SPST a relay that is rated for less current or voltage than your
relays, DPST, SPDT, and so on. application requires. The relay will fail you when you need it
most, and may be inconvenient to replace.
Compare the schematics in Figure 2-58 with the schematics
of switches in Figure 2-38. The main difference is that the Because there are so many different types of relays, read the
relay has a coil that activates the switch. The switch is shown specifications carefully before you buy one. Look for these
in its “relaxed” mode, when no power flows through the coil. basics:
Coil voltage
The voltage that the relay is supposed to receive when
you energize it.
Set voltage
The minimum voltage that the relay needs to close its
switch. This will be a bit less than the ideal coil voltage.
Operating current
The power consumption of the coil, usually in milliamps,
when the relay is energized. Sometimes the power is
expressed in milliwatts.
Switching capacity
The maximum amount of current that you can switch
with contacts inside the relay. Usually this is for a “resis-
tive load,” meaning a passive device such as light bulb.
When you use a relay to switch on a motor, the motor
takes a big initial surge of current before it gets up to
speed. In this case, you should choose a relay rated
for double the current that the motor draws when it is
running.
58 Chapter 2
Experiment 7: Relay-Driven LEDs
Procedure
Turn the relay with its legs in the air and attach wires and LEDs as shown in
Figure 2-59, with a 680Ω resistor (a 1K resistor will be OK if you don’t have the
correct value). Also attach a pushbutton switch. (Your pushbutton switch may
look different from the one shown, but as long as it is a SPST pushbutton with
two contacts at the bottom, it will work the same way.) When you press the
pushbutton, the relay will make the first LED go out and the second LED light
up. When you release the pushbutton, the first LED lights up and the second
one goes out.
How It Works
Check the schematic in Figure 2-60 and compare it with Figure 2-59. Also see
Figure 2-62, which shows how the pins outside the relay make connections
inside the relay when its coil is energized, and when it is not energized.
This is a DPDT relay, but we are only using one pole and ignoring the other. 12v DC from
AC adapter
Why not buy a SPDT relay? Because I want the pins to be spaced the way they
are when you will upgrade this circuit by transferring it onto a breadboard, Figure 2-59. As before, you can use patch
which will happen very shortly. cords, if you have them, instead of some of
the wired connections shown here.
On the schematic, I have shown the switch inside the relay in its relaxed
state. When the coil is energized, the switch flips upward, which seems 680
counterintuitive, but just happens to be the way that this particular relay is
made.
When you’re sure you understand how the circuit works, it’s time to move on
to the next step: making a small modification to get the relay to switch itself
on and off, as we’ll do in Experiment 8.
12v
DC
Connected
Connected
Connected
Connected
Figure 2-61. The layout of the Figure 2-62. How the relay connects the pins, when it is
pins of the relay, superimposed not energized (left) and when it is energized (right).
on a grid of 1/10-inch squares. Larger versions of all schematics and
This is the type of relay that you breadboard photos are available
will need in Experiment 8. online at this book's website: http://
oreilly.com/catalog/9780596153748.
680
12v DC from
AC adapter
12v
Figure 2-63. A small revision to the previ- DC
ous circuit causes the relay to start oscil-
lating when power is applied.
Now, when you press the button, the contacts in their relaxed state feed power
to the coil as well as to the lefthand LED. But as soon as the coil is energized, it
opens the contacts. This interrupts the power to the coil—so the relay relaxes,
and the contacts close again. They feed another pulse of power to the coil,
which opens the contacts again, and the cycle repeats endlessly.
Because we’re using a very small relay, it switches on and off extremely fast.
In fact, it oscillates perhaps 50 times per second (too fast for the LEDs to show
what’s really happening). Make sure your circuit looks like the one in the dia-
gram, and then press the pushbutton very briefly. You should hear the relay
make a buzzing sound. If you have impaired hearing, touch the relay lightly
with your finger, and you should feel the relay vibrating.
When you force a relay to oscillate like this, it’s liable to burn itself out or de-
stroy its contacts. That’s why I asked you to press the pushbutton briefly. To
make the circuit more practical, we need something to slow the relay down
and prevent it from self-destructing. That necessary item is a capacitor.
60 Chapter 2
Experiment 8: A Relay Oscillator
Adding Capacitance
Add a 1,000 μF electrolytic capacitor in parallel with the coil of the relay as
shown in the diagram in Figure 2-65 and the schematic in Figure 2-66. Check
Figure 2-14 if you’re not sure what a capacitor looks like. The 1,000 μF value will
be printed on the side of it, and I’ll explain what this means a little later.
Make sure the capacitor’s short wire is connected to the negative side of the
circuit; otherwise, it won’t work. In addition to the short wire, you should find
a minus sign on the body of the capacitor, which is there to remind you which
side is negative. Electrolytic capacitors are fussy about this.
When you press the button now, the relay should click slowly instead of buzz-
ing. What’s happening here?
A capacitor is like a tiny rechargeable battery. It’s so small that it charges in a
fraction of a second, before the relay has time to open its lower pair of con-
tacts. Then, when the contacts are open, the capacitor acts like a battery, pro- 12v DC from
AC adapter
viding power to the relay. It keeps the coil of the relay energized for about one
second. After the capacitor exhausts its power reserve, the relay relaxes and Figure 2-65. Adding a capacitor makes the
the process repeats. relay oscillate more slowly.
680
Fundamentals
Farad basics
12v
The Farad is an international unit to measure capacitance. Modern circuits DC
usually require small capacitors. Consequently it is common to find capacitors
measured in microfarads (one-millionth of a farad) and even picofarads (one-
trillionth of a farad). Nanofarads are also used, more often in Europe than in the
United States. See the following conversion table.
(You may encounter capacitances greater than 1,000 microfarads, but they are
uncommon.)
Fundamentals
Capacitor basics
DC current does not flow through a capacitor, but voltage can accumulate very
quickly inside it, and remains after the power supply is disconnected. Figures
2-67 and 2-68 may help to give you an idea of what happens inside a capacitor
when it is fully charged.
Figure 2-67. When DC voltage reaches a capacitor, no current flows, but the capaci-
tor charges itself like a little battery. The positive and negative charges are equal
Getting Zapped by Capacitors and opposite.
62 Chapter 2
Experiment 8: A Relay Oscillator
Fundamentals
Figure 2-69. The generic schematic for a capacitor is on the left. The version on the
right indicates a polarized capacitor which requires its left plate to be “more posi-
tive” than its right plate. The plus sign is often omitted.
Capacitor Polarity
You must connect an electrolytic
capacitor so that its longer wire is
more positive than its shorter wire.
The shell of the capacitor is usually
marked with a negative sign near the
shorter wire.
Some capacitors may behave badly
if you don’t observe their polarity.
One time I connected a tantalum
capacitor to a circuit, using a power
supply able to deliver a lot of current,
and was staring at the circuit and
wondering why it wasn’t working
when the capacitor burst open and
scattered little flaming fragments of
itself in a 3-inch radius. I had forgot-
ten that tantalum capacitors can be
fussy about positive and negative
connections. Figure 2-70 shows the
aftermath.
Figure 2-70. A tantalum capacitor was plugged into this breadboard, accidentally
connected the wrong way around to a power source capable of delivering a lot of
current. After a minute or so of this abuse, the capacitor rebelled by popping open
and scattering small flaming pieces, which burned their way into the plastic of the
breadboard. Lesson learned: observe polarity!
Background
64 Chapter 2
Experiment 8: A Relay Oscillator
Figure 2-72. A typical breadboard. You can plug components Figure 2-73. This X-ray-vision view of the breadboard reveals
into the holes to test a circuit very quickly. the copper strips that are embedded in it. The strips conduct
electricity from one component to another.
12v
DC
R1
D2
D1
S1
S2
C1
Figure 2-74. If you place the components on your breadboard in the posi- Figure 2-75. If your breadboard doesn’t have screw
tions shown, they will create the same circuit that you built from wire and terminals, insert two short pieces of solid-core
alligator clips in Experiment 8. Component values: wire with stripped ends and then attach the
stranded wires from the adapter using alligator
D1, D2: Light-emitting diodes clips.
S1: DPDT relay
S2: SPST momentary switch
C1: Electrolytic capacitor, 1,000 µF
R1: Resistor, 680Ω minimum
66 Chapter 2
Experiment 8: A Relay Oscillator
You’ll need some more 22-gauge wire, or some precut hookup wire, to supply
the power to your components, which are plugged into the breadboard as
shown in Figures 2-76 and 2-77. If you get all the connections right, the circuit
should function the same way as before.
The geometry of the metal connecting strips in the breadboard often forces
you to connect components in a roundabout way. The pushbutton, for in-
stance, supplies power to the pole of the relay but cannot be connected di-
rectly opposite, because there isn’t room for it.
Remember that the strips inside the breadboard that don’t have any wires or
components plugged into them are irrelevant; they don’t do anything.
I’ll include some suggested breadboard layouts for circuits as you continue
through this book, but eventually you’ll have to start figuring out breadboard Larger versions of all schematics and
layouts for yourself, as this is an essential part of hobby electronics. breadboard photos are available
online at this book's website: http://
oreilly.com/catalog/9780596153748.
Figure 2-76. Two oversized LEDs, one resistor, and the necessary jumper wires have been
added to the breadboard.
Figure 2-77. Now the pushbutton, relay, and capacitor have been added to complete the
circuit shown in the diagram and the schematic. When the pushbutton is pressed, the
relay oscillates and the LEDs flash.
12v
DC
S1
R1
C1
68 Chapter 2
Experiment 9: Time and Capacitors
Release the pushbutton, set aside your meter, and discharge the capacitor by
touching R2 across it for a second or two. Now substitute a 50K resistor for R1,
and repeat the measurement. The meter should count upward almost twice
as fast as before.
difference between one end of the resistor and the other will be zero (assum-
ing that we ignore little imperfections in the components). Figure 2-80 may
help to clarify this concept.
1K 1K
12v
DC
6 6
volts volts
1K 9K
12v
DC
1.2 10.8
volts volts
1K 99K
12v
DC
0.12 11.88
volts volts
infinite
1K resistance
12v
DC
0 12
volts volts
Figure 2-80. When two resistances are in series, the larger one drops the voltage more
than the smaller one. If the larger resistance becomes infinite (as in the case of a capaci-
tor), the smaller one no longer has any measurable contribution to the voltage drop, and
the voltage is almost exactly the same at both ends.
You should try this using real resistors and capacitors—although if you do, you
will run into a little problem. When you use your meter in its “DC volts” mode, it
diverts a little of the current in the circuit—just a tiny taste—in the process of
measuring it. The meter steals such a small amount, it doesn’t affect the read-
ing significantly when you are checking voltage across a resistor. The internal
resistance of the meter is higher than the values of most resistors. However,
remember that the internal resistance of a capacitor is almost infinite. Now the
internal resistance of the meter becomes significant. Because you can never
have an ideal meter, any more than you can have an ideal capacitor or resistor,
your meter will always interfere with the circuit slightly, and you will get only
an approximate indication.
If you try to measure the voltage on a capacitor that has been charged but is
now not connected to anything else, you’ll see the number slowly falling, as
the capacitor discharges itself through the meter.
70 Chapter 2
Experiment 9: Time and Capacitors
Theory
Figure 2-81. If our gourmet always eats just 63% of the cake still on the plate, he “charges up” his stomach in the same way that a
capacitor charges itself. No matter how long he keeps at it, his stomach is never completely filled.
Theory
volts) to find the difference. Call the result V2. Now take 63%
of V2, and add this to the current charge (V1) and call the
result V4. This is the new charge that the capacitor will have
after 1 second, so we copy it down to the next line in the
table, and it becomes the new value for V1.
Now we repeat the same process all over again. Figure 2-82
shows this in graphical form. Note that after 5 seconds, Figure 2-82. A capacitor starts with 0 volts. After 1 time con-
the capacitor has acquired 11.92 volts, which is 99% of stant it adds 63% of the available voltage. After another time
the power supply voltage. This should be close enough to constant, it adds another 63% of the remaining voltage differ-
satisfy anyone’s real-world requirements. ence, and so on.
72 Chapter 2
Experiment 10: Transistor Switching
R1
R2 Q1
Figure 2-85. The transistor blocks voltage that reaches it through R1.
S1 R3 But when pushbutton S1 is pressed, this tells the transistor to allow
current to pass through it. Note that transistors are always identified
with letter Q in wiring diagrams and schematics.
D1
S1: Pushbutton, momentary, OFF (ON)
R1: 180Ω
R2: 10K
R3: 680Ω
Q1: 2N2222 or similar
D1: LED
Initially, the LED should be dark. Now press the pushbutton and the LED should
glow brightly. Electricity is following two paths here. Look at the schematic in
Figure 2-86, which shows the same circuit more clearly. I’ve shown positive at
the top and negative at the bottom (the way most schematics do it) because it
helps to clarify the function of this particular circuit. If you view the schematic
S1 from the side, the similarity with the breadboard layout is easier to see.
Through R1, voltage reaches the top pin (the collector) of the transistor. The
R2 R1 transistor only lets a tiny trickle of it pass through, so the LED stays dark. When
you press the button, voltage is also applied along a separate path, through R2
to the middle pin (the base) of the transistor. This tells the transistor to open
its solid-state switch and allow current to flow out through its third pin (the
emitter), and through R3, to the LED.
Q1 You can use your meter in volts DC mode to check the voltage at points in the
circuit. Keep the negative probe from the meter touching the negative voltage
source while you touch the positive probe to the top pin of the transistor, the
middle pin, and the bottom pin. When you press the button, you should see
the voltage change.
R3 Fingertip Switching
Now here’s something more remarkable. Remove R2 and the pushbutton, and
insert two short pieces of of wire as shown in Figure 2-87. The upper piece of
wire connects with the positive voltage supply; the lower piece connects with
the middle pin of the transistor (its base). Now touch the tip of your finger to
the two wires. Once again, the LED should glow, although not as brightly as
before. Lick the tip of your finger, try again, and the LED should glow more
brightly.
Figure 2-86. This shows the same circuit as Never Use Two Hands
the breadboard diagram in Figure 2-85. The fingertip switching demo is safe if the electricity passes just through your finger.
You won’t even feel it, because it’s 12 volts DC from a power supply of 1 amp or less.
But it’s not a good idea to put the finger of one hand on one wire, and the finger of
your other hand on the other wire. This would allow the electricity to pass through
your body. Although the chance of hurting yourself this way is extremely small, you
should never allow electricity to run through you from one hand to the other. Also,
when touching the wires, don’t allow them to penetrate your skin.
74 Chapter 2
Experiment 10: Transistor Switching
Your finger is conducting positive voltage to the base of the transistor. Even
though your skin has a high resistance, the transistor still responds. It isn’t just
switching the LED on and off; it is amplifying the current applied to its base.
This is an essential concept: a transistor amplifies any changes in current that
you apply to its base.
Check Figure 2-88 to see more clearly what’s happening.
If you studied the section “Background: Positive and negative” in Chapter 1,
you learned that there is really no such thing as positive voltage. All we re-
ally have is negative voltage (created by the pressure of free electrons) and
an absence of negative voltage (where there are fewer free electrons). But be-
cause the idea of a flow of electricity from positive to negative was so widely
believed before the electron was discovered, and because the inner workings
of a transistor involve “holes” which are an absence of electrons and can be
Finger R1
thought of as positive, we can still pretend that electricity flows from positive
to negative. See the following section, “Essentials: All about NPN and PNP tran- tip
sistors,” for more details.
12v Q1
DC
R3
R1
Q1
Finger
tip R3
D1
Essentials
C E
B B
C
E
Figure 2-90. In a PNP transistor, a small negative potential has
Figure 2-89. You can think of a bipolar transistor as if it contains the same effect. The arrows point in the direction of “positive
a button that can connect the collector and the emitter. In an current flow.”
NPN transistor, a small positive potential presses the button.
76 Chapter 2
Experiment 10: Transistor Switching
Essentials
C E
B B
E C
Figure 2-91. The symbol for an NPN transistor always has an ar- Figure 2-92. The symbol for a PNP transistor always has an ar-
row pointing from its base to its emitter. Some people include row pointing from its emitter to its base. Some people include
a circle around the transistor; others don’t bother. The style of a circle around the transistor; others don’t bother. The style of
the arrow may vary. But the meaning is always the same. The the arrow may vary. But the meaning is always the same. The
top-left version is the one I use in this book. top-left version is the one I use in this book.
Background
Transistor origins
Though some historians trace the origins of the transistor back to the inven-
tion of diodes (which allow electricity to flow in one direction while preventing
reversal of the flow), there’s no dispute that the first working transistor was
developed at Bell Laboratories in 1948 by John Bardeen, William Shockley, and
Walter Brattain (Figure 2-93).
Shockley was the leader of the team, who had the foresight to see how
potentially important a solid-state switch could be. Bardeen was the theorist,
and Brattain actually made it work. This was a hugely productive collabora-
tion—until it succeeded. At that point, Shockley started maneuvering to have
the transistor patented exclusively under his own name. When he notified his
collaborators, they were—naturally—unhappy about this idea.
A widely circulated publicity photograph didn’t help, in that it showed Shockley
sitting at the center in front of a microscope, as if he had done the hands-on
work, while the other two stood behind him, implying that they had played a
lesser role. In fact Shockley, as the supervisor, was seldom present in the labora-
tory where the real work was done.
The productive collaboration quickly disintegrated. Brattain asked to be trans-
ferred to a different lab at AT&T. Bardeen moved to the University of Illinois
to pursue theoretical physics. Shockley eventually left Bell Labs and founded
Shockley Semiconductor in what was later to become Silicon Valley, but his am-
bitions outstripped the capabilities of the technology of his time. His company
never manufactured a profitable product.
Eight of Shockley’s coworkers in his company eventually betrayed him by
quitting and establishing their own business, Fairchild Semiconductor, which
became hugely successful as a manufacturer of transistors and, later, integrated
circuit chips.
Figure 2-93. Photographs provided by the Nobel Foundation show, left to right, John
Bardeen, William Shockley, and Walter Brattain. For their collaboration in develop-
ment of the world’s first working transistor in 1948, they shared a Nobel prize in
1956.
78 Chapter 2
Experiment 10: Transistor Switching
Essentials
Transistor Relay
Long-term reliability Excellent Limited
Configurable for DP and DT switching No Yes
Ability to switch large currents Limited Good
Able to switch alternating current (AC) Usually not Yes
Can be triggered by alternating current (AC) Usually not Optional
Suitability for miniaturization Excellent Very limited
Sensitive to heat High Moderate
Ability to switch at high speed Excellent Limited
Price advantage for low-voltage low-current Yes No
Price advantage for high-voltage high-current No Yes
Current leakage when “off” Yes No
Theory
80 Chapter 2
Experiment 10: Transistor Switching
Theory
What about the other end of its range? When it passes only
1.9 mA, the transistor has an internal resistance of around Figure 2-95. This is basically the
6,000Ω. The conclusion is that depending how much cur- P1 A1 Q1 same as the previous circuit,
with a potentiometer added and
rent you apply to this transistor, its internal resistance varies
the LED removed. Component
between zero and 6,000Ω, approximately. A2 values:
So much for the theory. Now what can we do with a transis-
R1: 180Ω
tor that’s fun, or useful, or both? We can do Experiment 11! R4 R3 R2: 10K
R3: 180Ω
R4: 10K
P1: 1M linear potentiometer
Q1: 2N2222 transistor
Amps
Amps
12v 12v
DC DC
R1 R1
Q1 Q1
A1 A2
R2
R2
R3
R3
R4 R4
Figure 2-96. The meter is measuring current flowing from the Figure 2-97. One end of resistor R3 has been unplugged from
potentiometer into the base of the transistor at position A1 the breadboard so that the meter now measures current
(see Figure 2-95). flowing out through the emitter of the transistor, into R3, at
position A2.
D1
functions, more accurately and more cheaply. However, the so-called pro-
grammable unijunction transistor is still widely available, often used in appli-
cations such as lamp dimmers and motor controllers. Because its primary use
Figure 2-98. Assemble these components, is in generating a stream of pulses, it’s ideal for our purposes.
apply power, and the LED should start
flashing.
If you put together the components shown in Figure 2-98, the LED should start
flashing as soon as you apply power.
R1: 470K
R2: 15K Note that this circuit will work on 6 volts. You won’t damage anything if you
R3: 27K run it with 12 volts, but as we continue adding pieces to it, you’ll find that
C1: 2.2 μF electrolytic capacitor it actually performs better at 6 volts than at 12. If you read the next section,
D1: LED
Q1: 2N6027 programmable unijunction
“Essentials: All about programmable unijunction transistors,” you’ll find out
transistor how the circuit works.
82 Chapter 2
Experiment 11: A Modular Project
Essentials
Anode
Gate
Anode
Gate
Cathode Cathode
Figure 2-99. The schematic symbol for Figure 2-100. In PUTs manufactured by
a PUT. On Semiconductor and Motorola, the
leads have these functions.
Essentials
ANODE
R1 R3
Input
GATE signal
R2
Output
device
CATHODE
Figure 2-101. When voltage at the anode Figure 2-102. This simple schematic
of a PUT crosses a threshold (deter- shows how a PUT is used. R1 and R2
mined by a preset voltage at the gate), determine the voltage at the gate, which
current breaks through and surges from sets the threshold point for the input at
the anode to the cathode. In this sense, the anode. Above the threshold, current
the anode voltage acts as if it presses a flows from anode to cathode.
button itself to open a connection inside
the PUT, with some assistance from
control voltage at the gate.
84 Chapter 2
Experiment 11: A Modular Project
6V
DC
470K 2.2uF
15K 27K
2N6027
Figure 2-103. This makes it easier to see what’s happening in the breadboard version.
The 15K resistor and 27K resistor establish the voltage at the gate. The 470K
resistor supplies the anode of the PUT, but the PUT begins in its “off” condition,
blocking the voltage. So the voltage starts to charge the 2.2 μF capacitor.
You may remember that a resistor slows the rate at which a capacitor accu-
mulates voltage. The bigger the resistor and/or the larger the capacitor, the
longer the capacitor takes to reach a full charge. In this circuit, the capacitor
takes about half a second to get close to 6 volts.
But notice that the PUT is connected directly with the capacitor. Therefore,
whatever voltage accumulates on the capacitor is also experienced by the
PUT. As the voltage gradually increases, finally it reaches the threshold, which
flips the PUT into its “on” state. The capacitor immediately discharges itself
through the PUT, through the LED (which flashes), and from there to the nega-
tive side of the power supply.
The surge depletes the capacitor. The voltage drops back down, and the PUT
returns to its original state. Now the capacitor has to recharge itself all over
again, until the whole process repeats itself.
If you substitute a 22 μF capacitor, the charge/discharge cycle should take
about 10 times as long, which will give you time to measure it. Set your me-
ter to measure volts DC and place its probes on either side of the capacitor.
You can actually watch the charge increasing until it reaches the threshold, at
which point the capacitor discharges and the voltage drops back down again.
So now we have an oscillator. What’s next?
6V 6V
DC
DC
470K 2.2uF
R1
R2 C1
Q1
15K 27K
R3
2N6027
D1
470K .0047uF
R4
R5 C2
Q2 33K 27K
R6
R7
2N6027
L1 100
Figure 2-104. The extra components which have been added at the lower half of the bread- Figure 2-105. The previous section that you
board have the same functions as the components at the top, but some values are slightly built is shown in gray. Just add the new
different: section in black.
R4: 470K
R5: 33K
R6: 27K
R7: 100Ω
C2: 0.0047 μF
Q2: 2N6027
L1: 8Ω 1-inch loudspeaker
86 Chapter 2
Experiment 11: A Modular Project
6V 6V
DC
DC
470K 2.2uF
R1
R2 C1
Q1
15K 27K
2N6027
R3
D1
470K .0047uF
R4
C2 33K 27K
R5 Q2
2N6027
R6
R8
R7 100
Q3
1K
L1
2N2222
Figure 2-107. By adding a 2N2222 general-purpose transistor, we amplify the signal Figure 2-108
from Q2:
R8: 1K
Q3: 2N2222
Other components are the same as in the previous step in constructing this circuit.
Add the second 2N2222 as shown in Figure 2-109. In Figure 2-110, once again
the previously wired section is in gray.
If the accumulation of electrical components is beginning to seem confusing,
remember that each cluster of parts has a separate defined function. We can
draw a block diagram to illustrate this, as in Figure 2-112.
Using the second 2N2222, you should find that the output is more clearly
audible, at least within the limits of your tiny 1-inch loudspeaker. Cup your
hands around it to direct the sound, and you’ll find that the volume seems
to increase. You can also try using a 3-inch loudspeaker, which will create a
generally better audio output while still remaining within the limits of the little
2N2222 transistor. See Figure 2-106, shown previously, and Figure 2-111.
88 Chapter 2
Experiment 11: A Modular Project
6V 6V
DC DC
470K 2.2uF
R1
R2 C1
Q1
15K 27K
R3
D1
2N6027
470K .0047uF
R4
R5 C2 33K 27K
Q2
R6
R8 2N6027
R9
Q3 2K2
1K
R7 100
Q4
L1 2N2222
2N2222
Figure 2-109. Q4 is another 2N2222 transistor that further amplifies the signal. It receives Figure 2-110. This schematic is comparable
power through R9: 2.2K. with the component layout in Figure 2-109.
Figure 2-111. The 2N2222 transistor is quite capable of driving a 3-inch loudspeaker, which
will create much better sound than a 1-inch speaker.
Fast Oscillator Well, the first section of the circuit that you assembled created a pulsing signal
about twice per second. You used it to flash an LED. Maybe we can get rid of
the LED and feed the output from the first section to the second section. The
lower block diagram in Figure 2-112 explains this concept.
Amplifier Can it really be that simple? Well, yes and no. The trick is to make the output
from the first section compatible with the input to the second section. If you
simply connect a wire from the cathode of the first PUT to the anode of the
second PUT, that’s not going to work, because the second PUT is already oscil-
lating nicely between low and high voltage, about 1,000 times each second.
Loudspeaker Add more voltage, and you will disrupt the balance that enables oscillation.
However, remember that the voltage on the gate of a PUT affects its threshold
for conducting electricity. Maybe if we connect the output from Q1 to the gate
of Q2, we’ll be able to adjust that threshold automatically. The voltage still has
to be in a range that the PUT finds acceptable, though. We can try various re-
Power sistors to see which one works well.
This sounds like trial and error—and that’s exactly what it is. Doing the math
to predict the behavior of a circuit like this is far too complicated—for me, any-
way. I just looked at the manufacturer’s data sheet, saw the range of resistor
Slow Oscillator values that the PUT would tolerate, and chose one that seemed as if it should
work.
If you remove the LED and substitute R10 as shown in the breadboard diagram
in Figure 2-113, you’ll find that the fluctuating output from Q1 makes Q2 emit
Fast Oscillator a two-tone signal. This is more interesting, but still not what I want. I’m think-
ing that if I make the pulses out of Q1 less abrupt, the result could be better,
and the way to smooth a pulsing output is to hook up another capacitor that
will charge at the beginning of each pulse and then release its charge at the
end of each pulse. This is the function of C3 in Figure 2-114, and it completes
Amplifier the circuit so that it makes a whooping sound almost like a “real” alarm.
If you don’t get any audio output, check your wiring very carefully. It’s easy to
make a wrong connection on the breadboard, especially between the three
legs of each transistor. Use your meter, set to DC volts, to check that each sec-
Loudspeaker tion of the circuit has a positive voltage relative to the negative side of the
power supply.
Figure 2-112. Top: The basic functions of
the noisemaking oscillator circuit shown Figure 2-115 shows how your circuit should actually look on the breadboard.
as a block diagram. Bottom: The same
functions with a slow oscillator added to
control the fast oscillator.
90 Chapter 2
Experiment 11: A Modular Project
6V 6V
DC
DC
470K 2.2uF
R1
R2 C1
Q1
15K 27K
2N6027 2.2uF
R3
C3
10K
R1
.0047uF
0
R4
470K
R5 C2 27K
Q2
33K
R6
R8 2N6027
R9
Q3 2K2
1K
R7 100
Q4
L1 2N2222
2N2222
Figure 2-113. R10 connects the slow-running oscillator at the top of the breadboard to the Figure 2-114. This schematic shows the
gate of Q2, the PUT in the middle of the breadboard. This modulates the audio oscillator, same circuit as in Figure 2-113:
with addition of a smoothing capacitor.
R10: 10K
C3: 2.2 μF
Figure 2-115. This photograph shows the complete alarm-audio circuit on a breadboard.
Tweaking it
There’s still a lot of room for creativity here:
• Adjust the frequency of the sound: Use a smaller or larger capacitor in-
stead of C2 (half or twice the current value). Use a smaller or larger value
for R5.
• Adjust the pulsing feature: Use a smaller or larger capacitor instead of C1
(half or twice the current value). Use a smaller or larger value for R2.
• General performance adjustments: try a larger value for R1. Try smaller or
larger values for C3.
• Try running the circuit at 7.5 volts, 10 volts, and 12 volts.
The circuits in this book are suggested as only a starting point. You should
always try to tweak them to make them your own. As long as you follow the
general rule of protecting transistors and LEDs with resistors, and respecting
their requirements for positive and negative voltage, you’re unlikely to burn
them out. Of course, accidents will happen—I myself tend to be careless, and
fried a couple of LEDs while working on this circuit, just because I connected
them the wrong way around.
Step 5: Enhancements
A noisemaking circuit is just the output of an alarm. You would need several
enhancements to make it useful:
1. Some kind of an intrusion sensor. Maybe magnetic switches for windows
and doors?
2. A way to start the sound if any one of the sensors is triggered. The way
this is usually done is to run a very small but constant current through
all of the switches in series. If any one switch opens, or if the wire itself is
broken, this interrupts the current, which starts the alarm. You could make
this happen with a double-throw relay, keeping the relay energized all the
time until the circuit is broken, at which point, the relay relaxes, opening
one pair of contacts and closing the other pair, which can send power to
the noisemaker.
The trouble is that a relay draws significant power while it’s energized, and
it also tends to get hot. I want my alarm system to draw very little current
while it’s in “ready” mode, so that it can be powered by a battery. Alarm
systems should never depend entirely on AC house current.
If we don’t use a relay, can we use a transistor to switch on the rest of the
circuit when the power is interrupted? Absolutely; in fact, one transistor
will do it.
3. But how do we arm the alarm in the first place? Really, we need a three-
step procedure. First, check a little light that comes on when all the doors
and windows are closed. Second, press a button that starts a 30-second
countdown, giving you time to leave, if that’s what you want to do. And
third, after 30 seconds, the alarm arms itself.
92 Chapter 2
Experiment 11: A Modular Project
-- Integrated circuits
-- Digital electronics
-- Microcontrollers
-- Motors
The tools are not particularly exotic or expensive, and the soldering skills are
easily acquired. Learning to join wires with solder is far easier than mastering
high-level crafts such as jewelry making or welding.
As for additional areas of knowledge about electronics, they are no more chal-
lenging than those that I have covered already.
By the end of this section, you should be able to transplant components from
a breadboard onto perforated board, where you will solder everything togeth-
er, and then mount the board in a little box with switches and warning lights
on the front, for everyday use.
95
Shopping List: Experiments 12 Through 15
I am assuming that you already have some commonly used workshop basics,
such as an electric drill.
Essential: Pencil-type 15-watt soldering iron
Examples are RadioShack part 64-2051, McMaster-Carr catalog item
7016A34, or Xytronic model 252. See Figure 3-1. Soldering irons rated at
15 watts are less common than those that deliver 25 watts or more. Still,
the 15-watt size is desirable for the small-scale work you’ll be doing, and
greatly reduces the risk of damaging components by inflicting excess
heat.
Figure 3-1. The low wattage of this pencil- When comparing prices, remember that a plated tip, which costs a little
style soldering iron enables you to use it more, will last longer, will be easier to keep clean, and will conduct heat
safely on sensitive components, and the
sharp tip helps to apply heat selectively. more reliably than a plain copper tip. If the manufacturer’s specification
doesn’t mention a plated tip, the soldering iron probably doesn’t have
one.
Essential: General-duty soldering iron, 30 to 40 watts
Although most of the projects in this book entail small, heat-sensitive
components and thin wire, at some point you’re likely to want to make a
solder joint with larger components and/or thicker wire. A 15-watt solder-
ing iron will be unable to deliver enough heat. You should consider having
a larger soldering iron in reserve, especially because they are relatively
inexpensive.
Personally, I like the Weller Therma-Boost, shown in Figure 3-2, because
Figure 3-2. This higher-wattage soldering it has an extra button that delivers more heat on demand. This is useful
iron delivers the additional heat necessary when you want the iron to get hot quickly, or if you are trying to solder
for thicker wire or larger components. The
discoloration quickly occurs as a result very thick wire, which absorbs a lot of heat.
of everyday use and has no effect on the
capability of the iron, as long as the tip of
If you can’t find or don’t like the Weller, almost any 30-watt or 40-watt sol-
it is clean. dering iron will do. Check eBay or your local hardware store.
Essential: Helping hand
The so-called “helping hand” (or “third hand”) has two alligator clips that
hold components or pieces of wire precisely in position while you join
them with solder. Some versions of the “helping hand” also feature a mag-
nifying lens, a wire spiral in which you can rest your soldering iron, and a
little sponge that you use to clean the tip of your iron when it becomes
dirty. These additional features are desirable. Helping hands are available
from all electronics hobby sources. Examples are the catalog item HH55
from Elenco or model 64-2991 from RadioShack. See Figure 3-3.
Essential: Magnifying lens
No matter how good your eyes are, a small, handheld, powerful magnify-
Figure 3-3. The helping hand is fitted with ing lens is essential when you are checking solder joints on perforated
two alligator clips to hold your work. The board. The three-lens set in Figure 3-4 is designed to be held close to your
metal spiral is a safe place to holster a hot
soldering iron, and you use the sponge to
eye, and is more powerful than the large lens on a “helping hand.” The
wipe its tip. folding lens in Figure 3-5 stands on your workbench for hands-free opera-
tion. Both are available from RadioShack and similar items are stocked by
art supply stores and hobby shops. Plastic lenses are quite acceptable if
you treat them carefully.
96 Chapter 3
Shopping List: Experiments 12 Through 15
Figure 3-4. As long as you treat it carefully, Figure 3-5. This kind of folding magni-
a cheap set of plastic magnifying lenses is fier can stand on your desktop and is
perfectly acceptable. Handheld magnifica- useful for checking part numbers on tiny
tion is essential for inspecting the solder components.
joints that you make on perforated board.
Figure 3-6. These “minigrabber” add-ons for Figure 3-7. To make your own minigrabber Figure 3-8. Then screw a collar over the
meter leads make it much easier to measure meter leads, first attach a banana plug to protruding piece of wire, and screw on the
voltage or current. Push the spring-loaded a wire by sliding the wire through the cap, cap. The other end of the wire is soldered to
button, and a little copper hook slides out. into the plug, and out through a hole in a probe.
Attach it to a wire, release the button, and the side.
you have your hands free for other tasks. It’s
a mystery that meters are not supplied with
these grabbers as standard equipment.
Figure 3-10. To remove a Figure 3-11. An additional op- Figure 3-12. A set of small Figure 3-13. A safe and simple
solder joint, you can heat the tion for removing liquid solder screwdrivers is essential. additional stand for a hot
solder until it’s liquid, then is to soak it up in this copper soldering iron.
suck it up into this squeezable braid.
rubber bulb.
98 Chapter 3
Shopping List: Experiments 12 Through 15
I like Mitutoyo calipers, and the low-end model 505-611 (shown in Figure
3-19) does everything I need. You can find cheaper brands, but economiz-
ing on precision measuring tools may not be a wise policy in the long
term. The manufacturer’s site will show you all their available models, af-
ter which you can Google “Mitutoyo” to find retail sources.
Figure 3-17. You spin this countersink tool Figure 3-18. This pick-and-hook set is use- Figure 3-19. Calipers can be digital (which
like a hand crank to add just the right ful in many unexpected ways. automatically convert from millimeters to
amount of bevel to a hole, so that it will 1/64 inch to 1/1,000 inch), or analog like
accommodate a flat-head screw. these (so you never need to worry about a
dead battery).
Supplies
Solder
This is the stuff that you will melt to join components together on a per-
manent (we hope) basis. You need some very thin solder, size 0.022 inches,
for very small components, and thicker solder, 0.05 inches, for heavier items.
Avoid buying solder that is intended for plumbers, or for craft purposes such
as creating jewelry. A range of solder thicknesses is shown in Figure 3-20. You
want to make sure to get lead-free solder.
Electronics solder has a nonacidic rosin core that is appropriate for elec-
tronic components. Rolls of solder are available from all hobby-electronics
sources including All Electronics, RadioShack, and Jameco, or search for
“electronic solder” on Amazon.
Wire
You’ll need some stranded wire to make flexible external connections
Figure 3-20. Spools of solder in various
thicknesses.
with the circuit that you’ll be building. Look for 22-gauge stranded hook-
up wire, in red, black, and green, 10 feet (minimum) of each.
If you want to install the intrusion alarm after completing that project in
Experiment 15, you’ll need white-insulated two-conductor wire of the
type sold for doorbells or furnace controls. This is available by the foot
100 Chapter 3
Shopping List: Experiments 12 Through 15
from Lowe’s, Home Depot, Ace Hardware, and similar stores. You’ll decide
how much to buy after you measure the distances between the magnetic
sensor switches that you decide to install.
Heat-shrink tube
For use in conjunction with your heat gun, described previously. You’ll
need a range of sizes in any colors of your choice. See Figure 3-21. Check
RadioShack part 278-1627, other electronics suppliers, or your local hard-
ware store. Prices will vary widely. You can buy the cheapest.
Copper alligator clips
These absorb heat when you are soldering delicate components. The
Mueller BU-30C is a full-size solid copper alligator clip for maximum heat
absorption. RadioShack sells smaller clips (part number 270-373, shown
in Figure 3-22) that are suitable for tiny components.
Figure 3-21. Slide heat-shrink tubing over a Figure 3-22. These small clips absorb
bare joint and apply heat from a heat gun heat to protect components when you’re
to make a tight insulating seal around the soldering them.
joint.
Perforated board
When you’re ready to move your circuit from a breadboard to a more per-
manent location, you’ll want to solder it to a piece of perforated board,
often known as “prototyping board” but also called “perfboard.”
You need the type that has copper strips etched onto the back, in ex-
actly the same “breadboard layout” as the conductors hidden inside a
breadboard, so that you can retain the same layout of your components
when you solder them into place. Examples are RadioShack part 276-150
(shown in Figure 3-23) for small projects and part 276-170 (in Figure 3-24)
for larger projects, such as Experiment 15.
For very small projects in which you will connect components using their
wires alone, you need perfboard that isn’t etched with copper strips con-
necting the holes. I like the Twin Industries 7100 range (available from
Mouser.com) or Vectorboard from Newark Electronics, shown in Figure Figure 3-23. This perforated board has a
3-25. You use a saw to cut out as small a piece as you need. Cheaper op- pattern of copper traces similar to the
tions are RadioShack part 276-147 (shown in Figure 3-26), or PC-1 from All pattern inside a breadboard, so that you
can lay out the components with minimal
Electronics. These have little copper circles around each hole that are not risk of wiring errors, when you’re ready to
necessary for our purposes, but not a problem, either. create a permanently soldered version of
your project.
Figure 3-24. A larger example of perforated Figure 3-25. Plain perforated board (with Figure 3-26. A small piece of perforated
board with breadboard geometry. no copper traces) can be used for mount- board with individual copper solder pads
ing components when you want to do to assist you in mounting components.
point-to-point wiring.
Plywood
When you use a soldering iron, hot drops of solder tend to fall onto your
table or workbench. The solder solidifies almost instantly, can be difficult
to remove, and will leave a scar. Consider using a 2-foot square of half-inch
plywood to provide disposable protection. You can buy it precut at Home
Depot or Lowe’s.
Machine screws
To mount components behind a panel, you need small machine screws
(or “bolts”). They look nice if they have flat heads that fit flush against the
panel. I suggest stainless-steel machine screws, #4 size, in 1/2-, 5/8-, 3/4-,
and 1-inch lengths, 100 of each, plus 400 washers and 400 #4 locknuts
of the type that have nylon inserts, so that they won’t work loose. Check
McMaster-Carr for a large and reasonably priced selection.
Project boxes
A project box is just a small box (usually plastic) with a removable lid. You
mount your switches, potentiometers, and LEDs in holes that you drill
through the box, and you attach your circuit on a perforated board that
goes inside the box. Search All Electronics for “project box” or RadioShack
for “project enclosure.”
You need a box measuring approximately 6 inches long, 3 inches wide,
and 2 inches high, such as RadioShack part 270-1805. Anything similar
will do. I suggest you buy a couple other sizes as well, as they will be use-
ful in the future.
102 Chapter 3
Shopping List: Experiments 12 Through 15
Components
Power plugs, sockets, and binding posts
After you finish a project and put it in a box, you’ll need a convenient way
to supply it with power. Buy yourself a pair of insulated binding posts, such
as RadioShack part 274-661, shown in Figure 3-27. Also obtain a panel-
mounted power jack, size N, such as RadioShack part 274-1583, and DC
power plug, size N, such as RadioShack 274-1573. The plug-and-socket
pair is pictured in Figure 3-28. Figure 3-27. These terminals, also known
as binding posts, enable a solderless con-
Finally, you will need interconnects that are sized to fit a perforated board nection with wires that have stripped ends.
that is drilled at intervals of 1/10 inch. Sometimes known as “single inline Also available in black.
sockets and headers,” but also known as “boardmount sockets and pin-
strip headers,” they come in strips of 36 or more, and you can snip off as
many as you need. Examples are Mill-Max part numbers 800-10-064-10-
001000 and 801-93-050-10-001000, or 3M part numbers 929974-01-36-
RK and 929834-01-36-RK. You can buy them from the usual electronics
suppliers. Figure 3-29 shows headers before and after being snapped into
small sections. Make sure that the interconnects have a terminal spacing
of 0.1 inch.
Battery Figure 3-28. The socket on the right can be
After you complete Experiment 15 at the end of this section of the book, mounted in a project box to receive power
if you want to use the project on a practical basis, you’ll need a 12-volt from the plug on the left.
battery. Search online for “12v battery” and you’ll find many sealed, re-
chargeable lead-acid batteries that are designed for alarm systems, some
measuring as small as 1×2×3-inch and costing under $10. You need a
charger with it, which will probably cost you about $10.
Switches and relays
You will need the same DPDT relay and the same SPDT toggle switch that
were mentioned in Chapter 2 shopping list.
For Experiment 15, you’ll need magnetic switches that you can apply to
doors or windows, such as the Directed model 8601, available from doz- Figure 3-29. Single inline sockets (top) and
ens of sources online. headers (middle) allow you to make very
compact plug-and-socket connections
Also you will need a DPDT pushbutton switch, ON-(ON) type, with to a PC board. They can be sawn, cut, or
solder terminals. Examples are model MPG206R04 by Tyco or model snapped into smaller sections (bottom).
MB2061SS1W01-RO by NKK (with optional cap). Or search eBay for “DPDT The terminals are 0.1 inch apart.
pushbutton.”
Diodes
Buy at least half-a-dozen red 5 mm LEDs rated for approximately 2 volts,
such as the Optek part number OVLFR3C7, Lumex part number SSL-LX-
5093IT, or Avago part HLMP-D155. Buy half-a-dozen similar green LEDs at
the same time.
In addition, you’ll need a signal diode, type 1N4001 (any brand will do).
Figure 3-30 shows an example, highly magnified. They’re cheap, and likely
to be useful in the future, so buy 10 of them.
Loudspeaker
To complete the project in Experiment 15, you’ll need a loudspeaker small
enough to fit inside your project box but louder than the 1-inch speaker
Soldering Irons Get Hot! that you used previously. It should be 2 inches or 2.5 inches (50 to 60 mm)
Please take these basic precautions: in diameter. If you can find a 100Ω speaker, it will give you more output,
but an 8Ω speaker will be acceptable.
Use a proper stand (such as the one
incorporated in your helping hands)
to hold your soldering iron. Don’t
leave it lying on a workbench.
Experiment 12: Joining Two Wires Together
If you have infants or pets, remember Your adventure into soldering begins with the prosaic task of joining one wire
that they may play with, grab, or to another, but will lead quickly to creating a full electronic circuit on perfo-
snag the wire to your soldering iron. rated board. So let’s get started!
They could injure themselves (or you).
You will need:
Be careful never to rest the hot tip
of the iron on the power cord that • 30-watt or 40-watt soldering iron
supplies electricity to the iron. It can
• 15-watt pencil-type soldering iron
melt the plastic in seconds and cause
a dramatic short circuit. • Thin solder (0.022 inches or similar)
If you drop a soldering iron, don’t be • Medium solder (0.05 inches or similar)
a hero and try to catch it. Most likely
you will grab the hot part, which • Wire strippers and cutters
hurts. (I speak from experience.)
When you burn your hand, you will • “Helping hand” gadget to hold your work
instinctively let go of the iron, so you
• Shrink-wrap tubing, assorted
may as well let it drop freely without
the intermediate step of burning • Heat gun
yourself while it’s on its way to the
floor. Naturally, you should pick it • Something to protect your work area from drops of solder
up quickly after it does hit the floor,
but by then you will have gained the
necessary time in which to make a Your First Solder Joint
sensible decision to grab it by the
We’ll start with your general-duty soldering iron—the one rated for 30 or 40
cool end.
watts. Plug it in, leave it safely in its holder, and find something else to do for
Always bear in mind that others in five minutes. If you try to use a soldering iron without giving it time to get fully
your home are more at risk of hurting hot, you will not make good joints.
themselves on a soldering iron than
you are, because they won’t know Strip the insulation from the ends of two pieces of 22-gauge solid wire and
that it’s hot. Most soldering irons clamp them in your helping hand so that they cross each other and touch each
have no warning lights to tell you other, as shown in Figure 3-31.
that they’re plugged in. As a general
rule, always assume that a soldering To make sure that the iron is ready, try to melt the end of a thin piece of solder
iron is hot, even if it’s unplugged. It on the tip of the iron. The solder should melt instantly. If it melts slowly, the
may retain sufficient heat to burn iron isn’t hot enough yet.
you for longer than you expect.
104 Chapter 3
Experiment 12: Joining Two Wires Together
4. Unclamp the wires and try to tug them apart. Tug hard! If they defeat
your best attempts to separate them, the wires are electrically joined and
should stay joined. If you didn’t make a good joint, you will be able to
separate the wires relatively easily, probably because you didn’t apply
enough heat or enough solder to connect them.
The reason I asked you to begin by using the higher-powered soldering iron is
that it delivers more heat, which makes it easier to use.
Figure 3-35. This and the preceding three Figure 3-36. The completed joint should be
figures illustrate four steps to making a shiny, uniform, and rounded in shape.
solder joint: apply heat to the wires, bring
in the solder while maintaining the heat,
wait for the solder to start to melt, and
wait a moment longer for it to form a com-
pletely molten bead. The whole process
should take between 4 and 6 seconds.
Background
Soldering myths
Myth #1: Soldering is very difficult. Myth #3: Soldering is hazardous.
Millions of people have learned how to do it, and statis- A soldering iron is less hazardous than the kind of iron
tically, you are unlikely to be less coordinated than all that you might use to iron a shirt, because it delivers
of them. I have a lifelong problem with a tremor in my less heat. In fact, in my experience, soldering is safer
hands that makes it difficult for me to hold small things than most activities in a typical home or basement
steadily. I also get impatient with repetitive detail work. workshop. That doesn’t mean you can be careless!
If I can solder components, almost anyone should be
able to.
Myth #2: Soldering involves poisonous chemicals.
Modern solder contains no lead. You should avoid
inhaling the fumes for prolonged periods, but that also
applies to everyday products such as bleach and paint.
If soldering was a significant health hazard, we should
have seen a high death rate among electronics hobby-
ists decades ago.
Soldering alternatives
As recently as the 1950s, connections inside electronic ap- preheated circuit board where chips have been inserted. A
pliances such as radio sets were still being hand-soldered by masking technique prevents the solder from sticking where
workers on production lines. But the growth of telephone it isn’t wanted.
exchanges created a need for a faster way to make large
Today, surface-mount components (which are significantly
numbers of rapid, reliable point-to-point wiring connec-
smaller than their through-hole counterparts) are glued to
tions, and “wire wrap” became a viable alternative.
a circuit board with a solder paste, and the entire assembly
In a wire-wrapped electronics project, components are is then heated, melting the paste to create a permanent
mounted on a circuit board that has long, gold-plated, connection.
sharp-cornered square pins sticking out of the rear. Special
silver-plated wire is used, with an inch of insulation stripped
from its ends. A manual or power-driven wire-wrap tool
twirls the end of a wire around one of the pins, applying
sufficient tension to “cold-weld” the soft silver plating of
the wire to the pin. The wrapping process exerts sufficient
pressure to make a very reliable joint, especially as 7 to 9
turns of wire are applied, each turn touching all four corners
of the pin.
During the 1970s and 1980s, this system was adopted by
hobbyists who built their own home computers. A wire-
wrapped circuit board from a hand-built computer is shown
in Figure 3-37. The technique was used by NASA to wire the
computer in the Apollo spacecraft that went to the moon,
but today, wire-wrapping has few commercial applications. Figure 3-37. This picture shows some of the wire-wrapping in
Steve Chamberlin’s custom-built, retro 8-bit CPU and com-
The widespread industrial use of “through-hole” compo- puter. “Back in the day,” connecting such a network of wires
nents, such as the chips on early desktop computers, en- with solder joints would have been unduly time-consuming and
couraged development of wave soldering, in which a wave prone to faults. Photo credit: Steve Chamberlin.
or waterfall of molten solder is applied to the underside of a
106 Chapter 3
Experiment 12: Joining Two Wires Together
Tools
Figure 3-43. This and the preceding three Figure 3-44. The finished joint has enough
figures show how joining two wires that solder for strength, but not so much solder
are parallel is more difficult, and the that it will prevent heat-shrink tubing from
low-wattage, pencil-type soldering iron will sliding over it.
require longer to heat them sufficiently for
a good joint. Thinner solder can be used.
108 Chapter 3
Experiment 12: Joining Two Wires Together
Theory Tools
Figure 3-45. With only a small surface Figure 3-46. A larger area of contact
area of contact between the iron and between the soldering iron and its target
the working surface, an insufficient will greatly increase the heat transfer.
amount of heat is transferred.
Adding Insulation
After you’ve succeeded in making a good inline solder connection between
Heat Guns Get Hot, Too! two wires, it’s time for the easy part. Choose some heat-shrink tubing that is
Notice the chromed steel tube at the just big enough to slide over the joint with a little bit of room to spare.
business end of your heat gun. Steel
costs more than plastic, so the manu-
facturer must have put it there for a
good reason—and the reason is that
the air flowing through it becomes so
hot that it would melt a plastic tube.
The metal tube stays hot enough to
burn you for several minutes after
you’ve used it. And, as in the case of
soldering irons, other people (and
pets) are vulnerable, because they
won’t necessarily know that the heat
gun is hot. Most of all, make sure that
no one in your home ever makes the
mistake of using a heat gun as a hair
dryer (Figure 3-47).
This tool is just a little more hazard-
ous than it appears.
Figure 3-47. Other members of your family should understand that although a heat gun
looks like a hair dryer, appearances may be deceptive.
Slide the tubing along until the joint is centered under it, hold it in front of
your heat gun, and switch on the gun (keeping your fingers away from the
blast of superheated air). Turn the wire so that you heat both sides. The tubing
should shrink tight around the joint within half a minute. If you overheat the
tubing, it may shrink so much that it splits, at which point you must remove
it and start over. As soon as the tubing is tight around the wire, your job is
done, and there’s no point in making it any hotter. Figures 3-48 through 3-50
show the desired result. I used white tubing because it shows up well in photo-
graphs. Different colors of heat-shrink tubing all perform the same way.
Figure 3-48. Slip the tubing over your wire Figure 3-49. Apply heat to the tubing. Figure 3-50. Leave the heat on the tubing
joint. until it shrinks to firmly cover the joint.
110 Chapter 3
Experiment 12: Joining Two Wires Together
I suggest you next practice your soldering skills on a couple of practical proj-
ects. In the first one, you can add color-coded, solid-core wires to your AC
adapter, and in the second one, you can shorten the power cord for a laptop
power supply. You can use your larger soldering iron for both of these tasks,
because neither of them involves any heat-sensitive components.
Modifying an AC Adapter
In the previous chapter, I mentioned the irritation of being unable to push the
wires from your AC adapter into the holes of your breadboard. So, let’s fix this
right now:
1. Cut two pieces of solid-conductor 22-gauge wire—one of them red, the
other black or blue. Each should be about 2 inches long. Strip a quarter-
inch of insulation from both ends of each piece of wire.
2. Trim the wire from your AC adapter. You need to expose some fresh, clean
copper to maximize your chance of getting the solder to stick.
I suggest that you make one conductor longer than the other to minimize
the chance of the bare ends touching and creating a short circuit. Use
your meter, set to DC volts, if you have any doubt about which conductor
is positive.
Solder the wires and add heat-shrink tubing as you did in the practice session.
The result should look like Figure 3-51.
Choose the Right Tubing
If you use heat-shrink tubing on 110v
AC cord, as is being done in this ex-
periment, make sure you use tubing
that’s been rated for 110v use.
Figure 3-51. Solid-core color-coded wires, soldered onto the wires from an AC adapter, pro-
vide a convenient way to feed power to a breadboard. Note that the wires are of differing
lengths to reduce the risk of them touching each other.
After searching exhaustively I couldn’t find any laptop power cables shorter
than 3 feet, so I decided to shorten one myself. If you feel no need to do this,
you should try the following procedure on an old extension cord, just as an
exercise. You do need to go through these steps to acquire some practice in
soldering heavier, stranded wire and using heat-shrink tubing:
1. Use your wire cutters to chop the wire, and then a utility knife to split the
two conductors, with one shorter than the other. When splicing a pow-
er cord or similar cable containing two or more conductors, it’s good to
avoid having the joints opposite each other. They fit more snugly if they
are offset, and there’s less risk of a short circuit if a joint fails.
112 Chapter 3
Experiment 12: Joining Two Wires Together
5. Use your helping hand to align the first joint. Push the two pieces of wire
together so that the strands intermingle, and then squeeze them tight
between finger and thumb, so that there are no little bits sticking out. A
stray strand of wire can puncture heat-shrink tubing when the tubing is
hot and soft and is shrinking around the joint.
6. The wire that you’re joining is much heavier than the 22-gauge wire that
you worked with previously, so it will suck up more heat, and you must
touch the soldering iron to it for a longer time. Make sure that the solder
flows all the way into the joint, and check the underside after the joint
is cool. Most likely you’ll find some bare copper strands there. The joint
should become a nice solid, rounded, shiny blob. Keep the heat-shrink
tubing as far away from the joint as possible while you’re using the solder-
ing iron, so that heat from the iron doesn’t shrink the tubing prematurely,
preventing you from sliding it over the joint later.
7. When the joint has cooled, slide the heat-shrink tubing over it, and apply
the heat gun. Now repeat the process with the other conductor. Finally,
slide the larger piece of tubing over the joint. You did remember to put
the large tubing onto the wire at the beginning, didn’t you?
Figures 3-59 through 3-65 show the steps all the way through to the end.
If you have completed the soldering exercises so far, you now have sufficient
basic skills to solder your first electronic circuit. But first, I want you to verify
the vulnerability of components to heat.
Figure 3-65. Completion of the shortened
power cord for a laptop power supply.
114 Chapter 3
Experiment 13: Broil an LED
Throw away your burned-out LED. Substitute a new one, connected as before,
but add a full-size copper alligator clip to one of the leads up near the body of
the LED, as shown in Figure 3-68. Press the tip of your 30-watt or 40-watt sol-
dering iron against the lead just below the alligator clip. This time, you should
be able to hold the powerful soldering iron in place for a full two minutes
without burning out the LED.
Imagine the heat flowing out through the tip of your soldering iron, into the
wire that leads to the LED—except that the heat meets the alligator clip along
the way, as shown in Figure 3-69. The clip is like an empty vessel waiting to
be filled. It offers much less resistance to heat than the remainder of the wire
leading to the LED, so the heat prefers to flow into the copper clip, leaving the
LED unharmed. At the end of your experiment, if you touch the clip, you’ll find
that it’s hot, while the LED remains relatively cooler.
Figure 3-68. When a copper alligator clip is
The alligator clip is known as a heat sink, and it should be made of copper, used as a heat sink, you should be able to
apply a 30-watt soldering iron (below the
because copper is one of the best conductors of heat. clip) without damaging the LED.
Because the 15-watt soldering iron failed to harm the LED, you may conclude
that the 15-watt iron is completely safe, eliminating all need for a heat sink.
Well, this may be true. The problem is, you don’t really know whether some
semiconductors may be more heat-sensitive than LEDs. Because the con-
sequences of burning out a component are so exasperating, I suggest you
should play it safe and use a heat sink in these circumstances:
• If you apply 15-watt iron extremely close to a semiconductor for 20 sec-
onds or more. Heat Sink
• If you apply a 30-watt iron near resistors or capacitors for 10 seconds or Heat Flow
more. (Never use it near semiconductors.)
• If you apply a 30-watt iron near anything meltable for 20 seconds or more. Soldering Iron
Meltable items include insulation on wires, plastic connectors, and plastic
components inside switches.
Fundamentals
Figure 3-70
Figure 3-71. Either this type of perforated board or the type in Fig- Figure 3-72. Perforated board etched with copper in variants of
ure 3-70 can be used for point-to-point wiring in Experiment 14. a breadboard layout. This example is appropriate for Experi-
ment 15.
116 Chapter 3
Experiment 14: A Pulsing Glow
Look back at the original schematic in Experiment 11, on page 82. Refresh your
memory about the way it worked. The capacitor charges through a resistor un-
til it has enough voltage to overcome the internal resistance in the PUT. Then Time
the capacitor discharges through the PUT and flashes the LED. Figure 3-73
If you drew a graph of the light coming out of the LED, it would be a thin, square-
shaped pulse, as shown in Figure 3-73. How can we fill it out to make it more like
the curve in Figure 3-74, so that the LED fades gently on and off, like a heartbeat?
One thing is obvious: the LED is going to be emitting a greater total amount of
Brightness
light in each cycle. Therefore, it’s going to need more power. This means that
C1, in Figure 3-75, must be a larger capacitor.
When we have a larger capacitor, it takes longer to charge. To keep the flashes Time
reasonably frequent, we’ll need a lower-value resistor for R1 to charge the ca-
pacitor quickly enough. In addition, reducing the values of R2 and R3 will pro- Figure 3-74. The original PUT oscillator
circuit in Experiment 11 made the LED
gram the PUT to allow a longer pulse. emit sharp, short flashes. The upper graph
shows what we might find if we measured
Most important, I want to discharge the capacitor through a resistor to make light output over time. The second graph
the onset of the pulse gradual instead of sudden. Remember, when you have shows a gentler onset to each flash, fol-
a resistor in series with a capacitor, the capacitor not only charges more slowly, lowed by a slow fade-out. Capacitors can
but discharges more slowly. be used to create this effect.
Figure 3-75 shows these features. Compare it with Figure 2-103 on page 85. R1
C1 is now 33K instead of 470K. R2 and R3 are reduced to 1K. R4 also is 1K, to so
that the capacitor takes longer to discharge through it. And C1 is now 100 µF
instead of 2.2 µF.
Assemble this circuit on a breadboard, and compare the results when you in-
R4 clude R4 or bypass it with a plain piece of jumper wire. It softens the pulse a
R1 bit, but we can work on it some more. On the output side of the PUT, we can
add another capacitor. This will charge itself when the pulse comes out of the
PUT, and then discharge itself gradually through another resistor, so that the
light from the LED dies away more slowly.
R2 R3 Figure 3-76 shows the setup. C2 is large—220 µF—so it sucks up the pulse that
comes out of the PUT, and then gradually releases it through 330Ω resistor R5
Q1 and the LED. You’ll see that the LED behaves differently now, fading out inside
of blinking off. But the resistances that I’ve added have dimmed the LED, and
to brighten it, you should increase the power supply from 6 volts to 9 volts.
Figure 3-75. The first step toward creating Remember that a capacitor imposes a smoothing effect only if one side of it
a gentler flashing effect is to use a larger is grounded to the negative side of the power supply. The presence of the
capacitor for C1 and discharge it through
negative charge on that side of the capacitor attracts the positive pulse to the
a resistor, R4. Lower-value resistors are
necessary to charge the capacitor rapidly other side.
enough.
I like the look of this heartbeat effect. I can imagine a piece of wearable elec-
R1: 33K tronic jewelry that pulses in this sensual way, very different from the hard-
R2: 1K edged, sharp-on-and-off of a simple oscillator circuit. The only question is
R3: 1K whether we can squeeze the components into a package that is small enough
R4: 1K
C1: 100 µF electrolytic to wear.
Q1: 2N6027
C1
9V
DC
R4
R1
R2 R3
Q1
Figure 3-76. The second step toward a C2
gentler flashing effect is to add another
capacitor, C2, which charges quickly with
each pulse and then discharges slowly
through R5 and the LED below it.
R5
Same components as before, plus:
R5: 330Ω Figure 3-77. On a dark night in a rural area, the
C2: 220 µF electrolytic heartbeat flasher may be attractive in unexpected
Power supply increased to 9 volts ways.
118 Chapter 3
Experiment 14: A Pulsing Glow
C1
R4
R1 C2
R2
R3 L R
R5
Figure 3-78. This layout of components replicates their connections in the schematic
diagram while squeezing them into a minimal amount of space.
The answer is to put it on a substrate, which is one of those terms that people in
the electronics field like to use, perhaps because it sounds more technical than L R
“perfboard.” But perforated board is what we need, and Figure 3-79 shows the
components transferred onto a piece of board measuring just 1 inch by 0.8 inch.
The center version of this diagram uses dotted lines to show how the compo-
nents will be connected with each other underneath the board. Mostly the
leads that stick out from underneath the components will be long enough to
make these connections.
Finally, the bottom version of the perfboard diagram shows the perfboard
flipped left-to-right (notice the L and the R have been transposed to remind
R L
you, and I’ve used a darker color to indicate the underside of the board).
Orange circles indicate where solder joints will be needed.
The LED should be unpluggable, because we may want to run it at some dis- Figure 3-79. Perforated board can be used
tance from the circuit. Likewise the power source should be unpluggable. For- to support the layout of components. Their
leads are soldered together under the
tunately we can buy miniature connectors that fit right into the perforated board to create the circuit. The middle dia-
board. You may have to go to large online retail suppliers such as Mouser.com gram shows the wires under the board as
for these. Some manufacturers call them “single inline sockets and headers,” dashed lines. The bottom diagram shows
while others call them “boardmount sockets and pinstrip headers.” Refer back the board from underneath, flipped left to
right. Orange circles indicate where solder
to Figure 3-29 and check the shopping list for more details. joints will be necessary.
This is a very compact design that will require careful work with your pencil-
style soldering iron. Because a piece of perforated board as small as this will
tend to skitter around, I suggest that you apply your miniature vise to one end
to anchor it with some weight while still allowing you to turn it easily.
When I’m working on this kind of project, I like to place it (with the vise at-
tached) on a soft piece of polyurethane foam—the kind of slab that is nor-
mally used to make a chair cushion. The foam protects the components from
damage when the board is upside-down, and again helps to prevent the work
from sliding around unpredictably.
Step by Step
Here’s the specific procedure for building this circuit:
1. Cut the small piece of perfboard out of a sheet that has no copper traces
on it. You can cut the section using your miniature hobby saw, or you may
be able to snap the board along its lines of holes, if you’re careful. Alter-
natively, use a small ready-cut piece of perfboard with copper circles on it
that are not connected to one another. You’ll ignore the copper circles in
this project. (In the next experiment, you’ll deal with the additional chal-
lenge of making connections between components and copper traces on
perforated board.)
2. Gather all the components and carefully insert them through holes in the
board, counting the holes to make sure everything is in the right place.
Flip the board over and bend the wires from the components to anchor
them to the board and create connections as shown. If any of the wires
isn’t long enough, you’ll have to supplement it with an extra piece of
22-gauge wire from your supply. You can remove all the insulation, as we’ll
be mounting the perfboard on a piece of insulating plastic.
3. Trim the wires approximately with your wire cutters.
4. Make the joints with your pencil soldering iron. Note that in this circuit,
Figure 3-80. Components mounted on a you are just joining wires to each other. The components are so close to-
piece of perforated board.
gether that they’ll prevent each other from wiggling around too much. If
you are using board with copper pads (as I did), and some solder connects
with them, that’s OK—as long as it doesn’t creep across to the neighbor-
ing component and create a short circuit.
5. Check each joint using a close-up magnifying glass, and wiggle it with
pointed-nosed pliers. If there isn’t enough solder for a really secure joint,
reheat it and add more. If solder has created a connection that shouldn’t
be there, use a utility knife to make two parallel cuts in the solder, and
scrape away the little section between them.
Generally, I insert three or four components, trim the wires approximately, sol-
der them, trim their wires finally, then pause to check the joints and the place-
ment. If I solder too many components in succession, there’s a greater risk of
missing a bad joint, and if I make an error in placing a component, undoing
Figure 3-81. The assembly seen from it will be much more problematic if I have already added a whole lot more
below. The copper circles around the holes
are not necessary for this project. Some of components around it.
them have picked up some solder, but this
is irrelevant as long as no unintentional
Figures 3-80 and 3-81 show the version of this project that I constructed, be-
short circuits are created. fore I trimmed the board to the minimum size.
120 Chapter 3
Experiment 14: A Pulsing Glow
1. You can put the battery in a pocket, and mount the flasher on the outside
of the pocket, with a thin wire penetrating the fabric. Note that the tiny
power connector on the perforated board will accept two 22-gauge wires
if they are solid core, or if they are stranded (like the wires from a 9-volt
battery connector) but have been thinly coated with solder.
2. You could mount the battery inside the crown of a baseball cap, with the
flasher on the front.
3. You can put together three 3-volt button batteries in a stack, held in some
kind of plastic clip. If you try this option, it may not be a good idea to try
to solder wire to a battery. You will heat the liquid stuff inside the battery,
which may not be good for it, and may not be good for you if the liquid
starts boiling and the battery bursts open. Also, solder doesn’t stick easily
to the metallic finish on most battery terminals.
Most LEDs create a sharply defined beam of light, which you may want to dif-
fuse to make it look nicer. One way to do this is to use a piece of transparent
acrylic plastic, at least 1/4 inch thick, as shown in Figure 3-82. Sandpaper the
front of the acrylic, ideally using an orbital sander that won’t make an obvious
pattern. Sanding will make the acrylic translucent rather than transparent.
Drill a hole slightly larger than the LED in the back of the acrylic. Don’t drill all
the way through the plastic. Remove all fragments and dust from the hole by
blasting some compressed air into it, or by washing it if you don’t have an air
compressor. After the cavity is completely dry, get some transparent silicone
caulking or mix some clear five-minute epoxy and put a drop in the bottom of
the hole. Then insert the LED, pushing it in so that it forces the epoxy to ooze
around it, making a tight seal. See Figure 3-82.
Figure 3-82. This cross-sectional view shows a sheet of transparent acrylic in which a hole
has been drilled part of the way from the back toward the front. Because a drill bit creates
a hole with a conical shape at the bottom, and because the LED has rounded contours,
transparent epoxy or silicone caulking can be injected into the hole before mounting the
LED.
Try illuminating the LED, and sand the acrylic some more if necessary. Finally,
you can decide whether to mount the circuit on the back of the acrylic, or
whether you want to run a wire to it elsewhere.
122 Chapter 3
Experiment 14: A Pulsing Glow
Because the LED will flash at about the speed of a human heart while the per-
son is resting, it may look as if it’s measuring your pulse, especially if you mount
it on the center of your chest or in a strap around your wrist. If you enjoy hoax-
ing people, you can suggest that you’re in such amazingly good shape, your
pulse rate remains constant even when you’re taking strenuous exercises.
To make a good-looking enclosure for the circuit, I can think of options rang-
ing from embedding the whole thing in clear epoxy to finding a Victorian-style
locket. I’ll leave you to consider alternatives, because this is a book about elec-
tronics rather than handicrafts.
However, I will address one final issue: how long will this gadget continue
flashing?
If you check the following section “Essentials: Battery life,” you’ll find that a reg-
ular alkaline 9-volt battery should keep the LED flashing for about 50 hours.
ESSENTIALS
Battery life
Any time you finish a circuit that you intend to run from a battery, you’ll want
to calculate the likely battery life. This is easily done, because manufacturers
rate their batteries according to the “ampere hours” they can deliver. Keep the
following in mind:
• The abbreviation for amp-hours is Ah, sometimes printed as AH. Milliampere-
hours are abbreviated mAh.
• The rating of a battery in amp-hours is equal to the current, in amps, multi-
plied by the number of hours that the battery can deliver it.
Thus, in theory 1 amp-hour can mean 1 amp for 1 hour, or 0.1 amp for 10 hours,
or 0.01 amp for 100 hours—and so on. In reality, it’s not as simple as this, be-
cause the chemicals inside a battery become depleted more quickly when you
draw a heavy current, especially if the battery gets hot. You have to stay within
limits that are appropriate to the size of the battery.
For instance, if a small battery is rated for 0.5 amp-hours, you can’t expect to
draw 30 amperes from it for 1 minute. But you should be able to get 0.005 amps
(i.e., 5 milliamps) for 100 hours without any trouble. Remember, though, that
the voltage delivered by a battery will be greater than its rated voltage when
the battery is fresh, and will diminish below its rated voltage while the battery is
delivering power.
According to some test data that I trust (I think they are a little more realistic
than the estimates supplied by battery manufacturers), here are some numbers
for typical batteries:
• Typical 9 volt alkaline battery: 0.3 amp-hours, while delivering 100 mA.
• Typical AA size, 1.5-volt alkaline battery: 2.2 amp-hours, while delivering
100 mA.
• Rechargeable nickel-metal hydride battery: about twice the endurance of a
comparably sized alkaline battery.
• Lithium battery: maybe three times the endurance of an alkaline battery.
Background
Maddened by measurement
Throughout most of this book, I’ve mostly used measurements in inches,
although sometimes I’ve digressed into the metric system, as when referring to
“5-mm LEDs.” This isn’t inconsistency on my part; it reflects the conflicted state
of the electronics industry, where you’ll find inches and millimeters both in daily
use, often in the very same data sheet.
The United States is the only major nation still using the old system of units
that originated in England. (The other two holdouts are Liberia and Myanmar,
according to the CIA’s World Factbook.) Still, the United States has led many
advances in electronics, especially the development of silicon chips, which have
contacts spaced 1/10 inch apart. These standards became firmly established,
and show no sign of disappearing.
To complicate matters further, even in the United States, you can encounter two
incompatible systems for expressing fractions of an inch. Drill bits, for instance,
are measured in multiples of 1/64 inch, while metal thicknesses may be mea-
sured in decimals such as 0.06 inch (which is approximately 1/16 inch).
The metric system is not necessarily more rational than the U.S. system. Origi-
nally, when the metric system was formally introduced in 1875, the meter was
defined as being 1/10,000,000 of the distance between the North Pole and the
equator, along a line passing through Paris—a quixotic, Francocentric conceit.
Since then, the meter has been redefined three times, in a series of efforts to
achieve greater accuracy in scientific applications.
As for the usefulness of a 10-based system, moving a decimal point is certainly
simpler than doing calculations in 64ths of an inch, but the only reason we
count in tens is because we happen to have evolved with that number of digits
on our hands. A 12-based system would really be more convenient, as numbers
would be evenly divisible by 2 and 3.
As we’re stuck with the whimsical aspects of length measurement, I’ve created
the charts in Figures 3-83 and 3-84 to assist you in going from one system to
another. From these you will see that when you need to drill a hole for a 5 mm
LED, a 3/16-inch drill bit is about right. (In fact, it results in a better, tighter fit
than if you drill an actual 5 mm hole.)
124 Chapter 3
Experiment 14: A Pulsing Glow
Figure 3-83. Because units of measurement are not standardized in electronics, conversion is often necessary. The chart on the right is a
5x magnification of the bottom section of the chart on the left.
Figure 3-84. This chart allows conversion between hundredths of an inch, conventional U. S. fractions of an inch, and fractions expressed
in thousandths of an inch.
126 Chapter 3
Experiment 15: Intrusion Alarm Revisited
Download at WoweBook.com
N
S
N
S
Figure 3-86. This cutaway diagram shows a reed switch (bottom) and the magnet that
activates it (top), inside an alarm sensor. The switch contains two flexible magnetized
strips, the upper one with its south pole adjacent to an electrical contact, the lower one
with its north pole adjacent to an electrical contact. When the south pole of the magnet
approaches the switch, the magnetic force (shown as dashed lines) repels the south
contact and attracts the north contact, causing them to snap together. Two screws on the
outside of the casing are connected with the strips inside.
128 Chapter 3
Experiment 15: Intrusion Alarm Revisited
10K 680
Switches
Q1
activated
by opened
doors or
windows
1K
Figure 3-88. A network of switches, wired in series, can be substituted for the single switch
in Figure 3-87. Now any one switch will break continuity and trigger the transistor.
I have shown the switches open, because that’s the way the schematic for a
switch is drawn, but imagine them all closed. The base of the transistor will
now be supplied through the long piece of wire connecting all the closed
switches, and the LED will stay dark. Now if just one switch is opened, or if
anyone tampers with the wire linking them, the base of the transistor loses its
connection to negative power, at which point the transistor conducts power
and the LED lights up.
While all the switches remain closed, the circuit is drawing very little current—
probably about 1.1 mA. So you could run it from a typical 12-volt alarm battery.
Now suppose we swap out the LED and put a relay in there instead, as shown
in Figure 3-89. I don’t mind using a relay in this location, because the relay will
not be “always on.” It will normally be off, and will draw power only when the
alarm is triggered.
12V
DC
10K
Switches
Q1
activated
by opened
doors or
windows
1K
R1
Figure 3-89. If the LED and 680Ω resistor shown in are removed, and a relay takes their
place, the relay will be activated when any switch in the sensor network is opened.
Try one of the 12-volt relays that you used previously. You should find that
when you open the switch, the relay is energized. When you close the switch,
the relay goes back to sleep. Note that I eliminated the 680Ω resistor from the
circuit, because the relay doesn’t need any protection from the 12-volt power
supply.
130 Chapter 3
Experiment 15: Intrusion Alarm Revisited
Self-Locking Relay
There’s only one remaining problem: we want the alarm to continue making
noise even after someone who has opened a door or window closes it again
quickly. In other words, when the relay is activated, it must lock itself on.
One way to do this would be by using a latching relay. The only problem is that
we would then need another piece of circuitry to unlatch it. I prefer to show
you how you can make any relay keep itself switched on after it has received
just one jolt of power. This idea will be useful to you later in the book as well.
The secret is to supply power to the relay coil through the two contacts inside
the relay that are normally open. (Note that this is exactly opposite to the relay
oscillator, which supplied power to its coil through the contacts that were nor-
mally closed. That setup caused the relay to switch itself off almost as soon as
it switched itself on. This setup causes the relay to keep itself switched on, as
soon as it has been activated.)
In Figure 3-90, the four schematics illustrate this. You can imagine them as be-
ing like frames in a movie, photographed microseconds apart. In the first pic-
ture, the switch is open, the relay is not energized, and nothing is happening.
In the second, the switch has been closed to energize the coil. In the third, the
coil has pulled the contact inside the relay, so that power now reaches the coil
via two paths. In the fourth, the switch has been opened, but the relay is still
powering its own coil through its contacts. It will remain locked in this state
until the power is disconnected.
12V 12V 12V 12V
DC DC DC DC
Figure 3-90. This sequence of schematics shows the events that occur when a relay is
energized. Initially, the switch is open. Then the switch is closed, activating the relay. The
relay then powers itself through its own internal contacts. The relay remains energized
even after the switch is opened again. Power switched by the relay can be taken from the
circuit at point A.
All we need to do, to make use of this idea, is to substitute the transistor for the
on/off switch, and tap into the circuit at point A, running a wire from there to
the noisemaking module.
Figure 3-91 shows how that would work. When the transistor is activated by
any of the network of sensor switches, as previously explained, the transistor
conducts power to the relay. The relay locks itself on, and the transistor be-
comes irrelevant.
Power to
noise
maker
Power 12V
DC
Mag. Switches
10K
Locking Relay
Q1
Figure 3-91. The self-locking relay depicted in has been incorporated in the alarm circuit,
so that if any switch in the network is opened, the relay will continue to power the noise
Loudspeaker maker even if the switch is closed again.
Because I’ve been adding pieces to the original alarm noisemaker circuit, I’ve
Figure 3-92. This block diagram previously
shown in Figure 2-112 on page 90 has been updated the block diagram from Figure 2-112 to show that we can still break
updated to include the magnetic-switch this down into modules with simple functions. The revised diagram is shown
network and locking-relay control system. in Figure 3-92.
132 Chapter 3
Experiment 15: Intrusion Alarm Revisited
from positive to negative, as shown by its arrow symbol. If current tries to flow
in the opposite direction, the diode blocks it. The only price you pay for this
service is that the diode imposes a small voltage drop on electricity flowing in
the “OK” direction.
So now, positive flow can pass from the transistor, through the diode, to the
relay coil, to get things started. The relay then supplies itself with power, but
the diode prevents the positive voltage from getting back into the transistor
the wrong way.
Perhaps a more elegant solution to the problem is to connect the NO leg of
the relay via a 10k resistor to the base connection. When the relay is not ener-
gized, the NO leg is inert and simply behaves as a parasitic capacitance on the
node. When the relay becomes energized, the NO leg shunts +12V through
the common terminal via a 10k resistor into the base of the transistor. In this
circuit configuration, the transistor is never exposed to a potentially harmful
voltage and you are not depending on leakage currents of non-ideal elements
to protect devices.
However, I needed an opportunity to introduce you to the concept of diodes.
You can check the following section “Essentials: All about diodes” to learn
more.
Power to
noise
maker
12V
DC
10K
Q1
Switches D1
activated
by opened
doors or
windows
1K
R1
Figure 3-93. Diode D1 has been added to protect the emitter of Q1 from positive voltage
when the relay is energized.
Essentials
Figure 3-94. Either of these schematic symbols may be used to represent a diode,
but the one on the right is more common than the one on the left.
134 Chapter 3
Experiment 15: Intrusion Alarm Revisited
Q1
S1
R2
D1
To
sensor
switches
Figure 3-95. The schematic that was developed in the previous pages can be emulated
with components on a breadboard, as shown here. S1 is a DPDT relay. Wires to the sensor
switch network and to the power supply must be added where shown.
The breadboarded relay circuit is exactly the same as the schematic in Figure
3-93. The components have just been rearranged and squeezed together so
that they will fit alongside the relay. Two wires at the lower-left corner go to
the network of magnetic sensor switches that will trip the alarm; for testing
purposes, you can just hold the stripped ends of these two wires together to
simulate all the switches being closed, and separate the wires to simulate a
switch opening.
Two more wires bring power to the breadboard on either side of the relay. This
is where you should connect your power supply during testing. The output
from the relay, through its top pair of contacts, is connected with the rails of
the breadboard by a little jumper wire at top left, and another at top right.
Don’t forget to include them! One more little wire at the lower-left corner (eas-
ily overlooked) connects the lefthand side rail to the lefthand coil terminal of
the relay, so that when the relay is powering the noisemaker circuit, it powers
itself as well.
When you mount the diode, remember that the end of it that is marked with a
band around it is the end that blocks positive current. In this circuit, that’s the
lower end of the diode.
Try it to make sure that it works. Short the sensor wires together and then ap-
ply power. The alarm should remain silent. You can use your meter to check
that no voltage exists between the side rails. Now separate the sensor wires,
and the relay should click, supplying power to the side rails, which activates
the noisemaker. Even if you bring the sensor wires back together, the relay
should remain locked on. The only way to unlock it is to disconnect the power
supply.
When the circuit is active, the transistor followed by the diode drops the volt-
age slightly, but the 12-volt relay should still work.
In my test circuit, trying three different relays, they drew between 27 and 40
milliamps at 9.6 volts. Some current still leaked through the transistor when it
was in its “off” mode, but only a couple of milliamps at 0.5 volts. This low volt-
age was far below the threshold required to trip the relay.
136 Chapter 3
Experiment 15: Intrusion Alarm Revisited
Essentials
Tools
Figure 3-102. Too little solder (or insufficient heat) can allow
a soldered wire to remain separate from the soldered copper
on the perforated board. Even a hair-thin gap is sufficient to
prevent an electrical connection.
138 Chapter 3
Experiment 15: Intrusion Alarm Revisited
Essentials
Loudspeaker
Figure 3-105. The final block diagram for
this phase of the project shows where user
controls fit in the series of functions.
140 Chapter 3
Experiment 15: Intrusion Alarm Revisited
When S1 is in its Off position, it still supplies positive power through its up-
per contact to S2, the pushbutton. When the pushbutton is pressed, so that it
goes into its “Test” position, the pole of S2 connects with the power and sends
it out through the sensor switches on doors and windows. The wires to these
switches will be attached via a couple of binding posts, shown here as two
circles. If the sensor switches are all closed, power returns through the second
binding post, passes through the lower set of contacts in S2, and lights D2, the
green LED. Because S1 is not supplying power to the alarm circuit board, the
alarm does not sound at this time.
S1
Off
S2
Ready
To Circuit
Board
Relay To/From On
Section Sensor
(green Switches
wires) D1
12V DC
Power J1
Supply
Test
R1
D2
Red Black
To Circuit Board Power Input
Figure 3-106. This schematic suggests a convenient way to add an on/off switch, a conti-
nuity testing feature, and a noisemaker testing feature to the alarm.
142 Chapter 3
Experiment 15: Intrusion Alarm Revisited
The circuit board will sit on the bottom, held in place with four #4-size ma-
chine screws (bolts) with washers and nylon-insert locknuts. You need to use
locknuts to eliminate the risk of a nut working loose and falling among com-
ponents where it can cause a short circuit.
You’ll have to cut the perfboard to fit, taking care not to damage any of the
components on it. Also check the underside the board for loose fragments of
copper traces after you finish cutting.
Drill bolt holes in the board, if necessary, taking care again not to damage any
components. Then mark through the holes to the plastic bottom of the box,
and drill the box. Countersink the holes (i.e., bevel the edges of a hole so that
a flat-headed screw will fit into it flush with the surrounding surface), push
the little bolts up from underneath, and install the circuit board. Be extremely
careful not to attach the circuit board too tightly to the project box. This can
impose bending stresses, which may break a joint or a copper trace on the
board.
I like to include a soft piece of plastic under the board to absorb any stresses.
Because you’re using locknuts, which will not loosen, there’s no need to make
them especially tight.
Test the circuit again after mounting the circuit board, just in case.
attach them, and don’t allow the iron to remain in contact with anything for
more than 10 seconds. It will quickly melt insulation, and may even damage
the internal parts of the switches.
In projects that are more complex than this one, it would be good practice
to link the top panel with the circuit board more neatly. Multicolored ribbon
cable is ideal for this purpose, with plug-and-socket connectors that attach to
the board. For this introductory project, I didn’t bother. The wires just straggle
around, as shown in Figure 3-111.
680 ohms
Normally Closed
Off
To Circuit
Board S1
S2
Normally Open On
(push to test)
Power to
Circuit
Board
To/From
Sensor Power In
Switches 12V DC
Figure 3-110. The components can be wired together like this to Figure 3-111. The circuit board has been installed in the
replicate the circuit shown in The red and green circles are LEDs. base of the project box, and the power input jack has been
Small, solid black circles indicate wire-to-wire solder joints. screwed into the end of the box. Twisted wire-pairs have
been connected on a point-to-point basis, without much
concern over neatness, as this is a relatively small project.
The white insulation at the top-right corner of the front
panel is heat-shrink tube that encloses a solder joint and the
680Ω load resistor. Soldering wires to the pushbutton switch
requires care and precision, as the contacts are closely
spaced.
144 Chapter 3
Experiment 15: Intrusion Alarm Revisited
Final Test
When you’ve completed the circuit, test it! If you don’t have your network of
magnetic sensor switches set up yet, you can just use a piece of wire to con-
nect the two binding posts. Make sure that S1 is in its Off position, then solder
the appropriate plug to your 12-volt power source, and plug it into the power
jack. When you press the button, the green LED should light up to show con-
tinuity between the two binding posts. Now disconnect the wire between the
binding posts, press the button again, and the green LED should remain dark.
Reconnect the binding posts, flip S1 to its On position, and the red LED should
light up. Press the button, and the alarm should start. Reset it by turning S1
off and then on again; then disconnect the wire between the binding posts.
Again, the alarm should start, and it should continue even if you reconnect
the wire.
If everything works the way it should, it’s time to screw the top of the box in
place, pushing the wires inside. Because you’re using a large box, you should
have no risk of metal parts touching each other accidentally, but still, proceed
carefully.
Alarm Installation
Before you install your magnetic sensor switches, you should test each one by
moving the magnetic module near the switch module and then away from it,
Figure 3-112. Dual-conductor, white
while you use your meter to test continuity between the switch terminals. The insulated wire can be used to connect the
switch should close when it’s next to the magnet, and open when the magnet terminals on the alarm control box with
is removed. magnetic sensors (shown in dark red).
Because the sensors must be in series, the
Now draw a sketch of how you’ll wire your switches together. Always remem- wire is cut and joined at positions marked
ber that they have to be in series, not in parallel! Figure 3-112 shows the con- with orange dots.
cept in theory. The two terminals are the binding posts on top of your control
box (which is shown in green), and the dark red rectangles are the magnetic
sensor switches on windows and doors. Because the wire for this kind of instal-
lation usually has two conductors, you can lay it as I’ve indicated but cut and
solder it to create branches. The solder joints are shown as orange dots. Note
how current flows through all the switches in series before it gets back to the
control box.
Figure 3-113 shows the same network as you might actually install it in a situ-
ation where you have two windows and a door. The blue rectangles are the
magnetic modules that activate the switch modules.
You’ll need a large quantity of wire, obviously. The type of white, stranded
wire that is sold for doorbells or furnace thermostats is good. Typically, it is
20-gauge or larger.
After you install all the switches, clip your meter leads to the wires that would Figure 3-113. In an installation involving two
normally attach to the alarm box. Set your meter to test continuity, and open windows and a door, the magnetic com-
each window or door, one at a time, to check whether you’re breaking the ponents of the sensors (blue rectangles)
could be placed as shown, while the
continuity. If everything is OK, attach the alarm wires to the binding posts on switches (dark red) are located alongside
your project box. them.
Now deal with the power supply. Use your AC adapter, set to 12 volts, hooked
up to your type N power plug, or attach the power plug to a 12-volt alarm
battery.
If you use a battery, be especially careful that the wire leading to the center
terminal of your power plug is positive! A 12-volt battery can deliver substan-
tial current, which can fry your components if you connect it the wrong way
around. It would be a shame to destroy your entire project at the very last step.
The only remaining task is to label the switch, button, power socket, and bind-
ing posts on the alarm box. You know that the switch turns the power on and
off, and the button tests the circuit and the noisemaker, but no one else knows,
and you might want to allow a guest to use your alarm while you’re away. For
that matter, months or years from now, you may forget some details. Will you
remember that the power source for this unit should be 12 volts?
Labeling really is a good idea. But as you can see in Figure 3-114, I haven’t quite
gotten around to it for the box that I built.
Conclusion
Figure 3-114. The intrusion alarm com- The alarm project has taken you through the basic steps that you will usually
pleted and in its project box. follow any time you develop something:
1. Draw a schematic and make sure that you understand it.
2. Modify it to fit the pattern of conductors on a breadboard.
3. Install components on the breadboard and test the basic functions.
4. Modify or enhance the circuit, and retest.
5. Transfer to perforated board, test, and trace faults if necessary.
6. Add switches, buttons, power jack, and plugs or sockets to connect the
circuit with the outside world.
7. Mount everything in a box (and add labeling).
While going through this sequence, I hope you’ve learned the basics of elec-
tricity, along with some simple electrical theory, and fundamentals about
electronic components. This knowledge should enable you to move on to the
much more powerful realm of integrated circuit—which I’ll cover in Chapter 4.
146 Chapter 3
Chips, Ahoy! 4
Before I get into the fascinating topic of integrated circuit (IC) chips, I have to In this chapter
make a confession: some of the things I asked you to do in Chapter 3 could
have been done a bit more simply. Does this mean you have been wasting Shopping List: Experiments 16 Through 24
your time? No, I firmly believe that by building circuits with old-fashioned Experiment 16: Emitting a Pulse
components—capacitors, resistors, and transistors—you acquire the best Experiment 17: Set Your Tone
possible understanding of the principles of electronics. Still, you are going to Experiment 18: Reaction Timer
find that integrated circuit chips, containing dozens, hundreds, or even thou- Experiment 19: Learning Logic
sands of transistor junctions, will enable some shortcuts.
Experiment 20: A Powerful Combination
Experiment 21: Race to Place
Shopping List: Experiments 16 Through 24 Experiment 22: Flipping and Bouncing
Experiment 23: Nice Dice
Tools Experiment 24: Intrusion Alarm
Completed
The only new tool that I recommend using in conjunction with chips is a logic
probe. This tells you whether a single pin on a chip has a high or low voltage,
which can be helpful in figuring out what your circuit is doing. The probe has
a memory function so that it will light its LED, and keep it lit, in response to a
pulse that may have been too quick for the eye to see.
Search online and buy the cheapest logic probe you can find. I don’t have any
specific brand recommendations. The one shown in Figure 4-1 is fairly typical.
Supplies
Integrated circuit chips
If you buy everything on this shopping list, and you bought basic parts
such as resistors and capacitors that were listed previously, you should
have everything you need for all the projects in this chapter.
As chips are quite cheap (currently around 50 cents apiece), I suggest you
buy extras. This way, if you damage one, you’ll have some in reserve. You’ll
also have a stock for future projects.
Please read the next section, “Fundamentals: Choosing chips,” before you
begin chip-shopping. Chips should be easily obtainable from all the major Figure 4-1. A logic probe detects the high or
low voltage on each pin of a chip, and re-
electronics retail suppliers, and sometimes are found on eBay shops. Look veals pulses that may occur too quickly for
in the appendix for a complete list of URLs. you to perceive them with the unaided eye.
147
Shopping List: Experiments 16 Through 24
Fundamentals
Choosing chips
Figure 4-2 shows what is often referred to as an integrated Often they are now referred to as “74xx” chips, where “xx”
circuit (IC). The circuit is actually etched onto a tiny wafer or includes all the members of the family. I’ll be using this fam-
“chip” of silicon, embedded in a black plastic body, which is ily a lot, so you need to know how to buy them. I’ll give you
properly referred to as the “package.” Tiny wires inside the some advice on that without going into details yet about
package link the circuit with the two rows of pins on either what the chips actually do.
side. Throughout this book, I will use the word “chip” to refer
to the whole object, including its pins, as this is the most
common usage.
Figure 4-3. The DIP chip, at the rear, has pins spaced 1/10
inch apart, suitable for insertion in a breadboard or perfo-
Figure 4-2. An integrated circuit chip in Plastic Dual-Inline Pin
rated board. It can be soldered without special tools. The
package, abbreviated PDIP, or, more often, DIP.
small-outline integrated circuit (SOIC) surface-mount chip
(foreground) has solder tabs spaced at 1/20 inch. Other
The pins are mounted at intervals of 1/10 inch in two rows surface-mount chips have pins spaced at 1/40 inch or even
spaced 3/10 inch apart. This format is known as a Plastic less (these dimensions are often expressed in millimeters).
Dual Inline Package, abbreviated PDIP, or, more often, just Surface-mount chips are designed primarily for automated
DIP. The chip in the photograph has four pins in each row; assembly and are difficult to work with manually. In this photo,
others may have many more. The first thing you need to the yellow lines are 1 inch apart to give you an idea of the scale.
know, when shopping for chips, is that you’ll only be using
the DIP package. This book will not be featuring the more Take a look at Figure 4-4, which shows how to interpret a
modern type, known as “surface-mount,” because they’re typical part number in a 74xx family member. The initial
much smaller, more difficult to handle, and require special letters identify the manufacturer (which you can ignore,
tools that are relatively expensive. Figure 4-3 shows a size as it really makes no difference for our purposes). Skip the
comparison between a 14-pin DIP package and a 14-pin letters until you get to the “74.” After that, you find two more
surface-mount package. Many surface-mount chips are letters, which are important. The 74xx family has evolved
even smaller than the one shown. through many generations, and the letter(s) inserted after
the “74” tell you which generation you’re dealing with. Some
Just about every chip has a part number printed on it. In generations have included:
Figure 4-2, the part number is KA555. In Figure 4-3, the DIP
• 74L
chip’s part number is M74HC00B1, and the surface-mount
chip is a 74LVC07AD. You can ignore the second line of • 74LS
numbers and/or letters on each chip, as they are not part of • 74C
the part number. • 74HC
Notice in Figure 4-3 that even though the chips look quite • 74AHC
different from each other, they both have “74” in their part And there are more. Generally speaking, subsequent gen-
numbers. This is because both of them are members of the erations tend to be faster or more versatile than previous
“7400” family of logic chips, which originally had part numbers generations. In this book, for reasons I’ll explain later, we are
from 7400 and upward (7400, 7401, 7402, 7403, and so on). mostly using the HC generation.
148 Chapter 4
Shopping List: Experiments 16 Through 24
Fundamentals
Type of chip
7400 NAND gate
150 Chapter 4
Shopping List: Experiments 16 Through 24
Latching relays
You’re going to need a 5-volt latching relay that has two coils, instead of
one. The first coil flips the relay one way; the second coil flips it back. The
relay consumes no additional power while remaining passively in each
state. I suggest the Panasonic DS2E-SL2-DC5V relay. If you buy a different
relay, it must be dual-coil latching to run off 5 volts DC, switching at least
1 amp, in a “2 form C” package, to fit your breadboard.
Potentiometers
You’ll need 5K, 10K, and 100K linear potentiometers (one of each). Also, a
10K trimmer potentiometer (which you may find described just as a “trim-
mer”). The manufacturer is unimportant.
Voltage regulators
Because many logic chips require precisely 5 volts DC, you need a voltage
regulator to deliver this. The LM7805 does the job. Here again, the chip Figure 4-8. Many integrated circuit chips
number will be preceded or followed with an abbreviation identifying the require a controlled power supply of
5 volts, which can be delivered by this
manufacturer and package style, as in the LM7805CT from Fairchild. Any regulator when you apply 7.5 to 9 volts to
manufacturer will do, but the package should look like the one in Figure it. The lefthand pin is for positive input,
4-8, and if you have a choice, buy a regulator that can deliver at least 1 the center pin is a common ground, and
amp. the righthand pin is the 5V output. For cur-
rents exceeding 250mA, you should bolt
Tactile switches the regulator to a metal heat sink using
the hole at the top.
These are SPST pushbuttons (momentary switches), usually with four legs.
Look for the ALPS part number SKHHAKA010 or any similar item that has
pins to fit your breadboard or perforated board. See Figure 4-9.
12-key numeric keypad
Velleman “12 keys keyboard with common output” (no part number, but
has been available through All Electronics under catalog code KP-12).
Quantity: 1.
This type of keypad has the same layout as an old-fashioned touchtone
phone. It should have at least 13 pins or contacts, 12 of which connect
with individual pushbuttons, the thirteenth connecting with the other
side of all the pushbuttons. In other words, the last pin is “common” to all Figure 4-9. A tactile switch delivers tactile
of them, and this type of keypad is often described as having a “common feedback through your fingertip when you
output.” The type of keypad that you don’t want is “matrix-encoded,” with press it. They are almost always SPST
pushbuttons designed for mounting in
fewer than 13 contacts, requiring additional external circuitry. See Figures circuit boards with standard 1/10-inch
4-10 and 4-11. If you can’t find the Velleman keypad that I suggest, look hole spacing.
carefully at keypad descriptions and photographs to make sure that the
one you buy is not matrix-encoded and has a common terminal.
Alternatively, you may substitute 12 cheap SPST NO pushbuttons and
mount them in a small project box.
Figure 4-10. When shopping for a numeric Figure 4-11. This keypad has insufficient
keypad, it should have 12 keys in “touch- pins and will not work in the circuit in this
tone phone” layout, and should have at book.
least 13 contacts for input/output. The
contacts are visible here along the front
edge.
Background
152 Chapter 4
Experiment 16: Emitting a Pulse
Procedure
Pins
The 555 chip is very robust, but still, in theory, you can zap it with a jolt of static
electricity and kill it. Therefore, to be on the safe side, you should ground Figure 4-13. The 555 timer chip, seen from
yourself before handling it. See the “Grounding yourself” warning on page 172 above. Pins on chips are always numbered
counterclockwise, from the top-left corner,
for details. Although this warning primarily refers to the type of chips known with a notch in the body of the chip upper-
as CMOS, which are especially vulnerable, grounding yourself is always a sen- most, or a circular indentation at top-left,
sible precaution. to remind you which end is up.
Look for a small circular indentation, called the dimple, molded into the body
of the chip, and turn the chip so that the indentation is at the top-left corner
with the pins pointing down. Alternatively, if your chip is of the type with a
notch at one end, turn the chip so that the notch is at the top.
The pins on chips are always numbered counterclockwise, starting from the
top-left pin (next to the dimple). See Figure 4-13, which also shows the names
of the pins on the 555 timer, although you don’t need to know most of them
just yet.
Insert the chip in your breadboard so that its pins straddle the channel down
the center. Now you can easily feed voltages to the pins on either side, and
read signals out of them. See Figure 4-14 for a precise guide to placement, in
the first project. The timer is identified as “IC1,” because “IC” is the customary
abbreviation for “Integrated Circuit.”
9V
C3 DC
S1
R5
R8
R4
IC1
C4
D1 C5
Volts R6
R7
S2
Figure 4-14. This circuit allows you to explore the behavior of the 555 timer chip. Use your
meter to monitor the voltage on pin 2 as shown. There are no resistors labeled R1, R2,
or R3 and no capacitors labeled C1 or C2, because they’ll be added in a later schematic.
Component values in this schematic:
R4: 100K
R5: 2K2
R6: 10K
R7: 1K
R8: 5K linear potentiometer
C3: 100 µF electrolytic
C4: 47 µF electrolytic
C5: 0.1 µF ceramic
IC1: 555 timer
S1, S2: SPST tactile switches (pushbuttons)
D1: Generic LED
R5 holds the trigger (pin 2) positive until S1 is pressed, which lowers the voltage depend-
ing on the setting of potentiometer R8. When the trigger voltage falls below 1/3 of the
power supply, the chip’s output (pin 3) goes high for a period determined by the values
of R4 and C4. S2 resets (zeros) the timer, by reducing the voltage to pin 4, the Reset. C3
smoothes the power supply, and C5 isolates pin 5, the control, so that it won’t interfere
with the functioning of this test circuit. (We’ll use the control pin in a future experiment.)
All integrated circuit chips require a power supply. The 555 is powered with
negative voltage applied to pin 1 and positive to pin 8. If you reverse the volt-
age accidentally, this can permanently damage the chip, so place your jumper
wires carefully.
154 Chapter 4
Experiment 16: Emitting a Pulse
Set your power supply to deliver 9 volts. It will be convenient for this experiment
if you supply positive down the righthand side and negative down the lefthand
side of the breadboard, as suggested in Figure 4-14. C3 is a large capacitor, at
least 100 µF, which is placed across the power supply to smooth it out and pro-
vide a local store of charge to fuel fast-switching circuits, as well as to guard
against other transient dips in voltage. Although the 555 isn’t especially fast-
switching, other chips are, and you should get into the habit of protecting them.
Begin with the potentiometer turned all the way counterclockwise to maxi-
mize the resistance between the two terminals that we’re using, and when you
apply the probe from your meter to pin 2, you should measure about 6 volts
when you press S1.
Now rotate the potentiometer clockwise and press S1 again. If the LED doesn’t
9V
light up, keep turning the potentiometer and pressing and releasing the but- DC
ton. When you’ve turned the potentiometer about two-thirds of the way, you C3
should see the LED light up for just over 5 seconds when you press and release
the button. Here are some facts that you should check for yourself: R8 R5
• The LED will keep glowing after you release the button. R4
1 8
• You can press the button for any length of time (less than the timer’s cycle 2 IC1 7
time) and the LED always emits the same length of pulse. S1
3 6
4 5
• The timer is triggered by a fall in voltage on pin 2. You can verify this with
D1
your meter. C4
C5
R7
• The LED is either fully on or fully off. You can’t see a faint glow when it’s off,
and the transition from off to on and on to off is very clean and precise. R6
Check Figure 4-16 to see how the components should look on your bread- S2
board, and then look at the schematic in Figure 4-15 to understand what’s Figure 4-15. A schematic view of the circuit
happening. I will be adding more components later, which I will be labeling R1, shown in Figure 4-14. Throughout this
R2, C1, and C2 to be consistent with data sheets that you may see for the 555 chapter, the schematics will be laid out
to emulate the most likely placement of
timer. Therefore, in this initial circuit the resistors are labeled R4 and up, and components on a breadboard. This is not
capacitors C3 and up. always the simplest layout, but will be
easiest for you to build. Refer to Figure
When S1 (the tactile switch) is open, pin 2 of the 555 timer receives positive 4-14 for the values of the components.
power through R5, which is 2K2. Because the input resistance of the timer is
very high, the voltage on pin 2 is almost the full 9 volts.
When you press the button, it connects negative voltage through R8, the 5K
potentiometer to pin 2. Thus, R8 and R5 form a voltage divider with pin 2 in
the middle. You may remember this concept from when you were testing tran-
sistors. The voltage between the resistances will change, depending on the
values of the resistances.
If R8 is turned up about halfway, it is approximately equal to R5, so the mid-
point, connected to pin 2, has about half the 9-volt power supply. But when
you turn the potentiometer so that its resistance falls farther, the negative volt-
age outweighs the positive voltage, so the voltage on pin 2 gradually drops. Figure 4-16. This is how the components
If you have clips on your meter leads, you can hook them onto the nearest look when installed on the breadboard.
The alligator clips are attached to a patch
jumper wires and then watch the meter while you turn the potentiometer up cord that links the 100 µF capacitor to the
and down and press the button. potentiometer. The power supply input is
not shown.
The graphs in Figure 4-17 illustrate what is happening. The upper graph shows
the voltage applied to pin 2 by random button-presses, with the potentiometer
turned to various values. The lower graph shows that the 555 is triggered if,
and only if, the voltage on pin 2 actively drops from above 3 volts to below 3
volts. What’s so special about 3 volts? It’s one-third of our 9-volt power supply.
Here’s the take-home message:
• The output of the 555 (pin 3) emits a positive pulse when the trigger (pin
2) drops below one-third of the supply voltage.
• The 555 delivers the same duration of positive pulse every time (so long as
you don’t supply a prolonged low voltage on pin 2).
• A larger value for R4 or for C4 will lengthen the pulse.
• When the output (pin 3) is high, the voltage is almost equal to the supply
voltage. When the output goes low, it’s almost zero.
The 555 converts the imperfect world around it into a precise and dependable
output. It doesn’t switch on and off absolutely instantly, but is fast enough to
appear instant.
Now here’s another thing to try. Trigger the timer so that the LED lights up.
While it is illuminated, press S2, the second button, which grounds pin 4, the
reset. The LED should go out immediately.
When the reset voltage is pulled low, the output goes low, regardless of what
voltage you apply to the trigger.
There’s one other thing I want you to notice before we start using the timer for
more interesting purposes. I included R5 and R6 so that when you first switch
on the timer, it is not emitting a pulse—but is ready to do so. These resistors
apply a positive voltage to the trigger and the reset pin, to make sure that the
555 timer is ready to run when you first apply power to it.
As long as the trigger voltage is high, the timer will not emit a pulse. (It emits a
pulse when the trigger voltage drops.)
As long as the reset voltage is high, the timer is able to emit a pulse. (It shuts
down when the reset voltage drops.)
R5 and R6 are known as “pull-up resistors” because they pull the voltage up.
You can easily overwhelm them by adding a direct connection to the negative
side of the power supply. A typical pull-up resistor for the 555 timer is 10K.
With a 9-volt power supply, it only passes 0.9mA (by Ohm’s Law).
Finally, you may be wondering about the purpose of C5, attached to pin 5. This
pin is known the “control” pin, which means that if you apply a voltage to it,
you can control the sensitivity of the timer. I’ll get to this in more detail a little
later. Because we are not using this function right now, it’s good practice to
put a capacitor on pin 5 to protect it from voltage fluctuations and prevent it
from interfering with normal functioning.
Make sure you become familiar with the basic functioning of the 555 timer
before you continue.
156 Chapter 4
Experiment 16: Emitting a Pulse
9v
Trigger 6v
Voltage
Pin 2 3v
0v
9v
Output 6v
Voltage
Pin 3 3v
0v
Figure 4-17. The top graph shows voltage on the trigger (pin 2) when the pushbutton is
pressed, for different intervals, at different settings of the potentiometer. The lower graph
shows the output (pin 3), which rises until it is almost equal to the power supply, when the
voltage on pin 2 drops below 1/3 the full supply voltage.
Fundamentals
The following table shows 555 pulse duration in monos- • The vertical scale shows common capacitor values
table mode: between pin 6 and negative supply voltage.
• Duration is in seconds, rounded to two figures. To calculate a different pulse duration, multiply resistance ×
• The horizontal scale shows common resistor values capacitance × 0.0011 where resistance is in kilohms, capaci-
between pin 7 and positive supply voltage. tance is in microfarads, and duration is in seconds.
Theory
555
TIMER
1 8
R4
2 7
A
DOWN
FF
3 6
UP
C4
4 B 5
C5
Figure 4-18. Inside the 555 timer. White lines indicate connections inside the chip.
A and B are comparators. FF is a flip-flop which can rest in one state or the other,
like a double-throw switch. A drop in voltage on pin 2 is detected by comparator A,
which triggers the flip-flop into its “down” position and sends a positive pulse out of
pin 3. When C4 charges to 2/3 of supply voltage, this is detected by comparator B,
which resets the flip-flop to its “up” position. This discharges C4 through pin 7.
158 Chapter 4
Experiment 16: Emitting a Pulse
Theory
Background
160 Chapter 4
Experiment 16: Emitting a Pulse
Fundamentals
Beware of Pin-Shuffling!
In all of the schematics in this book, I’ll show chips as you’d see them 9V
DC
from above, with pin 1 at top left. Other schematics that you may
see, on websites or in other books, may do things differently. For
convenience in drawing circuits, people shuffle the pin numbers on C2
a chip so that pin 1 isn’t necessarily shown adjacent to pin 2.
R8 S1
Look at the schematic in Figure 4-20 and compare it with the one
in Figure 4-15. The connections are the same, but the one in Figure
4-20 groups pins to reduce the apparent complexity of the wiring. R4
R5
“Pin shuffling” is common because circuit-drawing software tends D1
R7
to do it, and on larger chips, it is necessary for functional clarity of 2 8
3 7
the schematic (i.e., logical groupings of pin names versus physical
groupings on memory chips, for example). When you’re first learn- IC1 R6
ing to use chips, I think it’s easier to understand a schematic that 1 6
5 4
shows the pins in their actual positions. So that’s the practice I will
C3
be using here.
C1
S2
Figure 4-20. Many people draw schematics in which the pin numbers on a chip are shuffled around to make the schematic
smaller or simpler. This is not helpful when you try to build the circuit. The schematic here is for the same circuit as in Figure
4-15. This version would be harder to recreate on a breadboard.
Procedure
Leave the components from Experiment 16 where they are on the bread-
board, and add the next section below them, as shown in Figures 4-21 and
4-22. Resistor R2 is inserted between pins 6 and 7, instead of the jumper wire
that shorted the pins together in the previous circuit, and there’s no external
input to pin 2 anymore. Instead, pin 2 is connected via a jumper wire to pin
6. The easiest way to do this is by running the wire across the top of the chip.
I have omitted the smoothing capacitor from the schematic in Figure 4-22,
because I’m assuming that you’re running this circuit on the same breadboard
as the first, where the previous smoothing capacitor is still active.
A loudspeaker in series with a 100Ω resistor (R3) has been substituted for the
LED to show the output from the chip. Pin 4, the reset, is disabled by connect-
ing it to the positive voltage supply, as I’m not expecting to use the reset func-
tion in this circuit.
Now what happens when you apply power? Immediately, you should hear
noise through the loudspeaker. If you don’t hear anything, you almost cer-
tainly made a wiring error.
Notice that you don’t have to trigger the chip with a pushbutton anymore.
The reason is that when C1 charges and discharges, its fluctuating voltage is
connected via a jumper wire across the top of the chip to pin 2, the trigger. In
this way, the 555 timer now triggers itself. I’ll describe this in more detail in the
next section “Theory: Inside the 555 timer: astable mode,” if you want to see
exactly what is going on.
In this mode, the chip is “astable,” meaning that it is not stable, because it flips
to and fro endlessly, sending a stream of pulses for as long as the power is
connected. The pulses are so rapid that the loudspeaker reproduces them as
noise.
In fact, with the component values that I specified for R1, R2, and C1, the 555
chip is emitting about 1,500 pulses per second. In other words, it creates a 1.5
KHz tone.
Check the table on page 166 to see how different values for R2 and C1 can create
different pulse frequencies with the chip in this astable mode. Note that the
table assumes a fixed value of 1K for R1!
162 Chapter 4
Experiment 17: Set Your Tone
9V
C3 DC
R1
IC2
R2
C1
C2 Figure 4-21. These components should be
added on the same breadboard below the
components shown in Figure 4-14. Use the
following values to test the 555 timer in its
astable mode:
R3
R1: 1K
R2: 10K
Loudspeaker R3: 100Ω
C1: 0.047 µF ceramic or electrolytic
C2: 0.1 µF ceramic
IC2: 555 timer
9V
DC
R1
1 8
2 IC2 7
3 6
R2
4 5
R3
C2 C1
Theory
164 Chapter 4
Experiment 17: Set Your Tone
Theory
9v
Output 6v
Voltage
Pin 3 3v
0v
Duration of each
Off cycle is
proportionate to
R2 only
Figure 4-24. In its usual astable configuration, the timer charges a capacitor through
R1+R2 and discharges the capacitor through R2 only. Therefore its output on cycles
are longer than its output off cycles.
9V
DC
R1
1 8
2 IC2 7
3 6
R2
4 5
D2
R3
C2 C1
Figure 4-25. This is a modification of the schematic shown in Figure 4-22. By adding
a diode to a 555 timer running in astable mode, we eliminate R2 from the charging
cycle of capacitor C1. Now we can adjust the output on cycle with the value of R1,
and the output off cycle with the value of R2, so that the on and off durations are
independent of each other.
Fundamentals
The following table shows 555 timer frequency in astable To calculate a different frequency: double R2, add the prod-
mode: uct to R1, multiply the sum by C1, and divide the result into
• Frequency is in pulses per second, rounded to two 1440. Like this:
figures. Frequency = 1440 / ( (R1 + 2R2) × C1) cycles per second
• The horizontal scale shows common resistor values for In this formula, R1 and R2 are in kilohms, C1 is in microfarads,
R2. and the frequency is in hertz (cycles per second). Note that
• The vertical scale shows common capacitor values for the frequency is measured from the start of one pulse to
C1. Resistor R1 is assumed to be 1K. the start of the next. The duration of each pulse is not the
• Resistor R1 is assumed to be 1K. same as the length of time between each pulse. This issue is
discussed in the previous section.
Astable Modifications
In the circuits shown in Figures 4-22 or 4-25, if you substitute a 100K potenti-
ometer for R2, you can adjust the frequency up and down by turning the shaft.
Another option is to “tune” the timer by using pin 5, the control, as shown in
the Figure 4-26. Disconnect the capacitor that was attached to that pin and
substitute the series of resistors shown. R9 and R11 are both 1K resistors, either
side of R10, which is a 100K potentiometer. They ensure that pin 5 always has
at least 1K between it and the positive and negative sides of the power supply.
Connecting it directly to the power supply won’t damage the timer, but will
prevent it from generating audible tones. As you turn the potentiometer to
and fro, the frequency will vary over a wide range. If you want to generate a
very specific frequency, a trimmer potentiometer can be used instead.
166 Chapter 4
Experiment 17: Set Your Tone
A primary advantage of using pin 5 to adjust frequency is that you can control 9V
DC
it remotely. Take the output from pin 3 of another 555 timer running slowly in
astable mode, and pipe it through a 2K2 resistor to pin 5. Now you get a two-
tone siren effect, as one timer controls the other. If, in addition, you add a 100
µF capacitor between pin 5 and ground, the charging and discharging of the R1
1 8
capacitor will make the tone slide up and down instead of switching abruptly.
2 555 7
I’ll describe this in more detail shortly. This leads me to the whole topic of one timer
3 6
chip controlling another chip, which will be our last variation on this experiment. R2
4 5
Chaining Chips R3 C1
Generally speaking, chips are designed so that they can talk to each other. The
555 couldn’t be easier in this respect:
R9 R10 R11
• Pin 3, the output, from one 555 can be connected directly to pin 2, the
trigger, of a second 555.
Figure 4-26. The control (pin 5) is seldom
• Alternatively, the output can be sufficient to provide power to pin 8 of a used but can be useful. Varying the voltage
second 555. on it will adjust the speed of the timer. This
circuit enables you to test the behavior of
• The output is appropriate to control or power other types of chips too. it. Component values:
4 5 4 5 4 5
Figure 4-27. Three ways to chain 555 timers together. The output of IC1 can power a sec-
ond timer, or adjust its control voltage, or activate its trigger pin.
You can chain together the two 555 timers that you already have on your
breadboard. Figure 4-28 shows how to connect the two circuits that were
shown previously in Figures 4-15 and 4-22. Run a wire from pin 3 (the output)
of the first chip to pin 8 (the positive power supply) of the second chip, and
disconnect the existing wire connecting pin 8 to your power supply. The new
wire is shown in red. Now when you press the button to activate the first chip,
its output powers the second chip.
9V
DC
You can also use the output from one chip to trigger another (i.e., you can con-
nect pin 3 from the first chip to pin 2 of the second). When the output from the
C3
first chip is low, it’s less than half a volt. This is well below the threshold that
R8 R5 the second chip requires to be activated. Why would you want to do this? Well,
you might want to have both timers running in monostable mode, so that the
end of a high pulse from the first one triggers the start of a high pulse in the
1 8
R4
second one. In fact, you could chain together as many timers as you like in this
2 7
S1 IC1
way, with the last one feeding back and triggering the first one, and they could
3 6
flash a series of LEDs in sequence, like Christmas lights. Figure 4-29 shows how
4 5
D1
four timers could be linked this way, in a configuration that would occupy min-
C5 C4 imal space (and would be wired point-to-point on perforated board, not on
R4 breadboard-format board). Each of the outputs numbered 1 through 4 would
10K
have about enough power to run maybe 10 LEDs, if you used relatively high
load resistors to limit their current.
S2
Incidentally, you can reduce the chip count (the number of chips) by using two
1 8
R1 556 timers instead of four 555 timers. The 556 contains a pair of 555 timers in
2 IC2 7 one package. But because you have to make the same number of external con-
3 6 nections (other than the power supply), I haven’t bothered to use this variant.
R2
4 5
You can even get a 558 timer that contains four 555 circuits, all preset to func-
R3
C2 C1
tion in astable mode. I decided not to use this chip, because its output behaves
differently from a normal 555 timer. But you can buy a 558 timer and play with
it if you wish. It is ideal for doing the “chain of four timers” that I suggested
Figure 4-28. You can combine the two cir- previously. The data sheet even suggests this.
cuits shown in Figures 4-15 and 4-22 sim-
ply by disconnecting the wire that provides Lastly, going back to the idea of modifying the frequency of a 555 timer in
power to pin 8 of the second timer, and astable mode, you can chain two timers, as shown in Figure 4-30. The red wire
running a substitute wire (shown in red). shows the connection from the output of the first timer to the control pin of
the second. The first timer has now been rewired in astable mode, so that it
2
1 4
3 creates an oscillating on/off output around four times per second. This out-
put flashes the LED (to give you a visual check of what’s going on) and feeds
12V
DC
through R7 to the control pin of the second timer.
But C2 is a large capacitor, which takes time to charge through R7. While this
happens, the voltage detected by pin 5 slowly rises, so that the tone gener-
ated by IC2 gradually rises in pitch. Then IC1 reaches the end of its on cycle
and switches itself off, at which point C2 discharges and the pitch of the sound
generated by IC2 falls again.
You can tweak this circuit to create all kinds of sounds, much more controllably
then when you were using PUT transistors to do the same kind of thing. Here
are some options to try:
• Double or halve the value of C2.
• Omit C2 completely, and experiment with the value of R7.
Figure 4-29. Four 555 timers, chained to- • Substitute a 10K potentiometer for R7.
gether in a circle, can flash a series of four
sets of LEDs in sequence, like Christmas • Change C4 to increase or decrease the cycle time of IC1.
lights or a movie marquee.
168 Chapter 4
Experiment 17: Set Your Tone
• Halve the value of R5 while doubling the value of C4, so that the cycle
time of IC1 stays about the same, but the On time becomes significantly
longer than the Off time.
• Change the supply voltage in the circuit from 9 volts to 6 volts or 12 volts.
Remember, you can’t damage a 555 timer by making changes of this kind. Just
make sure that the negative side of your power supply goes to pin 1 and the
positive side to pin 8.
9V
DC
C3
R4
1 8
2 IC1 7
3 6
R5
4 5
D1
C5 C4
R6
R1
1 8
2 IC2 7
3 6
R2
4 5
R3
R7 C2 C1
Figure 4-30. When both timers are astable, but IC1 runs much more slowly than IC2, the
output from IC1 can be used to modulate the tone generated by IC2. Note that as this is
a substantial modification to the previous schematics, several components have been
relabeled. To avoid errors, you may need to remove the old circuit from your breadboard
and build this version from scratch. Try these values initially:
Step 1: Display
You can use three separate LED numerals for this project, but I suggest that
a you buy the Kingbright BC56-11EWA on the shopping list at the beginning of
this chapter. It contains three numerals in one big package.
You should be able to plug it into your breadboard, straddling the center
f b channel. Put it all the way down at the bottom of the breadboard, as shown in
Figure 4-31. Don’t put any other components on the breadboard yet.
g Now set your power supply to 9 volts, and apply the negative side of it to the
row of holes running up the breadboard on the righthand side. Insert a 1K
resistor between that negative supply and each of pins 18, 19, and 26 of the
e c Kingbright display, which are the “common cathode,” meaning the negative
connection shared by each set of LED segments in the display. (The pin num-
bers of the chip are shown in Figure 4-33. If you’re using another model of
d h display, you’ll have to consult a data sheet to find which pin(s) are designed to
receive negative voltage.)
Figure 4-32. The most basic and common Switch on the power supply and touch the free end of the positive wire to each
digital numeral consists of seven LED seg- row of holes serving the display on its left and right sides. You should see each
ments identified by letters, as shown here, segment light up, as shown in Figure 4-31.
plus an optional decimal point.
Each numeral from 0 to 9 is represented by a group of these segments. The
segments are always identified with lowercase letters a through g, as shown in
Figure 4-32. In addition, there is often a decimal point, and although we won’t
be using it, I’ve identified it with the letter h.
170 Chapter 4
Experiment 18: Reaction Timer
Check Figure 4-33 showing the Kingbright display, and you’ll see I have an-
1e 1 28 1g
notated each pin with its function. You can step down the display with the
f
positive wire from your power supply, making sure that each pin lights an ap- 1d 2 27 1f
g
propriate segment.
a
1 3 26 1
b
Incidentally, this display has two pins, numbered 3 and 26, both labeled to 1c 4
Numeral 1
25 1a
h
receive negative voltage for the first of the digits. Why two pins instead of one? 1h 5 24 1b
I don’t know. You need to use only one, and as this is a passive chip, it doesn’t
2e 6 23 2f
matter if you leave the unused one unconnected. Just take care not to apply
f
positive voltage to it, which would create a short circuit. 2d 7 22 2g
a
A numeric display has no power or intelligence of its own. It’s just a bunch of 2c 8 21 2a
b
light-emitting diodes. It’s not much use, really, until we can figure out a way to 2h 9 20 2b
h
Numeral 2
illuminate the LEDs in appropriate groups—which will be the next step.
3e 10 19 2
3d 11 18 3
Step 2: Counting
f
3g 12 17 3f
a
Fortunately, we have a chip known as the 4026, which receives pulses, counts
3c 13 16 3a
c
them, and creates an output designed to work with a seven-segment display so
b
3h Numeral 3 3b
h
14 15
that it shows numbers 0–9. The only problem is that this is a rather old-fashioned
CMOS chip (meaning, Complementary Metal Oxide Semiconductor) and is thus
Figure 4-33. This Kingbright unit incor-
sensitive to static electricity. Check the caution on page 172 before continuing. porates three seven-segment numeric
displays in one package, and can be driven
Switch off your power supply and connect its wires to the top of the breadboard, by three chained 4026 decade counters.
noting that for this experiment, we’re going to need positive and negative pow- The pin numbers are shown close to the
er on both sides. See Figure 4-34 for details. If your breadboard does not already chip. Segments a through g of numeral 1
have the columns of holes color-coded, I suggest you use Sharpie markers to are identified as 1a through 1g. Segments
a through g of numeral 2 are identified as
identify them, to avoid polarity errors that can fry your components. 2a through 2g. Segments a through g of
numeral 3 are identified as 3a through 3g.
The 4026 counter chip is barely powerful enough to drive the LEDs in our dis-
play when powered by 9 volts. Make sure you have the chip the right way up, 9v
and insert it into the breadboard immediately above your three-digit display, DC
leaving just one row of holes between them empty.
The schematic in Figure 4-35 shows how the pins of the 4026 chip should be con-
nected. The arrows tell you which pins on the display should be connected with 100uF
pins on the counter.
Figure 4-36 shows the “pinouts” (i.e., the functions of each pin) of a 4026 coun-
ter chip. You should compare this with the schematic in Figure 4-35.
Include a tactile switch between the positive supply and pin 1 of the 4026
counter, with a 10K resistor to keep the input to the 4026 counter negative un-
til the button is pressed. Make sure all your positives and negatives are correct,
and turn on the power. You should find that when you tap the tactile switch
Figure 4-34. When building circuits around
lightly, the counter advances the numeric display from 0 through 9 and then chips, it’s convenient to have a positive
begins all over again from 0. You may also find that the chip sometimes misin- and negative power supply down each
terprets your button-presses, and counts two or even three digits at a time. I’ll side of your breadboard. For the reaction
timer circuit, a 9V supply with a 100 µF
deal with this problem a little further on.
smoothing capacitor can be set up like
The LED segments will not be glowing very brightly, because the 1K series this. If your breadboard doesn’t color-code
the columns of holes on the left and right
resistors deprive of them of the power they would really like to receive. Those sides, I suggest you do that yourself with a
resistors are necessary to avoid overloading the outputs from the counter. permanent marker.
Grounding Yourself
To avoid the frustration that occurs when you power up a circuit and nothing happens, be sure to take these precautions when you
use the older generation of CMOS chips (which often have part numbers from 4000 upward, such as 4002, 4020, and so on):
Chips are often shipped with their legs embedded in black foam. This is electrically conductive foam, and you should keep the chips
embedded in it until you are ready to use them.
If the chips are supplied to you in plastic tubes, you can take them out and poke their legs into pieces of conductive foam or, if you
don’t have any, use aluminum foil. The idea is to avoid one pin on a chip acquiring an electric potential that is much higher than
another pin.
While handling CMOS components, grounding yourself is important. I find that in dry weather, I accumulate a static charge merely
by walking across a plastic floor-protecting mat in socks that contain some synthetic fibers. You can buy a wrist strap to keep your-
self grounded, or simply touch a large metal object, such as a file cabinet, before you touch your circuit board. I am in the habit of
working with my socked foot touching a file cabinet, which takes care of the problem.
Never solder a CMOS chip while there is power applied to it.
Grounding the tip of your soldering iron is a good idea.
Better still, don’t solder CMOS chips at all. When you’re ready to immortalize a project by moving it from a breadboard into perfo-
rated board, solder a socket into your perforated board, then push the chip into the socket. If there’s a problem in the future, you
can unplug the chip and plug in another.
Use a grounded, conductive surface on your workbench. The cheapest way to do this is to unroll some aluminum foil and ground
it (with an alligator clip and a length of wire) to a radiator, a water pipe, or a large steel object. I like to use an area of conductive
foam to cover my workbench—the same type of foam that is used for packaging chips. However, this foam is quite expensive.
10K
Clock input 1 16
1 16
Disable clock 2 15 Reset
2 15
3 14
4 13 4 Enable display 3 Not-2 output
IC3 14
5 12 24
27 6 11 1
28 7 10 25 Enable out 4 13 To segment c
8 9 2
1 28
Carry output 5 12 To segment b
2 27 R4
3 26
To segment f 6 11 To segment e
4 25
5 24
6 23 To segment g 7 10 To segment a
7 IC4 22
8 21 4026
8 9 To segment d
9 20 R5 Counter
Figure 4-35. IC3 is a 4026 10 19
counter. IC4 is a triple 11 18
Figure 4-36. The 4026 decade counter is a CMOS chip that accepts
seven-segment display chip. 12 17 clock pulses on pin 1, maintains a running total from 0 to 9, and out-
The arrows tell you which 13 16 R6
puts this total via pins designed to interface with a seven-segment
pins on the LED display 14 15 LED numeric display.
should be connected to the
pins on the counter.
172 Chapter 4
Experiment 18: Reaction Timer
Fundamentals
Assuming that you succeed in getting your counter to drive the numeric dis-
play, you’re ready to add two more counters, which will control the remaining
two numerals. The first counter will count in ones, the second in tens, and the
third in hundreds.
In Figure 4-37, I’ve continued to use arrows and numbers to tell you which pins
of the counters should be connected to which pins of the numeric display. Oth-
erwise, the schematic would be a confusing tangle of wires crossing each other.
At this point, you can give up in dismay at the number of connections—but
really, using a breadboard, it shouldn’t take you more than half an hour to
complete this phase of the project. I suggest you give it a try, because there’s
something magical about seeing a display count from 000 through 999 “all by
itself,” and I chose this project because it also has a lot of instructional value.
S3
S2 S1 is attached to the “clock disable” pin of IC1, so that when you hold down this
C1
S1
R3 button, it should stop that counter from counting. Because IC1 controls IC2,
R1 1 16
and IC2 controls IC3, if you freeze IC1, the other two will have to wait for it to
2 15 resume. Therefore you won’t need to make use of their “clock disable” features.
3 14
4
5
IC1
13
12
13
15
S2 is connected to the “reset” pins of all three counters, so that when you hold
R2
17 6 11 10 down this button, it should set them all to zero.
12 7 10 16
8 9 11 S3 sends positive pulses manually to the “clock input” pin of the first counter.
1
2
16
15
S1, S2, and S3 are all wired in parallel with 1K resistors connected to the nega-
3 14 tive side of the power supply. The idea is that when the buttons are not being
4
5
IC2
13
12
8
20
pressed, the “pull-down” resistors keep the pins near ground (zero) voltage. When
23 6 11 6 you press one of the buttons, it connects positive voltage directly to the chip,
22 7
8
10
9
21
7
and easily overwhelms the negative voltage. This way, the pins remain either in
a definitely positive or definitely negative state. If you disconnect one of these
1
2
16
15
pull-down resistors you are likely to see the numeric display “flutter” erratically.
3 14 (The numeric display chip has some unconnected pins, but this won’t cause any
4
5
IC3
13
12
4
24
problem, because it is a passive chip that is just a collection of LED segments.)
27 6 11 1
28 7 10 25
8 9 2
Always connect input pins of a CMOS chip so that they are either positive or nega-
1 28
tive. See the “No Floating Pins” warning on the next page.
2 27 R4
3 26
4 25
5 24
I suggest that you connect all the wires shown in the schematic first. Then cut
6 23 lengths of 22-gauge wire to join the remaining pins of the sockets from IC1,
7 IC4 22
8 21
IC2, and IC3 to IC4.
9 20 R5
10 19 Switch on the power and press S2. You’ll see three zeros in your numeric display.
11 18
12 17 R6 Each time you press S3, the count should advance by 1. If you press S2, the
13 16
14 15
count should reset to three zeros. If you hold down S1 while you press S3 re-
peatedly, the counters should remain frozen, ignoring the pulses from S3.
Figure 4-37. This test circuit, laid out as you
would be likely to place it on a breadboard,
allows you to trigger a counter manually
to verify that the display increments from Fundamentals
000 upward to 999.
Component values: Switch bounce
ll resistors are 1K.
A When you hit S3, I think you’ll find that the count sometimes increases by more
S1, S2, S3: SPST tactile switches, normally
open
than 1. This does not mean that there’s something wrong with your circuit or your
IC1, IC2, IC3: 4026 decade counter chips components; you are just observing a phenomenon known as “switch bounce.”
IC4: Kingbright 3-digit common-cathode
On a microscopic level, the contacts inside a pushbutton switch do not close
display
C1: 100 µF (minimum) smoothing capacitor smoothly, firmly, and decisively. They vibrate for a few microseconds before set-
tling; the counter chip detects this vibration as a series of pulses, not just one.
Wire the output pins on IC1, IC2, and IC3
to the pins on IC4, according to the num- Various circuits are available to “debounce” a switch. The simplest option is to
bers preceded by arrows. The actual wires put a small capacitor in parallel with the switch, to absorb the fluctuations; but
have been omitted for clarity. Check for
the pinouts of IC4.
this is less than ideal. I’ll come back to the topic of debouncing later in the book.
Switch bounce is not a concern in this circuit, because we’re about to get rid of
S3 and substitute a 555 timer that generates nice clean bounceless pulses.
174 Chapter 4
Experiment 18: Reaction Timer
Pulse Generation
A 555 timer is ideal for driving a counter chip. You’ve already seen how to wire
a 555 to create a stream of pulses that made noise through a loudspeaker. I’m
reproducing the same circuit in Figure 4-38 in simplified form, using the posi-
tive and negative supply configuration in the current project. Also I’m show-
ing the connection between pins 2 and 6 in the way that you’re most likely to
make it, via a wire that loops over the top of the chip.
For the current experiment, I’m suggesting initial component values that will
generate only four pulses per second. Any faster than that, and you won’t be
able to verify that your counters are counting properly.
Install IC5 and its associated components on your breadboard immediately
above IC1. Don’t leave any gap between the chips. Disconnect S3 and R3 and
connect a wire directly between pin 3 (output) of IC5 and pin 1 (clock) of IC1,
the topmost counter. Power up again, and you should see the digits advancing No Floating Pins!
rapidly in a smooth, regular fashion. Press S1, and while you hold it, the count
should freeze. Release S1 and the count will resume. Press S2 and the counter A CMOS chip is hypersensitive. Any
pin that is not wired either to the
should reset, even if you are pressing S1 at the same time.
supply voltage or to ground is said
to be “floating” and may act like an
antenna, sensitive to the smallest
fluctuations in the world around it.
The 4026 counter chip has a pin
labeled “clock disable.” The manu-
facturer’s data sheet helpfully tells
you that if you give this pin a positive
R7 voltage, the chip stops counting and
1 8
freezes its display. As you don’t want
2 IC5 7 to do that, you may just ignore that
pin and leave it unconnected, at least
3 6
while you test the chip. This is a very
R8 bad idea!
4 5
What the data sheet doesn’t bother
to tell you (presumably because
C3 C2 “everyone knows” such things) is that
To Pin 1 if you want the clock to run normally,
of 4026 the clock-disable feature itself has to
Counter
IC1
be disabled, by wiring it to negative
(ground) voltage. If you leave the pin
Figure 4-38. A basic astable circuit to drive the decade counter in the previous schematic. floating (and I speak from experi-
Output is approximately 4 pulses per second. ence), the chip will behave erratically
and uselessly.
R7: 1K
R8: 2K2 All input pins must be either
C2: 68 µF positively or negatively wired, unless
C3: 0.1 µF otherwise specified.
IC5: 555 timer
Refinements
Now it’s time to remember that what we really want this circuit to do is test a
person’s reflexes. When the user starts it, we want an initial delay, followed by a
signal—probably an LED that comes on. The user responds to the signal by press-
ing a button as quickly as possible. During the time it takes for the person to re-
spond, the counter will count milliseconds. When the person presses the button,
the counter will stop. The display then remains frozen indefinitely, displaying the
number of pulses that were counted before the person was able to react.
How to arrange this? I think we need a flip-flop. When the flip-flop gets a sig-
nal, it starts the counter running—and keeps it running. When the flip-flop
gets another signal (from the user pressing a button), it stops the counter run-
ning, and keeps it stopped.
How do we build this flip-flop? Believe it or not, we can use yet another 555
timer, in a new manner known as bistable mode.
Fundamentals
176 Chapter 4
Experiment 18: Reaction Timer
In bistable mode, the 555 has turned into one big flip-flop. To avoid any un-
certainty, we keep pins 2 and 4 normally positive via pull-up resistors, but
negative pulses on those pins can overwhelm them when we want to flip the
555 into its opposite state. The schematic for running a 555 timer in bistable
mode, controlled by two pushbuttons, is shown in Figure 4-40. You can add
this above your existing circuit. Because you’re going to attach the output
from IC6 to pin 2 of IC1, the topmost counter, you can disconnect S1 and R1
from that pin. See Figure 4-41.
Now, power up the circuit again. You should find that it counts in the same way
as before, but when you press S4, it freezes. This is because your bistable 555
timer is sending its positive output to the “clock disable” pin on the counter.
The counter is still receiving a stream of pulses from the astable 555 timer,
but as long as pin 2 is positive on the counter, the counter simply ignores the
pulses.
Now press S5, which flips your bistable 555 back to delivering a negative out-
put, at which point the count resumes.
We’re getting close to a final working circuit here. We can reset the count to
zero (with S3), start the count (with S5), and wait for the user to stop the count
(with S4). The only thing missing is a way to start the count unexpectedly.
1 8 Download at WoweBook.com
2 7
IC6
R9 3 6
4 5
S4
R10
To Pin 2
of 4026
Counter
S5 IC1
Figure 4-40. Adding a bistable 555 timer to the reflex tester will stop the counter with a
touch of a button, and keep it stopped.
R9, R10: 1K
IC6: 555 timer
The Delay
Suppose we set up yet another 555 in monostable mode. Trigger its pin 2 with
Start Delay
C1 a negative pulse, and the timer delivers a positive output that lasts for, say, 4
S4
1 8
seconds. At the end of that time, its output goes back to being negative. Maybe
2 7 we can hook that positive-to-negative transition to pin 4 of IC6. We can use this
IC7 R11
R10 3 6 instead of switch S5, which you were pressing previously to start the count.
4 5
C5
C6
Check the new schematic in Figure 4-41 which adds another 555 timer, IC7
C4 above IC6. When the output from IC7 goes from positive to negative, it will
R9
1 8 trigger the reset of IC6, flipping its output negative, which allows the count to
2 7
IC6 begin. So IC7 has taken the place of the start switch, S4. You can get rid of S4,
Stop Count 3 6
4 5
but keep the pull-up resistor, R9, so that the reset of IC6 remains positive the
S3
R12 rest of the time.
Prompt
R10
LED This arrangement works because I have used a capacitor, C4, to connect the
output of IC7 to the reset of IC6. The capacitor communicates the sudden
R7
1 8 change from positive to negative, but the rest of the time it blocks the steady
2 IC5 7
voltage from IC7 so that it won’t interfere with IC6.
3 6
R8
4 5 The final schematic in Figure 4-41 shows the three 555 timers all linked together,
as you should insert them above the topmost counter, IC1. I also added an LED to
C3 C2
signal the user. Figure 4-42 is a photograph of my working model of the circuit.
Set to Zero S2
Clock
Input
1 16
2 15
Disable 3 14 Reset
Clock IC1
178 Chapter 4
Experiment 18: Reaction Timer
Enhancements
It goes without saying that anytime you finish a project, you see some oppor-
tunities to improve it. Here are some suggestions:
1. No counting at power-up. It would be nice if the circuit begins in its
“ready” state, rather than already counting. To achieve this you need to
send a negative pulse to pin 2 of IC6, and maybe a positive pulse to pin 15
of IC1. Maybe an extra 555 timer could do this. I’m going to leave you to
experiment with it.
2. Audible feedback when pressing the Start button. Currently, there’s no
confirmation that the Start button has done anything. All you need to do
is buy a piezoelectric beeper and wire it between the righthand side of
the Start button and the positive side of the power supply.
3. A random delay interval before the count begins. Making electronic com-
ponents behave randomly is very difficult, but one way to do it would be
to require the user to hold his finger on a couple of metal contacts. The
skin resistance of the finger would substitute for R11. Because the finger
pressure would not be exactly the same each time, the delay would vary.
You’d have to adjust the value of C5.
180 Chapter 4
Experiment 19: Learning Logic
Summing Up
This project demonstrated how a counter chip can be controlled, how counter
chips can be chained together, and three different functions for 555 timers. It
also showed you how chips can communicate with each other, and introduced
you to the business of calibrating a circuit after you’ve finished building it.
Naturally, if you want to get some practical use from the circuit, you should
build it into an enclosure with heavier-duty pushbuttons—especially the but-
ton that stops the count. You’ll find that when people’s reflexes are being test-
ed, they are liable to hit the stop button quite hard.
Because this was a major project, I’ll follow it up here with some quicker, easier
ones as we move into the fascinating world of another kind of integrated circuit:
logic chips.
You’re going to be entering the realm of pure digital electronics, using “logic 5v DC
gates” that are fundamental in every electronic computing device. When you
deal with them individually, they’re extremely easy to understand. When you
start chaining them together, they can seem intimidatingly complex. So let’s
start with them one at a time.
Figure 4-44. This simple circuit is essential
Logic gates are much fussier than the 555 timer or the 4026 counter that you to provide a regulated 5V DC supply for
used previously. They demand an absolutely precise 5 volts DC, with no fluc- logic chips.
tuations or “spikes” in the flow of current. Fortunately, this is easy to achieve:
just set up your breadboard with an LM7805 voltage regulator, as shown in
the schematic in Figure 4-44 and the photograph in Figure 4-45. The regula-
tor receives 9 volts from your usual voltage supply, and reduces it to 5 volts,
with the help of a couple of capacitors. You apply the 9 volts to the regulator,
and distribute the 5 volts down the sides of your breadboard instead of the
unregulated voltage that you used previously. Use your meter to verify the
voltage, and make sure you have the polarity clearly marked.
After installing your regulator, take a couple of tactile switches, two 10K resis-
tors, a low-current LED, and a 1K resistor, and set them around a 74HC00 logic Figure 4-45. The voltage regulator and its
two capacitors can fit snugly at the top of
chip as shown in Figure 4-46. You may notice that many of the pins of the chip a breadboard. Remember to apply the 9V
are shorted together and connected to the negative side of the power supply. input voltage at the left pin of the regula-
I’ll explain that in a moment. tor, and distribute the 5V output down the
sides of the breadboard.
9v DC
Fundamentals
0.33uF
Voltage regulators
The simplest versions of these
LM7805
little semiconductors accept a
higher DC voltage on one pin
and deliver a lower DC voltage
on another pin, with a third pin 0.1uF
(usually in the middle) serving as
a common negative, or ground.
You should also attach a couple of
capacitors to smooth the current,
as shown in Figure 4-46.
Typically you can put a 7.5-volt or
9-volt supply on the “input” side of 10K
a 5-volt regular, and draw a precise
5 volts from the “output” side. If
you’re wondering where the extra 10K
voltage goes, the answer is, the 74HC00
regulator turns the electricity into NAND
gate
heat. For this reason, small regula- 1K
tors (such as the one in Figure 4-8)
often have a metal back with a
hole in the top. Its purpose is to
radiate heat, which it will do more
effectively if you bolt it to a piece Figure 4-46. By observing the LED when you press either, both, or neither of the buttons,
you can easily figure out the logical function of the NAND gate.
of aluminum, since aluminum
conducts heat very effectively. The
When you connect power, the LED should light up. Press one of the tactile
aluminum is known as a heat sink,
and you can buy fancy ones that
switches, and the LED remains illuminated. Press the other tactile switch, and
have multiple cooling fins. again the LED stays on. Now press both switches, and the light should go out.
For our purposes, we won’t be Pins 1 and 2 are logic inputs for the 74HC00 chip. Initially they were held at
drawing enough current to require negative voltage, being connected to the negative side of the power supply
a heat sink. through 10K resistors. But each pushbutton overrides its pull-down resistor
and forces the input pin to go positive.
The logic output from the chip, as you saw, is normally positive—but not if
the first input and the second input are positive. Because the chip does a “Not
AND” operation, it’s known as a NAND logic gate. You can see the breadboard
layout in Figure 4-47. Figure 4-48 is a simplified version of the circuit. The U-
shaped thing with a circle at the bottom is the logic symbol for a NAND gate.
No power supply is shown for it, but in fact all logic chips require a power sup-
ply, which enables them to put out more current than they take in. Anytime
you see a symbol for a logic chip, try to remember that it has to have power
to function.
182 Chapter 4
Experiment 19: Learning Logic
The 74HC00 actually contains four NAND gates, each with two logical inputs
and one output. They are arrayed as shown in Figure 4-49. Because only one
gate was needed for the simple test, the input pins of the unused gates were
shorted to the negative side of the power supply.
Pin 14 supplies positive power for the chip; pin 7 is its ground pin. Almost
all the 7400 family of logic chips use the same pins for positive and negative
power, so you can swap them easily.
In fact, let’s do that right now. First, disconnect the power. Carefully pull out
the 74HC00 and put it away with its legs embedded in conductive foam. Sub-
stitute a 74HC08 chip, which is an AND chip. Make sure you have it the right
way up, with its notch at the top. Reconnect the power and use the pushbut-
tons as you did before. This time, you should find that the LED comes on if
the first input AND the second input are both positive, but it remains dark
otherwise. Thus, the AND chip functions exactly opposite to the NAND chip.
Its pinouts are shown in Figure 4-50.
You may be wondering why these things are useful. Soon you’ll see that we Figure 4-48. The structure and function of
can put logic gates together to do things such as create an electronic com- the NAND gate is easier to visualize with
this simplified schematic that omits the
bination lock, or a pair of electronic dice, or a computerized version of a TV power supply for the chip and doesn’t
quiz show where users compete to answer a question. And if you were really attempt to place the wires to fit a bread-
insanely ambitious, you could build an entire computer out of logic gates. board layout.
1 14 1 14
2 13 2 13
3 12 3 12
4 11 4 11
5 10 5 10
6 9 6 9
7400 7408
Quad Quad
7 2-Input 8 7 2-Input 8
NAND gate AND gate
Figure 4-49. The pinouts of the logic gates in a 74HC00chip. Figure 4-50. The pinouts of the logic gates in a 74HC08chip.
Background
rs
w ea
n
An hat
the
th
Bo r the
a
we hat
rs
w ea
b
No one Bo hat
wears the
the hat
Figure 4-51. This slightly frivolous Venn diagram illustrates the various possibilities
for two people, Ann and Bob, who own only one hat.
Another way to summarize the hat-wearing situation is to make the “truth table”
shown in Figure 4-52. The rightmost column shows whether each combination
of propositions can be true. Now check the table in Figure 4-53. It’s the same
table but uses different labels, which describe the pattern you have seen while
using the NAND gate.
Boole published his treatise on logic in 1854, long before it could be applied
to electrical or electronic devices. In fact, during his lifetime, his work seemed
to have no practical applications at all. But a man named Claude Shannon
encountered Boolean logic while studying at MIT in the 1930s, and in 1938 he
published a paper describing how Boolean analysis could be applied to circuits
using relays. This had immediate practical applications, as telephone networks
were growing rapidly, creating complicated switching problems.
184 Chapter 4
Experiment 19: Learning Logic
Background
Ann is Bob is This A very simple telephone problem could be expressed like
wearing wearing this. Suppose two customers in a rural area share one tele-
combination
phone line. If one of them wants to use the line, or the other
the hat the hat can be wants to use it, or neither of them wants to use it, there’s
no problem. But they cannot both use it at once. You may
NO NO TRUE notice that this is exactly the same as the hat-wearing situa-
tion for Ann and Bob.
NO YES TRUE We can easily draw a circuit using two normally closed
relays that creates the desired outcome (see Figure 4-54),
YES NO TRUE but if you imagine a telephone exchange serving many
thousands of customers, the situation becomes very compli-
YES YES FALSE cated indeed. In fact, in Shannon’s time, no logical process
existed to find the best solution and verify that it used fewer
Figure 4-52. The hat-wearing possibilities can be expressed in a components than some other solution.
“truth table.”
Shannon saw that Boolean analysis could be used for this
Input A Input B purpose. Also, if you used an “on” condition to represent
Output numeral 1 and an “off” condition to represent numeral 0,
you could build a system of relays that could count. And if it
OFF OFF ON could count, it could do arithmetic.
When vacuum tubes were substituted for relays, the first
OFF ON ON practical digital computers were built. Transistors took the
place of vacuum tubes, and integrated circuit chips replaced
ON OFF ON transistors, leading to the desktop computers that we now
take for granted today. But deep down, at the lowest levels
ON ON OFF of these incredibly complex devices, they still use the laws
of logic discovered by George Boole. Today, when you use
Figure 4-53. The truth-table from can be relabeled to describe a search engine online, if you use the words AND and OR to
the inputs and outputs of a NAND gate. refine your search, you’re actually using Boolean operators.
Input A Input B
Output
Figure 4-54. This relay circuit could illustrate the desired logic for two telephone customers wanting to share one line, and its
behavior is almost identical to that of the NAND schematic shown in Figure 4-48.
Essentials
NOT
AND NAND OR NOR XNOR
INVERTER
XOR
Logical Outputs
Figure 4-56. American symbols for the six types of two-input logic gates, and the
single-input inverter.
Figure 4-57. Inputs and corresponding outputs for the six types of logic gates (note
that the XNOR gate is seldom used). The minus signs indicate low voltage, close
to ground potential. The plus signs indicate higher voltage, close to the positive
potential of the power supply in the circuit. The exact voltages will vary depending
on other components that may be actively connected.
186 Chapter 4
Experiment 19: Learning Logic
Essentials
OUTPUT
INPUT B
INPUT A
AND
NO NO NO
NO YES NO
YES NO NO
YES YES YES
A A
B B
A
A
B B
Figure 4-58
OUTPUT
INPUT B
INPUT A
NAND
NO NO YES
NO YES YES
YES NO YES
YES YES NO
B A B A
B A B A
Figure 4-59
Essentials
OUTPUT
INPUT B
INPUT A
OR
NO NO NO
NO YES YES
YES NO YES
YES YES YES
A A
B B
A A
B
B
Figure 4-60
OUTPUT
INPUT B
INPUT A
NOR
NO NO YES
NO YES NO
YES NO NO
YES YES NO
A A
B
B
A A
B B
Figure 4-61
188 Chapter 4
Experiment 19: Learning Logic
Essentials
OUTPUT
INPUT B
INPUT A
XOR
NO NO NO
NO YES YES
B A
YES NO YES
YES YES NO
B A
B A
B A
INPUT A
XNOR
NO NO YES
NO YES NO
YES NO NO
YES YES YES
A B A B
A B A B
Figure 4-63
Background
190 Chapter 4
Experiment 19: Learning Logic
Background
Background
Abbreviations
When looking at data sheets, you are likely to encounter some or all of these
abbreviations:
• VOH min: Minimum output voltage in high state
• VOL max: Maximum output voltage in low state
• VIH min: Minimum input voltage to be recognized as high
• VIL max: Maximum input voltage recognized as low
Background
192 Chapter 4
Experiment 19: Learning Logic
Fundamentals
single-input inverters, as shown in the following table. tions of the logic chips that
you are most likely to use. 2 13
1 14 1 14 1 14 1 14
2 13 2 13 2 13 2 13
3 12 3 12 3 12 3 12
4 11 4 11 4 11 4 11
5 10 5 10 5 10 5 10
6 9 6 9 6 9 6 9
7410 7411 7420
7404 Hex Triple Triple Dual
7 Inverter 8 7 3-Input 8 7 3-Input 8 7 4-Input 8
NAND gate AND gate NAND gate
1 14 1 14 1 14 1 14
2 13 2 13 2 13 2 13
3 12 3 12 3 12 3 12
4 11 4 11 4 11 4 11
5 10 5 10 5 10 5 10
6 9 6 9 6 9 6 9
7421 7427 7432 7486
Dual Triple Quad Quad
7 4-Input 8 7 3-Input 8 7 2-Input 8 7 2-Input 8
AND gate NOR gate OR gate XOR gate
Fundamentals
Maximum 0.8V
Maximum 1.0V
consumption
3.5V
Minimum
consumption
2.0V
Minimum
at each pin: at each pin:
74HCXX 5V 74LSXX 5V
Logic Gate DC Logic Gate DC
At least 4.4V
output output
2.7V
At least
194 Chapter 4
Experiment 19: Learning Logic
Fundamentals
Figure 4-78. The output from one logic gate must not be allowed to feed back into the output from another logic gate. Diodes can
be used to isolate them, or they can be linked via another gate.
5VDC Regulated In the 74HCxx logic family, each input of a logic gate consumes just a micro-
amp, while the output can source 4 milliamps. This seems paradoxical: how
can the chip give out more than it takes in? The answer is that it also consumes
power from the power supply attached to pins 7 and 14. That’s where the ad-
ditional electricity comes from.
Because the logical output from a chip can be greater than the logical input,
10K
we can put the chip in a state where it keeps itself “switched on” in a way which
74HC08
AND is similar to the way the relay in the alarm project was wired to lock itself on.
gate The simplest way to do this in a logic chip is by feeding some of the output
1K
back to one of the inputs.
Figure 4-79 shows an AND gate with one of its inputs wired to positive and its
other input held low by a pull-down resistor, with a pushbutton that can make
Figure 4-79. Using a diode, the logical the input high. A signal diode connects the output of the chip back to the
output from a gate can be allowed to feed pushbutton-controlled input. Remember that the diode has a mark on it indi-
back to one of its inputs, so that the gate cating the end which should be connected to the negative side of the power
latches after receiving a brief logical input
pulse. supply, which in this case will be the end of the 10K resistor.
The schematic in Figure 4-79 shows how the circuit should look in breadboard
format. Figure 4-80 shows it in a simpler format.
From this point on, I won’t bother to show the power regulator and the capacitors
associated with it. Just remember to include them every time you see the power sup-
ply labeled as “5V DC Regulated.”
When you switch on the power, the LED is dark, as before. The AND gate needs
a positive voltage on both of its logical inputs, to create a positive output, but
it now has positive voltage only on one of its inputs, while the other input
is pulled down by the 10K resistor. Now touch the pushbutton, and the LED
comes on. Let go of the pushbutton, and the LED stays on, because the posi-
tive output from the AND gate circulates back through the diode and is high
enough to overcome the negative voltage coming through the pull-down
resistor.
The output from the AND gate is powering its own input, so the LED will stay
on until we disconnect it. This arrangement is a simple kind of “latch,” and can
be very useful when we want an output that continues after the user presses
and releases a button.
You can’t just connect the output from the gate to one of its inputs using an
ordinary piece of wire, because this would allow positive voltage from the tac-
tile switch to flow around and interfere with the output signal. Remember, you
must never apply voltage to the output pin of a logic gate. The diode prevents
this from happening.
Figure 4-80. The breadboard-format sche-
matic in is simplified here to show more If you’ve grasped the basics of logic gates, you’re ready now to continue to our
clearly the way in which a gate can latch first real project, which will use all the information that I’ve set out so far.
itself after receiving an input pulse.
196 Chapter 4
Experiment 20: A Powerful Combination
1 2 3
4 5 6
7 8 9
#
* 0
Figure 4-82. A keypad of the type required for Experiment 20 incorporates a common
terminal connected to one side of each of the 12 pushbuttons. The wire from the common
terminal is shown red, here, to make it more easily identifiable.
• Keypads that use “matrix encoding” won’t work with the circuit that I’m
going to describe. If the Velleman keypad, which I recommend, is unavail-
able, and you can’t find another like it, you can use 12 separate SPST push-
buttons. Of course, that will cost a little more.
• 74HC08 logic chip containing four AND gates. Quantity: 1.
• 74HC04 logic chip containing six inverters. Quantity: 1.
• 555 timer chip. Quantity: 1.
The Schematic
This time I’d like you to study the schematic before building anything. Let’s
start with the simplified version, shown in Figure 4-83.
5VDC
Regulated
Logic gate
power input pins
*
0
1 8
2
555
3 timer
8
Computer
on switch
9
Figure 4-83. A simplified schematic showing the basic structure of the combination lock
circuit.
198 Chapter 4
Experiment 20: A Powerful Combination
Incorrect Inputs
What happens if you enter the wrong code? If you press any button other than
1, 4, or 7, it sends positive voltage to the inverter near the top of the sche-
matic. The positive voltage overwhelms the negative voltage being applied to
the inverter through a pull-down resistor, and causes the inverter to output a
negative voltage, which it applies to one of the logical inputs of the first AND
gate. If the AND gate was locked on, the negative input will switch it off. If it
was supplying the second AND gate, it’ll switch that one off too.
Thus, any error when entering the first, second, or third digit of the secret code
will reset the AND gates, forcing you to begin the sequence all over again.
What if you enter 1, 4, and 7 out of their correct sequence? The circuit won’t
respond. The third AND gate needs a high input supplied by the second AND
gate, and the second AND gate needs a high input supplied by the first AND
gate. So you have to activate the AND gates in the correct sequence.
Questions
Why did I use a 555 timer to deliver the pulse to the relay? Because the logical
output from an AND gate cannot deliver sufficient power. I could have passed
it through a transistor, but I liked the idea of a pulse of a fixed length to flip the
relay and illuminate an LED for about 1 second, regardless of how briefly the user
presses the 7 button.
Why do I need three LEDs? Because when you’re punching buttons to un-
lock your computer, you need to know what’s going on. The Power On LED
reassures you that your battery isn’t dead. The Relay Active LED tells you that
the system is now unlocked, in case you are unable to hear the relay click. The
System Relocked LED reassures you that you have secured your computer.
Because all the LEDs are driven either directly from the 5-volt supply or from
the output of the 555 timer, they don’t have to be low-current LEDs and can be
used with 330Ω series resistors, so they’ll be nice and bright.
How do you connect the keypad with the circuit? That’s where your ribbon
cable comes in. You carefully strip insulation from each of the conductors,
and solder them to the contact strip or edge connector on your keypad. Push
the conductors on the other end of the cable into your breadboard (when
you’re test-building the circuit) or solder them into perforated board (when
you’re building it permanently). Find a convenient spot inside your computer
case where you can attach the perforated board, with double-sided adhesive
or small bolts or whatever is convenient. Include a 9-volt battery carrier, and
don’t forget your power regulator to step the voltage down to 5 volts.
Breadboarding
No doubt you have realized by now that breadboards are very convenient as a
quick way to push in some components and create connections, but the layout
of their conductors forces you to put components in unintuitive configurations.
Still, if you carefully compare the breadboard schematic in Figure 4-83 with the
simplified schematic in Figure 4-84, you’ll find that the connections are the same.
200 Chapter 4
Experiment 20: A Powerful Combination
To help it make sense, I’ve shown the logic gates that exist inside the chips. I’ve
also colored the power supply wires, as before, to reduce the risk of confusion. If you build the circuit and you can’t
The positive side of the supply goes only to the common terminal on your understand why everything’s dead,
it’s most likely because you forgot to
keypad, and you have to press the asterisk key to send the power back down hold down the asterisk button.
the ribbon cable, to supply the chips.
Note that the “wrong” numbers on the keypad are all shorted together. This
will create some inconvenience if you want to change the combination in the
future. I’ll suggest a different option in the “enhancements” section that fol-
lows. For now, ideally, you should run a wire from every contact on your key-
pad, down to your circuit on its breadboard, and short the “wrong” keypad
numbers together with jumper wires on the breadboard.
Also note that if you use a meter to test the inputs to the AND gates, and you
touch your finger against the meter probe while doing so, this can be suffi-
cient to trigger the sensitive CMOS inputs and give a false positive.
5VDC Regulated
(from 9V battery)
330
*
7
10K
1
74HC08
10K
4
2
10K
3
6 74HC04
100K
9 330 10uF
555
0.1uF
330
Computer
power-up
switch
#
Figure 4-84. The combination lock schematic redrawn to show how the components can
be laid out on a breadboard.
202 Chapter 4
Experiment 20: A Powerful Combination
Power Up
button on
computer
Heat-shrink tubing
(not yet shrunk)
To your
latching
relay
Solder
joints
Connector
Computer motherboard
Figure 4-85. The combination lock project can be interfaced with a typical desktop com-
puter by cutting one conductor in the wire from the “power up” pushbutton, soldering an
extension, and covering the joints with heat-shrink tube.
Enhancements
At the end of any project, there’s always more you can do.
To make this setup more secure, you could remove the usual screws that secure
the case of the computer, and replace them with tamper-proof screws. Check any
online source for “tamper-proof screws,” such as http://www.mcmaster.com. Natu-
rally, you will also need the special tool that fits the screws, so that you can install
them (or remove them, if your security system malfunctions for any reason).
204 Chapter 4
Experiment 21: Race to Place
The Goal
On quiz shows such as Jeopardy, contestants race to answer each question.
The first person who hits his answer button automatically locks out the other
contestants, so that their buttons become inactive. How can we make a circuit
that will do the same thing?
If you search online, you’ll find several hobby sites where other people have
suggested circuits to work this way, but they lack some features that I think are
necessary. The approach I’m going to use here is both simpler and more elabo-
rate. It’s simpler because it has a very low chip count, but it’s more elaborate in
that it incorporates “quizmaster control” to make a more realistic game.
I’ll suggest some initial ideas for a two-player version. After I develop that idea,
I’ll show how it could be expanded to four or even more players.
A Conceptual Experiment
I want to show how this kind of project grows from an idea to the finished
version. By going through the steps of developing a circuit, I’m hoping I may
inspire you to develop ideas of your own in the future, which is much more
valuable than just replicating someone else’s work. So join me in a conceptual
experiment, thinking our way from a problem to a solution. Button Button
Blocker Blocker
First consider the basic concept: two people have two buttons, and whoever
goes first locks out the other person. I always find it helps me to visualize this
kind of thing if I draw a sketch, so that’s where I’ll begin. In Figure 4-87, the
signal from each button passes through a component that I’ll call a “button
blocker,” activated by the other person’s button. I’m not exactly sure what the
button blocker will be or how it will work, yet.
Now that I’m looking at it, I see a problem here. If I want to expand this to three Figure 4-87. The basic concept of the quiz
players, it will get complicated, because each player must activate the “button project is that the output from one button
should feed back to intercept the output
blockers” of two opponents. Figure 4-88 shows this. And if I have four players,
of another button. At this point, the way in
it’s going to get even more complicated. which the “button blocker” circuit works
has not been figured out.
Anytime I see this kind of complexity, I think there has to be a better way.
Chips, Ahoy! 205
Experiment 21: Race to Place
Also, there’s another problem. After a player lets his finger off the button, the
other players’ buttons will be unblocked again. I need a latch to hold the signal
from the first player’s button and continue to block the other players.
Figure 4-88. The quiz concept becomes more complicated when an additional pushbutton
is added. Now each button must block two other buttons. If a fourth button is added, the
circuit will become unmanageably complex. There has to be a better way.
This now sounds even more complicated. But wait a minute, if I have a latch
which allows the winning player to take his finger off his button, I don’t care if
any of the buttons are being pressed anymore—including the button of the
winning player. As soon as his signal is latched, all the buttons can be blocked.
This makes things much simpler. I can summarize it as a sequence of events:
1. First player presses his button.
2. The signal is latched.
3. The latched signal feeds back and blocks all the buttons.
The new sketch in Figure 4-89 shows this. Now the configuration is modular,
and can be expanded to almost any number of players, just by adding more
modules.
There’s something important missing, though: a reset switch, to put the sys-
tem back to its starting mode after the players have had time to press their
buttons and see who won. Also, I need a way to prevent players from pressing
their buttons too soon, before the quizmaster has finished asking the ques-
tion. Maybe I can combine this function in just one switch, which will be under
the quizmaster’s control. In its Reset position, the switch can reset the system
and remove power to the buttons. In its Play position, the switch stops hold-
ing the system in reset mode, and provides power to the buttons. Figure 4-90
shows this. I’ve gone back to showing just two players, to minimize the clutter
of lines and boxes, but the concept is still easily expandable.
206 Chapter 4
Experiment 21: Race to Place
Reset
Latch Latch Latch Latch Latch
Figure 4-89. If a latch is added below each button, it can Figure 4-90. A quizmaster switch will be needed to
retain one input and then block all inputs from all buttons. activate the buttons initially and then reset the circuit
This simplifies the concept. after a winning input has been recorded.
Now I have to deal with a logic problem in the diagram. The way I’ve drawn
it, after the output from the lefthand latch goes up to the “button blockers,” it
can also run down the wire to the other half of the circuit (against the direc-
tion to the arrows), because everything is joined together. In other words, if
the lefthand LED lights up, the righthand LED will light up, too. How can I stop
this from happening?
Well, I could put diodes in the “up” wires to block current from running down
them. But I have a more elegant idea: I’ll add an OR gate, because the inputs to
an OR gate are separated from each other electrically. Figure 4-91 shows this.
OR
Usually an OR gate has only two logical inputs. Will this prevent me from adding
more players? No, because you can actually buy an OR that has eight inputs. If
any one of them is high, the output is high. For fewer than eight players, I can
short the unused inputs to ground, and ignore them.
Play Button Button
Looking again at Figure 4-91, I’m getting a clearer idea of what the thing I’ve Blocker Blocker
called a “button blocker” should actually be. I think it should be another logic
gate. It should say, “If there’s only one input, from a button, I’ll let it through.
But if there is a second input from the OR gate, I won’t let it through.” Reset
Latch Latch
That sounds like a NAND gate, but before I start choosing chips, I have to de-
cide what the latch will be. I can buy an off-the-shelf flip-flop, which flips “on” if
it gets one signal and “off” if it gets another, but the trouble is, chips containing
flip-flops tend to have more features than I need for a simple circuit like this.
Therefore I’m going to use 555 timers again, in flip-flop mode. They require
Figure 4-91. To prevent the output from one
very few connections, work very simply, and can deliver a good amount of cur-
latch feeding back around the circuit to the
rent. The only problem with them is that they require a negative input at the output from another latch, the outputs can
trigger pin to create a positive output. But I think I can work with that. be combined in an OR gate.
So now, finally, here’s a simplified schematic, in Figure 4-92. I like to show the
R1
S2 S3
pins of the 555 timers in their correct positions, so I had to move the compo-
S1 nents around a little to minimize wire crossovers, but you can see that logi-
cally, it’s the same basic idea.
R2 R3
Before you try to build it, just run through the theory of it, because that’s the
final step, to make sure there are no mistakes. The important thing to bear in
OR1 OR2 OR3 mind is that because the 555 needs a negative input on its trigger pin to create
its output, when any of the players presses a button, the button has to create a
R4 negative “flow” through the circuit. This is a bit counterintuitive, so I’m includ-
1 8 ing a three-step visualization in Figure 4-93, showing how it will work.
555
timer In Step 1, the quizmaster has asked a question and flipped his switch to the
right, to supply (negative) power to the players’ buttons. So long as no one
presses a button, the pull-up resistors supply positive voltage to OR2 and OR3.
An OR gate has a positive output if it has any positive input, so OR2 and OR3
1 8 keep the trigger inputs of the 555 timers positive. Their outputs remain low,
and nothing is happening yet.
555
timer
In Step 2, the lefthand player has pressed his button. Now OR2 has two nega-
tive inputs, so its output has gone low. But IC1 hasn’t reacted yet.
Figure 4-92. Now that the basic concept In Step 3, just a microsecond later, IC1 has sensed the low voltage on its trig-
of the quiz circuit has been roughed out, ger, so its output from pin 3 has gone high, lighting the LED. Remember, this
specific components can be inserted, with 555 timer is in flip-flop mode, so it locks itself into this state immediately.
compatible inputs and outputs.
Meanwhile its high output also feeds back to OR1. Because OR1 is an OR gate,
just one high input is enough to make a high output, so it feeds this back to
OR2 and OR3. And now that they have high inputs, their outputs also go high,
and will stay high, regardless of any future button-presses.
R1 S2 S3 R1 S2 S3 R1 S2 S3
S1 S1 S1
R2 R3 R2 R3 R2 R3
R4 R4 R4
1 8 1 8 1 8
1 8 1 8 1 8
Figure 4-93. These three schematics show the prevalence of higher and lower voltages
(red and blue lines) through the quiz circuit when a pushbutton is pressed.
Because OR2 and OR3 now have high inputs and outputs, IC1 and IC2 cannot be
triggered. But IC1 is still locked into its “on” state, keeping the LED illuminated.
208 Chapter 4
Experiment 21: Race to Place
The only way to change IC1 is if the quizmaster flips his switch back to the left.
That applies negative power to the reset pins of both the timers. Consequently R1
S2 S3 S4
their outputs go low, the LED goes out, and the circuit goes back into the same S1
state as where it started. Having reset it, the quizmaster can ask another ques-
R2 R3
tion, but the players’ buttons are not activated until the quizmaster flips the
switch back to the right again.
OR1 OR2 OR3 OR4
There’s only one situation that I haven’t addressed: what if both players press
their buttons absolutely simultaneously? In the world of digital electronics, R4
1 8
this is highly unlikely. Even a difference of a microsecond should be enough
time for the circuit to react and block the second button. But if somehow both IC1
buttons are pressed at the same instant, both of the timers should react, and
both of the LEDs will light up, showing that there has been a tie.
In case you feel a little uncertain about the way in which a two-player circuit 1 8
Breadboarding It 1 8
Now it’s time to create a schematic that’s as close to the breadboard layout
IC3
as possible, so that you can build this thing easily. The schematic is shown in
Figure 4-95 and the actual components on a breadboard are in Figure 4-96.
Because the only logic gates that I’ve used are OR gates, and there are only three
Figure 4-94. The two-player schematic in
of them, I just need one logic chip: the 74HC32, which contains four 2-input OR can be easily upgraded to a three-player
gates. (I’ve grounded the inputs to the fourth). The two OR gates on the left version, as shown here, provided the first
side of the chip have the same functions as OR2 and OR3 in my simplified OR gate can handle three inputs.
schematic, and the OR gate at the bottom-right side of the chip works as OR1,
receiving input from pin 3 of each 555 timer. If you have all the components,
you should be able to put this together and test it quite quickly.
You may notice that I’ve made one modification of the previous schematic. A
0.01 µF capacitor has been added between pin 2 of each 555 timer (the Input)
and negative ground. Why? Because when I tested the circuit without the ca-
pacitors, sometimes I found that one or both of the 555 timers would be trig-
gered simply by flipping S1, the quizmaster switch, without anyone pressing
a button.
At first this puzzled me. How were the timers getting triggered, without any-
one doing anything? Maybe they were responding to “bounce” in the quiz-
master switch. Sure enough, the small capacitors solved the problem. They
may also slow the response of the 555 timers fractionally, but not enough to
interfere with slow human reflexes.
As for the buttons, it doesn’t matter if they “bounce,” because each timer locks
itself on at the very first impulse and ignores any hesitations that follow.
You can experiment building the circuit, disconnecting the 0.01 µF capacitors,
and flipping S1 to and fro a dozen times. If you have a high-quality switch, you
may not experience any problem. If you have a lower-quality switch, you may
see a number of “false positives.” I’m going to explain more about “bounce,”
and how to get rid of it, in the next experiment.
5V DC regulated
10K
10K
S2
S3
74HC32
OR2
OR3
S1
OR1
0.01 1 8
555
330
0.01 1 8
555
330 10K
Figure 4-95. Applying the simplified schematic to a breadboard inevitably entails Figure 4-96. The quiz schematic applied to a
a wiring layout that is less intuitively obvious and appears more complex. The breadboard, to test the concept prior to full-scale
connections are the same, though. implementation.
Enhancements
After you breadboard the circuit, if you proceed to build a permanent version,
I suggest that you expand it so that at least four players can participate. This
will require an OR gate capable of receiving four inputs. The 74HC4078 is the
obvious choice, as it allows up to eight. Just connect any unused inputs to
negative ground.
Alternatively, if you already have a couple of 74HC32 chips and you don’t want
to bother ordering a 74HC4078, you can gang together three of the gates in-
side a single 74HC32 so that they function like a four-input OR. Look at the
simple logic diagram in Figure 4-97 showing three ORs, and remember that
the output from each OR will go high if at least one input is high.
And while you’re thinking about this, see if you can figure out the inputs and
output of three ANDs in the same configuration.
For a four-player game, you’ll also need two additional 555 timers, of course,
Figure 4-97. Although a four-input OR gate and two more LEDs, and two more pushbuttons.
is not manufactured, its functionality can
be achieved easily by linking three 2-input As for creating a schematic for the four-player game—I’m going to leave that
OR gates together. to you. Begin by sketching a simplified version, just showing the logic symbols.
Then convert that to a breadboard layout. And here’s a suggestion: pencil, pa-
per, and an eraser can still be quicker, initially, than circuit-design software or
graphic-design software, in my opinion.
210 Chapter 4
Experiment 22: Flipping and Bouncing
1K
10K
1K
10K
74HC02
Figure 4-98. A simple circuit to test the behavior of two NOR gates wired as a simple flip-
flop that retains its state after an input pulse ceases.
Now I want you to do something odd. Please disconnect the SPDT switch by
taking hold of the wire that connects the positive power supply to the pole of
the switch, and pulling the end of the wire out of the breadboard. When you
do this, you may be surprised to find that the LED remains lit.
Push the wire back into the breadboard, flip the switch, and the first LED
should go out, while the other LED should become lit. Once again, pull out the
wire, and once again, the LED should remain lit.
Here’s the take-home message:
• A flip-flop requires only an initial pulse.
• After that, it ignores its input.
How It Works
Two NOR gates or two NAND gates can function as a flip-flop:
• Use NOR gates when you have a positive input from a double-throw switch.
• Use NAND gates when you have a negative input from a double-throw
switch.
Either way, you have to use a double-throw switch.
I’ve mentioned the double-throw switch three times (actually, four times if you
count this sentence!) because for some strange reason, most introductory books
fail to emphasize this point. When I first started learning electronics, I went crazy
trying to understand how two NORs or two NANDs could debounce a simple
SPST pushbutton—until finally I realized that they can’t. The reason is that
when you power up the circuit, the NOR gates (or NAND gates) need to be
told in which state they should begin. They need an initial orientation, which
comes from the switch being in one state or the other. So it has to be a double-
throw switch. (Now I’ve mentioned it five times.)
I’m using another simplified multiple-step schematic, Figure 4-99, to show the
changes that occur as the switch flips to and fro with two NOR gates. To refresh
your memory, I’ve also included a truth table showing the logical outputs from
NOR gates for each combination of inputs.
Figure 4-99. Using two NOR gates in conjunction with a positive input through a SPDT
switch, this sequence of four diagrams shows how a flip-flop circuit responds.
Suppose that the switch is turned to the left. It sends positive current to the
lefthand side of the circuit, overwhelming the negative supply from the pull-
down resistor, so we can be sure that the NOR gate on the left has one posi-
tive logical input. Because any positive logical input will make the NOR give
a negative output (as shown in the truth table), the negative output crosses
over to the righthand NOR, so that it now has two negative inputs, which make
it give a positive output. This crosses back to the lefthand NOR gate. So, in this
configuration everything is stable.
Now comes the clever part. Suppose that you move the switch so that it
doesn’t touch either of its contacts. (Or suppose that the switch contacts are
bouncing, and failing to make a good contact. Or suppose you disconnect the
switch entirely.) Without a positive supply from the switch, the lefthand input
212 Chapter 4
Experiment 22: Flipping and Bouncing
of the left NOR gate goes from positive to negative, as a result of the pull-
down resistor. But the righthand input of this gate is still positive, and one
positive is all it takes to make the NOR maintain its negative output, so nothing
changes. In other words, the circuit has “flopped” in this state.
Now if the switch turns fully to the right and supplies positive power to the
righthand pin of the right NOR gate, quick as a flash, that NOR recognizes that
it now has a positive logical input, so it changes its logical output to negative.
That goes across to the other NOR gate, which now has two negative inputs,
so its output goes positive, and runs back to the right NOR.
In this way, the output states of the two NOR gates change places. They flip,
and then flop there, even if the switch breaks contact or is disconnected again.
The second set of drawings in Figure 4-100 shows exactly the same logic, using
a negatively powered switch and two NAND gates. You can use your 74HC00
chip, specified in the parts list for this experiment, to test this yourself.
Figure 4-100. The schematic from Figure 4-99 can be rewired with NAND gates and a
negative switched input.
Seeing Binary
The counter that we dealt with before was unusual, in that its outputs were de-
signed to drive seven-segment numerals. A more common type has outputs
that count in binary code.
The 74LS92 pinouts are shown in Figure 4-101. Plug the chip into your bread-
board and make connections as shown in Figure 4-102. Initially, the 555 timer
will drive the counter in slow-motion, at around 1 step per second. Figure
4-103 shows the actual components on a breadboard.
Note that the counter has unusual power inputs, on pins 5 and 10 instead of
at the corners. Also four of its pins are completely unused, and do not connect
with anything inside the chip. Therefore, you don’t need to attach any wire to
them on the outside.
214 Chapter 4
Experiment 23: Nice Dice
Clock Clock
input B 1 14 input A
No connection 2 13 No connection
Binary
No connection 3 12 output A
Binary
No connection 4 11 output B
5 10
Negative Binary
to enable 6 9 output C
Negative
74LS92 Binary
to enable 7 Counter 8 output D
Figure 4-101. The unusual pin assignments include four that have no connection of any
kind inside the chip, and can be left unattached.
1 8
100K
555
0.1uF 10uF
74LS92
Low- 4K7
Current 4K7
LEDs 4K7
Figure 4-102. This simple circuit uses a 555 timer running Figure 4-103. The breadboard version of the schematic
slowly to control the 74LS92 binary counter and display the in Figure 4-102 to display the outputs from a 74LS92
succession of high states from its outputs. counter.
Now we come to the first new and difficult fact about the 74LSxx generation
of TTL chips that makes them less desirable, for our purposes, than the 74HCxx
generation of CMOS chips that I have recommended in previous projects. The
modern and civilized HC chips will source 4mA or sink 4mA at each logical
output, but the older LS generation is fussier. It will sink around 8mA into each
output pin from a positive source, but when its output is high, it hardly gives
you anything at all. This is a very basic principle:
• Outputs from TTL logic chips are designed to sink current.
• They are not designed to source significant current.
In fact, the 74LS92 is rated to deliver less than half a milliamp. This is quite
acceptable when you’re just connecting it with another logic chip, but if you
want to drive an external device, it doesn’t provide much to work with.
The proper solution is to say to the chip, “All right, we’ll do it your way,” and set
things up with a positive source that flows through a load resistor to the LED
that you want to use, and from there into the output from the chip. This is the
“better” option shown in Figure 4-104.
1 14 1 14
74LSxx 74LSxx
series series
logic logic
chip chip
Not
so good Better
Figure 4-104. Most TTL chips, including those in the LS generation, are unable to source
much current from their logical output pins (left) and should usually be wired to sink cur-
rent from a positive source (right).
The only problem is that now the LED lights up when the counter’s output is
low. But the counter is designed to display its output in high pulses. So your
LED is now off when it should be on, and on when it should be off.
You can fix this by passing the signal through an inverter, but already I’m get-
ting impatient with this inconvenience. My way around the problem, at least
for demo purposes, is to use the “Not so good” option in Figure 4-104 and
make it work by connecting a very-low-current LED with a large 4K7 load resis-
tor. This will enable us to “see” the output from the counter without asking it to
give more than its rated limit, and if you want to create a more visibly powerful
216 Chapter 4
Experiment 23: Nice Dice
display for a finished version of the dice circuit, I’ll deal with that later. Accord- 0 000
ing to my meter, the 4K7 resistor holds the current between 0.3mA and 0.4mA,
which is the counter’s rated maximum.
Set up your initial version of the circuit as shown in Figures 4-102 and 4-103. Be 1 001
careful when you wire the positive and negative power supply to the counter
chip, with its nonstandard pin assignments. 2 010
The 555 will run in astable mode, at about 1 pulse per second. This becomes
the clock signal for the counter. The first three binary outputs from the counter
then drive the three LEDs. 3 011
The counter advances when the input signal goes from high to low. So when
the LED beside the 555 timer goes out, that’s when the counter advances. 4 100
If you stare at the pattern generated by the outputs for long enough, you may
be able to see the logic to it, bearing in mind that its zero state is when they are 5 101
all off, and it counts up through five more steps before it repeats. The diagram
in Figure 4-105 shows this sequence. If you want to know why the pattern Figure 4-105. The three output pins of the
74LS92 counter have high states shown by
works this way, check the following section, “Theory: Binary arithmetic.” the red circles as the counter steps from
000 to 101 in binary notation.
Theory 0
1
Binary arithmetic
The rule for binary counting is just a variation of the rule that we normally use
2
for everyday counting, probably without thinking much about it. In a 10-based 3
system, we count from 0 to 9, then carry 1 over to the next position on the left,
and go from 0 to 9 again in the right-most position. We repeat this procedure 4
until we get to 99, then carry a 1 over to a new position to make 100, and con-
tinue counting. 5
In binary we do the same thing, except that we restrict ourselves to digits 0 and 6
1 only. So begin with 0 in the rightmost position, and count up to 1. As 1 is our
limit, to continue counting we carry 1 over to the next place on the left, and
7
start again from 0 in the right-most position. Count up to 1, then add 1 to the 8
next place on the left—but, it already has a 1 in it, so it can’t count any higher.
So, carry 1 from there one space further, to the next place beside that—and so on. 9
If a glowing LED represents a 1, and a dark LED represents a 0, the diagram in 10
Figure 4-105 shows how the 74LS92 counts up from 0 to (decimal) 6 or (binary)
101 in its inimitable fashion. I’ve also included a diagram in Figure 4-106 show- 11
ing how a counter with four binary outputs would display decimal numbers
from 0 through 15, again using the LEDs to represent 1s and 0s.
12
Here’s a question for you: how many LEDs would you need to represent the 13
decimal number 1024 in binary? And how many for 1023?
14
Obviously binary code is ideally suited to a machine full of logic components
that either have a high or a low state. So it is that all digital computers use 15
binary arithmetic (which they convert to decimal, just to please us). Figure 4-106. A hexadecimal (16-based)
binary counter would generate this suc-
cession of high states from its four output
pins as it counts from 0 through 15 in
decimal notation.
Getting back to our project: I want to take the three binary outputs and make
them create patterns like the spots on a die. How can I do this? Quite easily, as
it turns out.
I’m assuming that I’ll use seven LEDs to simulate the patterns of spots on a
die. These patterns can be broken down into groups, which I have assigned to
the three outputs from the counter in Figure 4-108. The first output (farthest
to the right) can drive an LED representing the dot at the center of the die
face. The second (middle) output can drive two more diagonal LEDs. The third
output must switch on all four corner LEDs.
This will work for patterns 1 through 5, but won’t display the die pattern for a
6. Suppose I tap into all three outputs from the counter with a three-input NOR
gate. It has an output that goes high only when all three of its inputs are low,
so it will only give a high output when the counter is beginning with all-low
outputs. I can take advantage of this to make a 6 pattern.
Note that it’s bad practice to mix the LS generation of TTL chips with the HC
generation of CMOS chips, as their input and output ranges are different; so,
the NOR chip has to be a 74LS27, not a 74HC27.
We’re ready now for a simple schematic. In Figure 4-107 I’ve colored some of
the wires just to make it easier for you to distinguish them. The colors have no
other significance.
Clock input
74LS92 counter
Binary outputs C B A
Each of the three
counter outputs
lights these groups
NOR D2 D3 D4 Special
case to
D1 create
a six
LO LO LO pattern
LO LO HI
to form these patterns
The groups combine
218 Chapter 4
Experiment 23: Nice Dice
Each of the LEDs is grounded through a separate 4K7 load resistor. Unfortu-
nately, this means that when they are displaying the pattern for a 6, all of them
are running in parallel from the output of the NOR gate, which overloads it.
As long as you don’t leave the display in this mode for very long periods, it
shouldn’t cause a problem. You could compensate by increasing the load re-
sistors, or by running pairs of the LEDs through one resistor, but this will make
them so dim that they’ll be difficult to see, as they’re so close to their lower
limit for current already.
Notice how I have added four signal diodes, D1 through D4. When Output C
goes high, it has to illuminate all four corner LEDs, and so its power goes into
the brown wire as well as the gray wire. But we must never allow one output
to feed back into another, so D4 is needed to protect Output B when Output
C is high. 5V DC regulated power supply
And, we have to protect the output from the NOR gate when either Output C
1K
555
board format, while Figure 4-110 shows the test version that I built. Note that
the unused logical inputs on the 74LS27 chip are shorted together and con-
nected to the positive side of the power supply. Here’s the rule:
74LS92
• When using CMOS chips (such as the HC series), connect unused logical
inputs to the negative side of the power supply.
• When using TTL chips (such as the LS series), connect unused logical in-
puts to the positive side of the power supply.
74LS27
I assume that you have had enough fun watching the LEDs count slowly, so
I’ve changed the capacitor and resistor values for the 555 to increase its speed
from approximately 1 pulse per second to about 50,000 pulses per second. D4
The counter could run much faster than this, but I just want it to cycle fast D2
enough so that when the user presses and releases a button, the count will D1
D3
stop at an unforeseeable number.
The button starts and stops the 555 timer by applying and releasing power
to the timing circuit only. This is the equivalent of shaking and then throwing
the die.
While the counter is running fast, the LEDs are flashing so fast that all of them
will seem to be on at once. At the same time, the circuit charges a new 68 µF
capacitor, which I have added between the pushbutton and ground. When
you release the button, this capacitor discharges itself through the 1K timing
resistor. As the charge dissipates, the timing capacitor will take longer and
longer to charge, and discharge, and the frequency of the 555 will gradually All above are 4K7
diminish. Consequently the LED display will also flash slower, like the reel on a
Figure 4-109. With some extra compo-
Las Vegas slot machine gradually coming to a stop. This increases the tension nents, the schematics from Figures 4-102
as players can see the die display counting to the number that they’re hoping and 4-107 can be combined to make the
for—and maybe going one step beyond it. working dice simulation.
Note that to maximize this effect, the button has to be held down for a full
second or more, so that the 68 µF capacitor becomes fully charged before the
button is released.
So, this circuit now fulfills the original goal. But can it be better? Of course
it can.
Enhancements
The main thing I want to improve is the brightness of the LEDs. I could add a
transistor to amplify the current to each one, but there’s a simpler alternative:
a TTL “open collector” inverter.
I want to use an inverter because in the world of TTL, as I mentioned earlier, we
can sink much more power into the output pin of a chip than we can source
from it. So, I’m going to turn each LED the other way around and connect their
load resistors to the positive side of the power supply. This way, they’ll sink
their power into the outputs of the inverter.
And the great advantage of an “open collector” version of the inverter chip is
that it is designed to sink much more current than a normal TTL logic chip. It is
rated for 40mA per pin. The only disadvantage is that it cannot source any cur-
rent at all; instead of its output going high, it just behaves like an open switch.
But that’s OK for this circuit.
Figure 4-110. The electronic dice schematic
applied to a breadboard, with a pushbut- So the next and final schematic, in Figure 4-111, includes the 74LS06 invert-
ton at the top to start and stop the coun- er, which has also been added to the breadboarded version shown in Figure
ter, and 7 LEDs at the bottom to display 4-112. I suggest that you put aside the little low-current LEDs and substitute
the output.
some normal-size ones. Using Kingbright “standard” WP15031D 5mm LEDs, I
find that each draws almost exactly 20mA with a voltage drop of about 2V
with a 120 ohm series resistor. Because each output pin from the 74LS06 in-
verter powers no more than two LEDs at a time, this is exactly within its speci-
fication. I suggest that if you build this circuit, you check the consumption of
your particular choice of LEDs and adjust the resistors if necessary.
Remember: to measure the voltage drop across an LED, simply touch the
probes of your meter across it while it is illuminated. To measure the current,
disconnect one side of the LED and insert the meter, in milliamp mode, be-
tween the leg of the LED and the contact that it normally makes in the circuit.
For a really dramatic display, you can get some 1 cm diameter LEDs (Figure
4-113). Check the specification, and you should find that many of these don’t
use more power than the usual 5 mm type. But whatever kind you use, don’t
forget to turn them around so that their negative sides face toward the in-
verter, and their positive sides face the resistors, which are connected to the
positive side of the power supply.
One last detail: I had to add two 10K resistors to this version of the circuit. Can
you see why? Diodes D1 through D4 are designed to transmit positive voltage
through to the inverter when appropriate, but they prevent the inputs of the
inverter from “seeing” the negative side of the power supply when the counter
outputs are low. These inverter inputs require pull-down resistors to prevent
them from “floating” and producing erroneous results.
220 Chapter 4
Experiment 23: Nice Dice
68uF 1K
1K
1 8
1K
555
0.1uF 0.01uF
74LS92
74LS27
D4
D2
10K D3
D1
10K
74LS06
Each
resistor
below
is 120
ohms
Figure 4-111. If open-collector inverters are added to the dice Figure 4-112. The completed circuit using an open-collector
schematic, it can drive full-size LEDs with up to 40mA, as long as inverter to drive full-size LEDs.
the LEDs are turned around to sink current into the TTL output
stage instead of trying to source current from it.
The final enhancements are up to you. Most obviously, you can add a second
die, as many games require two dice. The 74LS27 chip still has a couple of
spare NOR gates in it, one of which you can make use of, but you will need
an additional 555 timer, running at a significantly different speed to ensure
randomness, and it will have to drive a second counter.
After you get your dice up and running, you may want to test them for ran-
domness. Because the pulses from a 555 timer are of equal length, every num-
ber has an equal chance of coming up; but the longer you hold down the Start
button, the better your odds are of interrupting the counting process at a truly
random moment. Anyone using your electronic dice should be told that “shak-
ing” them for a full second is mandatory.
Of course, I could have simulated dice more easily by writing a few lines of
software to generate random numbers on a screen, but even a fancy screen
image cannot have the same appeal as a well-made piece of hardware. Figure
4-113 shows white 1 cm LEDs mounted in a sanded polycarbonate enclosure
for dramatic effect.
Most of all, I derived satisfaction from using simple, dedicated chips that dem-
onstrate the binary arithmetic that is fundamental in every computer.
Figure 4-113. The open-collector inverter chip in the dice circuit is sufficiently powerful to
drive 1-cm white LEDs that draw about 20mA each, using a potential of 2V. In this finished
version, the LEDs were embedded in cavities drilled from the underside of half-inch poly-
carbonate, which has been treated with an orbital sander to create a translucent finish.
222 Chapter 4
Experiment 24: Intrusion Alarm Completed
These modifications are so simple that I think the block diagram in Figure
4-114 should be all you need. I don’t think I need to give you any schematics.
The only change you have to make to the existing alarm is to substitute the
latching relay for the on/off switch.
But, there is still one obvious necessary enhancement needed: how can you
get back into the house without instantly triggering the alarm?
Alarm Box
Noise
Maker
Test Button
1-Minute
Delay Circuit Door and Window
Magnetic Switches
Transistor Sensor
and Self-Locking
Relay
Latching
Keypad and Alarm on/off Relay
5V Logic Circuit
Pushbutton
1-Minute
Power Interrupt
12V DC
Power
Supply
Figure 4-114. This block diagram shows the relative placement of the old and new compo-
nents. The pushbutton power interrupt (which allows you to leave the house before the
alarm switches itself back on) goes between the power supply and everything else.
The latching relay substitutes for the DPDT switch on the previous version of the alarm.
The transistor and self-locking relay, connected with the door and window magnetic
switches, remain unchanged. The new delay circuit is inserted between the self-locking
relay and the noisemaker. The test button is wired with the latching relay in the same way
that it was wired previously with the DPDT switch.
224 Chapter 4
Experiment 24: Intrusion Alarm Completed
12V
DC Power to
noise
maker
1M
68uF
10K 555
10K
Q1
Switches D1 10uF
activated
by opened
doors or
windows
1K
R1
Figure 4-115. This addition to the original alarm circuit imposes a one-minute delay before
the alarm sounds. The 555 timer (wired in bistable mode) receives power through relay
R1. The lower timing circuit initially applies negative voltage to the reset, ensuring that
the 555 powers up with its output suppressed. This voltage quickly rises. Meanwhile the
upper timing circuit applies a voltage to the trigger that gradually diminishes as the 68
µF capacitor equalizes its charge through the 1M resistor. When the voltage diminishes to
1/3 of the supply, the timer’s output goes high and starts the noisemaker. If the power to
the circuit is interrupted at any time before this, the relay relaxes, the capacitors gradually
discharge, and the alarm does not sound.
The Wrap-Up
If you add these three enhancements, your alarm will have all the features on
my original wish list. Of course, if I were designing it from scratch, with all the
information that has been added in this chapter of the book, it could be more
elegant. But the modifications have not entailed making destructive changes
to our original project, and all the design goals have been met.
226 Chapter 4
What Next? 5
At this point, we can branch out in numerous directions. Here are some In this chapter
possibilities:
Shopping List: Experiments 25 Through 36
Audio electronics
This is a field in itself, including hobby projects, such as simple amplifiers Customizing Your Work Area
and “stomp boxes,” to modify guitar sound. Reference Sources
Experiment 25: Magnetism
Radio-frequency devices
Anything that receives or transmits radio waves, from an ultra-simple AM Experiment 26: Tabletop Power Generation
radio to remote controllers. Experiment 27: Loudspeaker Destruction
Experiment 28: Making a Coil React
Motors
The field of robotics has encouraged the growth of many online sites sell- Experiment 29: Filtering Frequencies
ing stepper motors, gear motors, synchronous motors, servo motors, and Experiment 30: Fuzz
more. Experiment 31: One Radio, No Solder,
No Power
Programmable microcontrollers
Experiment 32: A Little Robot Cart
These are tiny computers on a single chip. You write a little program on
your desktop computer, which will tell the chip to follow a series of pro- Experiment 33: Moving in Steps
cedures, such as receiving input from a sensor, waiting for a fixed period, Experiment 34: Hardware Meets Software
and sending output to a motor. Then you download your program onto Experiment 35: Checking the Real World
the chip, which stores it in nonvolatile memory. Popular controllers in- Experiment 36: The Lock, Revisited
clude the PICAXE, BASIC Stamp, Arduino, and many more. The cheapest In Closing
ones retail for a mere $5 each.
Obviously, I don’t have space to develop all of these topics fully, so what I’m
going to do is introduce you to them by describing just one or two projects in
each category. You can decide which interests you the most, and then proceed
beyond this book by reading other guides that specialize in that interest.
I’m also going to make some suggestions about setting up a productive work
area, reading relevant books, catalogs, and other printed sources, and gener-
ally proceeding further into hobby electronics.
227
Shopping List: Experiments 25 Through 36
Figure 5-1. The ideal work area: surrounded by storage. Never again will you need to get
out of your chair!
228 Chapter 5
Customizing Your Work Area
For undivided, flat-format storage boxes, the Prolatch 23600-00 is ideally sized
to fit a file-cabinet drawer, and the latches are sufficiently secure that you
could stack a series of them on their long edges. See Figure 5-4.
Plano also sells some really nicely designed toolboxes, one of which you can
place on your desktop. It will have small drawers for easy access to screwdriv-
ers, pliers, and other basics. Because you need a work area that’s only about
three feet square for most electronics projects, surrendering some desk space
to a toolbox is not a big sacrifice.
If you have a steel desk with relatively shallow drawers, one of them can be al-
Figure 5-4. This Plano brand box is located for printed catalogs. Don’t underrate the usefulness of hard copy, just
undivided, making it useful for storing because you can buy everything online. The Mouser catalog, for instance, has
spools of wire or medium-size tools. When an index, which is better in some ways than their online search feature, and
stacked upright on its long edge, three will
fit precisely in a file-cabinet drawer. the catalog is divided into helpful categories. Many times I’ve found useful
parts that I never knew existed, just by browsing, which is much quicker than
flipping through PDF pages online, even with a broadband connection. Cur-
rently, Mouser is still quite generous about sending out their catalogs, which
contain over 2,000 pages. McMaster-Carr will also send you a catalog, but only
after you‘ve ordered from them, and only once a year.
Now, the big question: how to store all those dinky little parts, such as resistors,
capacitors, and chips? I’ve tried various solutions to this problem. The most ob-
vious is to buy a case of small drawers, each of which is removable, so you can
place it on your desk while you access its contents. But I don’t like this system,
for two reasons. First, for very small components, you need to subdivide the
drawers, and the dividers are never secure. And second, the removability of
the drawers creates the risk of accidentally emptying the contents on the floor.
Maybe you’re too careful to allow this to happen, but I’m not!
My personal preference is to use Darice Mini-Storage boxes, shown in Figure
5-5. You can find these at Michaels in small quantities, or buy them more eco-
nomically in bulk online from suppliers such as http://www.craftamerica.com.
The blue boxes are subdivided into five compartments that are exactly the
right size and shape for resistors. The yellow boxes are subdivided into ten
compartments, which are ideal for semiconductors. The purple boxes aren’t
divided at all, and the red boxes have a mix of divisions.
The dividers are molded into the boxes, so you don’t have the annoyance asso-
Figure 5-5. Darice Mini-Storage boxes are ciated with removable dividers that slip out of position, allowing components
ideal for components such as resistors, ca-
pacitors, and semiconductors. The boxes
to mix together. The box lids fit tightly, so that even if you drop one of the
can be stacked stably or stored on shelves, boxes, it probably won’t open. The lids have metal hinges, and a ridge around
with their ends labeled. The brand sticker the edge that makes the boxes securely stackable.
is easily removed after being warmed with
a heat gun. I keep my little storage boxes on a set of shelves above the desk, with a gap of
3 inches between one shelf and the next, allowing two boxes to be stacked on
each shelf. If I want to work with a particular subset of boxes, I shift them onto
the desktop and stack them there.
230 Chapter 5
Customizing Your Work Area
Labeling
No matter which way you choose to store your parts, labeling them is essential.
Any ink-jet printer will produce neat-looking labels, and if you use peelable
(nonpermanent) labels, you’ll be able to reorganize your parts in the future, as
always seems to become necessary. I use color-coded labels for my collection
of resistors, so that I can compare the stripes on a resistor with the code on the
label, and see immediately if the resistor has been put in the wrong place. See
Figure 5-6.
Even more important: you need to place a second (non-adhesive) label inside
each compartment with the components. This label tells you the manufac-
turer’s part number and the source, so that reordering is easy. I buy a lot of
items from Mouser, and whenever I open their little plastic bags of parts, I snip Figure 5-6. To check that resistors are not
placed in the wrong compartments, print
out the section of the bag that has the identifying label on it, and slide it into the color code on each label.
the compartment of my parts box before I put the parts on top of it. This saves
frustration later.
If I were really well organized, I would also keep a database on my computer
listing everything that I buy, including the date, the source, the type of com-
ponent, and the quantity. But I’m not that well organized.
On the Bench
Some items are so essential that they should sit on the bench or desktop on
a permanent basis. These include your soldering iron(s), helping hands with
magnifier, desk lamp, breadboard, power strip, and power supply. For a desk
lamp, I prefer the type that has a daylight-spectrum fluorescent bulb, because
it spreads a uniform light and helps me to distinguish colors of adjacent stripes
on resistors.
The power supply is a matter of personal preference. If you’re serious about
electronics, you can buy a unit that delivers properly smoothed current at a
variety of properly regulated and calibrated voltages. Your little wall-plug unit
from RadioShack cannot do any of these things, and its output may vary de-
pending on how heavily you load it. Still, as you’ve seen, it is sufficient for basic
experiments, and when you’re working with logic chips, you need to mount a
5-volt regulator on your breadboard anyway. Overall, I consider a good power
supply optional.
Another optional item is an oscilloscope. This will show you, graphically, the
electrical fluctuations inside your wires and components, and by applying
probes at different points, you can track down errors in your circuit. It’s a neat
gadget to own, but it will cost a few hundred dollars, and for our tasks so far, it
has not been necessary. If you plan to get seriously into audio circuits, an oscil-
loscope becomes far more important, because you’ll want to see the shapes of
the waveforms that you generate.
You can try to economize on an oscilloscope by buying a unit that plugs into
the USB port of your computer and uses your computer monitor to display the
signal. I have tried one of these, and was not entirely happy with the results. It
worked, but did not seem accurate or reliable for low-frequency signals. May-
be I was unlucky; I decided not to try any other brands.
The surface of your desk or workbench will undoubtedly become scarred by ran-
dom scuffs, cut marks, and drops of molten solder. I use a piece of half-inch ply-
wood, two feet square, to protect my primary work area, and I clamp a miniature
vise to its edge. To reduce the risk of static electricity when working with sensitive
components, I cover the plywood with a square of conductive foam. This is not
cheap, but offers advantages in addition to protecting chips from being zapped.
Instead of scattering stray components, I can stick them into the foam, like plants
growing in a garden. And like a garden, I can divide it into sections, with resistors
on one side, capacitors on the other, and chips straight ahead.
Inevitably, during your work you’ll create a mess. Little pieces of bent wire, stray
screws, fasteners, and fragments of stripped insulation tend to accumulate, and
can be a liability. If metal parts or fragments get into a project that you’re build-
ing, they can cause short circuits. So you need a trash container. But it has to be
easy to use. I use a full-size garbage pail, because it’s so big that I can’t miss it
when I throw something toward it, and I can never forget that it’s there.
Last, but most essential: a computer. Now that all data sheets are available
online, and all components can be ordered online, and many sample circuits
are placed online by hobbyists and educators, I don’t think anyone can work
efficiently without quick Internet access. To avoid wasting space, I suggest you
use a small, cheap laptop that has a minimal footprint. A possible workbench
configuration, using a steel desk, is shown in Figure 5-7.
Small
parts
boxes
Fluorescent
desk lamp Helping
hands
Soldering
Laptop iron
computer
232 Chapter 5
Reference Sources
Reference Sources
Online
My favorite educational and reference site is Doctronics (http://www.doctronics.
co.uk). I like the way they draw their schematics, and I like the way they include
many illustrations of circuits on breadboards (which most sites don’t bother to
do). They also sell kits, if you’re willing to pay and wait for shipping from the UK.
Part of a page from the doctronics website is reproduced in Figure 5-8.
Figure 5-8. A sample page from http://www.doctronics.co.uk shows their detailed instruc-
tional approach. This is a valuable free online resource.
My next favorite hobby site is also British-based: the Electronics Club (http://
www.kpsec.freeuk.com). It’s not as comprehensive as Doctronics, but very
friendly and easy to understand.
For a more theory-based approach, try http://www.electronics-tutorials.ws. This
will go a little farther than the theory sections I’ve included here.
For an idiosyncratic selection of electronics topics, try Don Lancaster’s Guru’s
Lair (http://www.tinaja.com). Lancaster wrote The TTL Cookbook more than 30
years ago, which opened up electronics to at least two generations of hob-
byists and experimenters. He knows what he’s talking about, and isn’t afraid
of getting into some fairly ambitious areas such as writing his own PostScript
drivers and creating his own serial-port connections. You’ll find a lot of ideas
there.
Books
Yes, you do need books. As you’re already reading this one, I won’t recommend
other beginners’ guides. Instead, in keeping with the orientation of this chap-
ter, I’ll suggest some titles that will take you farther in various directions, and
can be used for reference. I own all of these myself, and find them valuable:
Practical Electronics for Inventors, by Paul Scherz (McGraw-Hill, Second Edition,
2007)
This is a massive, comprehensive book, well worth the $40 cover price.
Despite its title, you won’t need to invent anything to find it useful. It’s my
primary reference source, covering a wide range of concepts, from the
basic properties of resistors and capacitors all the way to some fairly high-
end math. If you buy only one book (in addition to this one, of course!),
this would be my recommendation.
Getting Started with Arduino, by Massimo Banzi (Make: Books, 2009)
If you enjoy the simplicity and convenience of the PICAXE programmable
microcontroller that I describe later in this chapter, you’ll find that the
Arduino can do a lot more. Getting Started is the simplest introduction
around, and will help to familiarize you with the Processing language
used in Arduino (similar to the C language, not much like the version of
BASIC used by the PICAXE).
Making Things Talk, by Tom Igoe (Make: Books, 2007)
This ambitious and comprehensive volume shows how to make the most
of the Arduino’s ability to communicate with its environment, even get-
ting it to access sites on the Internet.
TTL Cookbook, by Don Lancaster (Howard W. Sams & Co, 1974)
The 1974 copyright date is not a misprint! You may be able to find some
later editions, but whichever one you buy, it will be secondhand and pos-
sibly expensive, as this title now has collectible value. Lancaster wrote his
guide before the 7400 series of chips was emulated on a pin-for-pin basis
by CMOS versions, but it’s still a good reference, because the concepts and
part numbers haven’t changed, and his writing is so accurate and concise.
CMOS Sourcebook, by Newton C. Braga (Sams Technical Publishing, 2001)
This book is entirely devoted to the 4000 series of CMOS chips, not the
74HC00 series that I’ve dealt with primarily here. The 4000 series is older
and must be handled more carefully, because it’s more vulnerable to stat-
ic electricity than the generations that came later. Still, the chips remain
widely available, and their great advantage is their willingness to tolerate
a wide voltage range, typically from 5 to 15 volts. This means you can set
up a 12-volt circuit that drives a 555 timer, and use output from the timer
to go straight into CMOS chips (for example). The book is well organized
in three sections: CMOS basics, functional diagrams (showing pinouts for
all the main chips), and simple circuits showing how to make the chips
perform basic functions.
234 Chapter 5
Reference Sources
Figure 5-9. These books from MAKE provide Figure 5-10. A sun-damaged copy of the Don Lancaster’s
guidance if you want to go beyond basic micro- classic TTL Cookbook, a 2,000-page catalog from the
controllers into the more exotic realms of the Mouser Electronics supply company, and two com-
Arduino chip. prehensive reference books that can provide years of
additional guidance in all areas of electronics.
236 Chapter 5
Experiment 25: Magnetism
Theory
Inductance
When electricity flows through a wire, it creates a magnetic Here’s an approximated formula showing the relationship
field around the wire. Because the electricity “induces” this between the diameter of the coil, the width of the coil from
effect, it is known as inductance. The effect is illustrated in end to end, the number of turns, and its inductance. The
Figure 5-13. letter L is the symbol for inductance, even though the unit
is the Henry, named after an American electrical pioneer
named Joseph Henry:
L (in microHenrys) =
[(D × D) × (N x N)] / [(18 × D) + (40 × W)]
(Approximately)
In this formula, D is the diameter of the coil, N is the number
of turns, and W is the width of the coil from end to end. See
Figure 5-15. Here are three simple conclusions from this
formula:
• Inductance increases with the diameter of the coil.
Figure 5-13. When the flow of electricity is from left to right • Inductance increases with the square of the number of
along this conductor, it induces a magnetic force shown by the turns. (In other words, three times as many turns create
green arrows. nine times the inductance.)
• If the number of turns remains the same, inductance is
The field around a straight wire is very weak, but if we bend lower if you wind the coil so that it’s slender and long,
the wire into a circle, the magnetic force starts to accumu- but is higher if you wind it so that it’s fat and short.
late, pointing through the center of the circle, as shown in
Figure 5-14. If we add more circles, to form a coil, the force N=Number
accumulates even more. And if we put a magnetic object of turns of
(such as a screwdriver) in the center of the coil, the effective- wire
ness increases further.
D=Diameter
of coil
W
=
of Wi
co dth
il
Fundamentals Background
A coil in isolation does not gener- Henry was appointed to Princeton in 1832, where he received $1,000 per year
ally have any polarity. You can con- and a free house. When Morse attempted to patent the telegraph, Henry testi-
nect it either way around, but the fied that he was already aware of its concept, and indeed had rigged a system
magnetic force will be reversed ac- on similar principles to signal his wife, at home, when he was working in his
cordingly (coils that interact with laboratory at the Philosophical Hall.
stuff—such as in transformers and Henry taught chemistry, astronomy, and architecture, in addition to physical
solenoids—do have polarity). science, and because science was not divided into strict specialties as it is now,
Perhaps the most widespread he investigated phenomena such as phosphorescence, sound, capillary action,
application of coils is in transform- and ballistics. In 1846, he headed the newly founded Smithsonian Institution as
ers, where alternating current its secretary.
in one coil induces alternating
current in another, often sharing
the same iron core. If the primary
(input) coil has half as many turns
as the secondary (output) coil, the
voltage will be doubled, at half
the current—assuming hypotheti-
cally that the transformer is 100%
efficient.
238 Chapter 5
Experiment 26: Tabletop Power Generation
Procedure
You may be able to make this experiment work with the spool of hookup wire,
depending on the size of the spool relative to the size of your magnet, but as
the results are more likely to be better with the magnet wire, I’ll assume that
you’re using that—initially, at least. The advantage of the magnet wire is that
its very thin insulation allows the coils to be closely packed, increasing their
inductance.
First peek into the hollow center of the spool to see if the inner end of the
wire has been left accessible, as is visible in Figures 5-18 and 5-19. If it hasn’t,
you have to unwind the wire onto any large-diameter cylindrical object, then Figure 5-18. An everyday 100-foot spool of
rewind it back onto the spool, this time taking care to leave the inner end stick- hookup wire is capable of demonstrating
ing out. the inductive power of a coil.
Scrape the transparent insulation off each end of the magnet wire with a utility
knife or sandpaper, until bare copper is revealed. To check, attach your meter,
set to measure ohms, to the free ends of the wire. If you make a good contact,
you should measure a resistance of 30 ohms or less.
Place the spool on a nonmagnetic, nonconductive surface such as a wooden,
plastic, or glass-topped table. Attach the LED between the ends of the wire
using jumper wires. The polarity is not important. Now take a cylindrical neo-
dymium magnet of the type shown in Figure 5-20 and push it quickly down
into the hollow core, then pull it quickly back out. See Figure 5-21. You should
see the LED blink, either on the down stroke or the up stroke.
The same thing may or may not happen if you use 100 feet of 26-gauge hook-
up wire. Ideally, your cylindrical magnet should fit fairly closely in the hollow
center of the spool. If there’s a big air gap, this will greatly reduce the effect of Figure 5-19. Magnet wire has thinner
the magnet. Note that if you use a weaker, old-fashioned iron magnet instead insulation than hookup wire, allowing the
of a neodymium magnet, you may get no result at all. turns to be more densely packed, inducing
a more powerful magnetic field.
240 Chapter 5
Experiment 26: Tabletop Power Generation
Figure 5-22. Because inductance increases with the diameter of a coil and with the square
of the number of turns, your power output from moving a magnet through the coil can
increase dramatically with scale. Those wishing to live “off the grid” may consider this
steam-powered configuration, suitable for powering a three-bedroom home.
Long Wire
(positive) Volts
Figure 5-23. Using a diode in series with a capacitor, you can charge the capacitor with the
pulses of current that you generate by moving the magnet through the center of the coil.
This demo illustrates the principle of rectifying alternating current.
Figure 5-25. Loudspeaker ready for creative Figure 5-26. The cone has been removed. Figure 5-27. The neck of the cone has been
destruction. pulled out. Note the coil of copper wire,
which fits precisely in the groove between
two magnets in the base of the speaker.
242 Chapter 5
Experiment 27: Loudspeaker Destruction
Background
Origins of loudspeakers
Loudspeakers utilize the fact that if you run a varying electrical current through
a coil situated in a magnetic field, the coil will move in response to the current.
This idea was introduced in 1874 by Ernst Siemens, a prolific German inven-
tor. (He also built the world’s first electrically powered elevator in 1880.) Today,
Siemens AG is one of the largest electronics companies in the world.
When Alexander Graham Bell patented the telephone in 1876, he used Siemen’s
concept to create audible frequencies in the earpiece. From that point on,
sound-reproduction devices gradually increased in quality and power, until
Chester Rice and Edward Kellogg at General Electric published a paper in 1925
establishing basic principles that are still used in loudspeaker design today.
At http://www.radiolaguy.com/Showcase/Gallery-HornSpkr.htm you’ll find
photographs of very beautiful early loudspeakers, which used a horn design
to maximize efficiency. As sound amplifiers became more powerful, speaker
efficiency became less important compared with quality reproduction and low
manufacturing costs. Today’s loudspeakers convert only about 1% of electrical
energy into acoustical energy.
Figure 5-28. This beautiful Amplion AR-114x illustrates the efforts of early design-
ers to maximize efficiency in an era when the power of audio amplifiers was very
limited. Photos by “Sonny, the RadiolaGuy.” Many early speakers are illustrated at
www.radiolaguy.com. Some are for sale.
Theory
Waves
of air
pressure
traveling
at the
speed of
sound
PRESSURE
TIME
Figure 5-29. Step 1 in the process of converting sound to electricity, and back again.
When the hammer hits the gong, the face of the gong vibrates, creating pressure
waves that travel through the air.
244 Chapter 5
Experiment 27: Loudspeaker Destruction
Theory
VOLTAGE
TIME
MOVING-COIL
MICROPHONE
Figure 5-30. Step 2: the pressure waves penetrate the perforated shell of a micro-
phone and cause a diaphragm to vibrate in sympathy. The diaphragm has a coil
attached to it. When the coil vibrates to and fro, a magnet at its center induces
alternating current.
VOLTAGE
AMPLIFIER
Figure 5-31. Step 3: the tiny signals from the microphone pass through an amplifier,
which enlarges their amplitude while retaining their frequency and the shape of
their waveform.
Waves
of air
pressure
VOLTAGE
traveling
at the
speed of
LOUDSPEAKER sound
Figure 5-32. Step 4: the amplified electrical signal is passed through a coil around
the neck of a loudspeaker cone. The magnetic field induced by the current causes
the cone to vibrate, reproducing the original sound.
Procedure
D1 Take a look at the schematic in Figure 5-33. At first it may not make much
sense. The curly symbol is a coil of wire—nothing more than that. So appar-
ently the voltage will pass through the 220Ω resistor, and then through the
coil, ignoring the two LEDs, because the coil obviously has a much lower resis-
tance than either of them (and one of them is upside-down anyway).
Is that what will happen? Let’s find out. The coil can be a spool of 100 feet of
D2 26-gauge (or smaller) hookup wire, although the spool of magnet wire listed
in Experiment 25 will work better, if you have that. Once again, you will need
access to both ends of the wire, and if the inner end is inaccessible, you’ll need
to rewind the coil, leaving the end sticking out.
Now that you have a coil, you can hook it up on your breadboard as shown in
Figure 5-33. In this demonstration of self- Figure 5-34, where the green circle is a tactile switch and the two circular red
inductance, D1 and D2 are light-emitting objects are LEDs. Make sure that you use low-current LEDs (otherwise, you
diodes. When the switch is closed, D1 may not see anything) and make sure that one of them is negative-side-up,
flashes briefly because the coil obstructs
the initial flow of electricity. When the positive-side-down and the other is positive-side-up, negative-side-down.
switch is opened, D2 flashes as the col- Also, the 220Ω resistor should be rated at 1/4 watt or higher, if possible (see
lapsing magnetic field induced by the coil the following caution).
releases another short burst of current.
246 Chapter 5
Experiment 28: Making a Coil React
Hot Resistors
You’ll be passing about 50mA
through the 220Ω resistor, while
the current is flowing. At 12 volts,
this works out at 0.6 watts. If you
use a 1/8-watt resistor, you will be
overloading it, and it will get quite
hot and may burn out. If you use a
1/4-watt resistor, it will still get hot,
but is unlikely to burn out, as long as
you don’t press the button for more
than a second or two.
12V Don’t run the circuit without the coil
DC of wire; you’ll be trying to pass more
than 50mA through the LEDs.
Figure 5-34. The breadboarded version of the schematic in Figure 5-33 shows a simple
way to set it up for a quick demo. The green button is a tactile switch. The two red LEDs
should be placed so that the polarity of one is opposite to the polarity of the other.
When you press the button, one LED should flash briefly. When you release the
button, the other LED should flash.
What’s happening here? The coil possesses self-inductance, which means that
it reacts against any sudden change in the flow of electricity. First it fights it,
and during that brief moment, it blocks most of the current. Consequently, the
current looks for an alternative path and flows through D1, the lefthand LED
in the schematic. (D2 doesn’t respond, because it can pass current only in the
opposite direction.)
Meanwhile, the voltage pressure overcomes the coil’s self-inductance. When
the self-inductance disappears, the resistance of the coil is no more than 10
ohms—so now the electricity flows mostly through the coil, and because the
LED receives so little, it goes dark.
When you disconnect the power, the coil reacts again. It fights any sudden
changes. After the flow of electricity stops, the coil stubbornly sustains it for a
moment, because as the magnetic field collapses, it is turned back into elec-
tricity. This residual flow of current depletes itself through D2, the LED on the
right.
In other words, the coil stores some energy in its magnetic field. This is similar
to the way a capacitor stores energy between two metal plates, except that
the coil blocks the current initially and then lets it build up, whereas the ca-
pacitor sucks up current initially, and then blocks it.
The more turns of wire you have in your coil, the more self-inductance the coil
will have, causing your LEDs to flash more brightly.
Here’s one last variation on this experiment to test your understanding of elec-
trical fundamentals. Remove the 220Ω resistor, and substitute a 1K resistor (to
protect your LED from sustained current). Remove the coil, and substitute a
very large capacitor—ideally, about 4,700 μF. (Be careful to get its polarity the
right way around.) What will you see when you press the button? Note that
you will have to hold it down for a couple of seconds to get a result. And what
will you see when you release the button? Remember: the behavior of capaci-
tance is opposite to the behavior of self-inductance.
Theory
248 Chapter 5
Experiment 29: Filtering Frequencies
Figure 5-35. To hear the effects of audio Figure 5-36. This single chip contains a Figure 5-37. A nonpolarized electrolytic
filters using coils and capacitors, you’ll stereo amplifier capable of delivering a capacitor, also known as a bipolar capaci-
need a loudspeaker capable of reproduc- total of 5 watts into an 8Ω speaker when tor, looks just like an electrolytic capaci-
ing lower frequencies. This 5-inch model is the two channels are combined. tor, except that it will have “NP” or “BP”
the minimum required. printed on it.
Procedure
The purpose of the audio amplifier chip is to provide enough power to get
a decent amount of sound out of your loudspeaker. The purpose of using a
5-inch speaker is to enable you to hear lower-frequency sounds than the baby
speakers that we have used previously. Bass notes have long wavelengths that
small speakers are not able to generate effectively.
Maybe you remember from building the intrusion alarm that a speaker makes
much more noise if you prevent the sound waves from the back of the cone
from cancelling the sound waves from the front of the cone. The obvious way
to achieve this is by enclosing the speaker in a box. I suggest a plastic box,
because they’re cheap, and we don’t care too much about sound quality as
Figure 5-39. A resonant enclosure is neces-
sary if you want to hear some bass (lower long as we can hear at least some of the low frequencies. Figure 5-39 shows
frequencies) from your speaker. A cheap the speaker bolted into the bottom of a plastic box, and Figure 5-40 shows the
plastic shoebox is sufficient for demo box turned upside-down after snapping its lid into place.
purposes.
Normally, a speaker should be mounted in a cabinet of heavy, thick material
that has a very low resonant frequency—below the limits of human hearing.
To minimize the resonance of the shoebox, you can put some soft, heavy fab-
ric inside it before you snap the lid on. A hand towel or some socks should be
sufficient to absorb some of the vibration.
Adding an Amplifier
Back in the 1950s, you needed vacuum tubes, transformers, and other power-
hungry heavyweight components to build an audio amplifier. Today, you can
buy a chip for about $1 that will do the job, if you add a few capacitors around
Figure 5-40. Drill some half-inch holes
it, and a volume control. The TEA2025B that I’m recommending is intended for
in the bottom of the box, then bolt the use in cheap portable cassette players and CD players, and can work in stereo
speaker in place, running a wire out or mono mode, from a power supply ranging from 3 to 9 volts. With 9 volts
through a hole in one end. Snap on the lid, and the two sides of the chip bridged together to drive one 8Ω speaker, it can
and you’re ready for not-quite-high-fidelity
audio.
generate 5 watts of audio power. That doesn’t sound much compared with a
typical home theater system rated at 100 watts per channel, but because loud-
ness is a logarithmic scale, 5 watts will be quite enough to irritate any family
members in the same room—and possibly even in other rooms.
If you can’t find the TEA2025B chip, you can use any alternative listed as an
audio amplifier. Try to find one that is designed to drive an 8Ω speaker with up
to 5 watts in mono mode. Check the manufacturer’s data sheet to see where
you attach capacitors around it. Note carefully whether some of the capacitors
have no polarity marked, even though they have fairly high values, such as 100
μF. These capacitors must function regardless of which way the alternating
current is flowing, and I’ve marked them “NP” in my schematic in Figure 5-41,
meaning “nonpolarized.” (You may find them identified as “bipolar” or “BP” in
parts catalogs.) As noted in the shopping list, you can put two 220 μF capaci-
tors in series, negative-to-negative, to get the same effect as a single 100 μF
nonpolarized capacitor.
For this project, it’s essential to include the regular 100 μF electrolytic smooth-
ing capacitor across the power supply. Otherwise, the amplifier will pick up
and—yes, amplify—small voltage spikes in the circuit.
250 Chapter 5
Experiment 29: Filtering Frequencies
8 ohms
9V
DC
1 16
0.15uF 0.15uF
2 15
3 14
100uF 100uF
TEA2025B
NP 4 13 NP
5 12
100uF 6 11
100uF
7 10
100uF 8 9
0.22uF
33K
10K
Input from
headphone jack
on audio device
Figure 5-41. The audio amplifier chip should be wired with capacitors around it as shown,
“NP” denoting the ones that are not polarized. The acronym“BP,” meaning bipolar, is also
often used to mean the same thing. The output from pins 2 and 15 of the chip can be
passed through a coil or a 10 μF capacitor to demonstrate audio filtering.
Figure 5-42. To sample the output from the
The input shown in the schematic can receive a signal from a typical media headphone socket of a music player, you
can use this adapter and push the stripped
player, such as a portable MP3 player, CD player, or cassette player. To connect end of a piece of hookup wire into one of
its headphone jack to the breadboard, you can use an adapter that converts the sockets. Then use alligator clips on a
it to a pair of RCA-type audio jacks, and then stick a wire into one of them as jumper wire to connect the audio to your
shown in Figure 5-42. The wire will connect to the 33K resistor on the bread- breadboarded circuit. Don’t forget to use
an additional jumper wire to connect the
board circuit. The chromed neck of the RCA jack (which is sometimes gold- outside of the socket to the negative side
plated, or at least gold-colored) must be connected with the negative side of of the power supply on the breadboard.
your power supply on the breadboard; otherwise, you won’t hear anything. Because we’re only using one speaker, the
You can ignore the second output on the adapter, because we’re working in amplifier is connected to only one of the
stereo outputs from your player. The other
mono, here, not stereo. is ignored.
The 33K resistor is necessary to protect the amplifier from being overdriven. If
you don’t get enough volume using your music player, decrease the 33K value.
If the music is too loud and distorted, increase the value. You can also try omit-
ting or increasing the 10K resistor next to it, which is included in an effort to
reduce background hum noise.
I’ve shown two switches at the top of the schematic: one to bypass a coil, the
other to bypass a capacitor. You can use alligator clips instead, as long as you
can easily compare the sound when each of the components is inserted into
the circuit.
Figure 5-43 shows a coil consisting of a spool of hookup wire being used. The
red and black alligator clips resting loose on top of the shoebox will go to the
output from the chip (on pins 2 and 15). There is no polarity; it doesn’t matter
which clip goes to which pin.
Begin by turning the volume control on your music source all the way down
before you apply power. Don’t be surprised if you hear humming or crackling
Figure 5-43. The red and black alligator
clips, lying on top of the shoebox, should noises when you activate the amplifier; it will pick up any stray voltages, be-
connect with the output from your ampli- cause in this simple experiment, I haven’t suggested that you should shield
fier chip. The red jumper wire passes the the input, and the amplifier circuit can pick up noise, as its wires can act like
signal through a coil of hookup wire on its antennas.
way to the speaker. Note the change in
sound when you short out the coil. Note that you may also get additional unwanted sound if you use the ampli-
fier on a conductive desktop surface. Remove any aluminum foil or conductive
foam for this project.
Make sure that your player is playing music, and slowly turn up its volume
control until you hear it. If you don’t hear anything, you’ll have to check for
circuit errors.
Now comes the interesting part. Insert the 100-foot spool of hookup wire be-
tween one output from the amplifier, and one input of the speaker (it doesn’t
matter which one), or if you used switches, open the switch that bypasses the
coil. You should find that the music loses all its high-end response. By compari-
son, if you disconnect the coil and substitute a 10 μF capacitor, you should find
that the music sounds “tinny,” meaning that it loses all its low range, leaving
only the high frequencies.
You’ve just tested two very simple filters. Here’s what they are doing:
• The coil is a low-pass filter. It passes low frequencies but blocks high fre-
quencies, because brief audio cycles don’t have time to overcome the coil’s
self-inductance. A bigger coil eliminates a wider range of frequencies.
• The capacitor is a high-pass filter. It passes high frequencies and blocks
low frequencies because longer audio cycles can fill the capacitance, at
which point the capacitor stops passing current. A smaller capacitor elimi-
nates a wider ranger of frequencies.
You can go a lot farther into filter design, using complex combinations of coils
and capacitors to block frequencies at any point in the audible spectrum.
Search online for audio filter schematics—you’ll find hundreds of them.
252 Chapter 5
Experiment 29: Filtering Frequencies
Crossover Networks
In a traditional audio system, each speaker cabinet contains two drivers—one
of them a small speaker called a tweeter, which reproduces high frequencies,
the other a large speaker known as a woofer, which reproduces low frequen-
cies. (Modern systems often remove the woofer and place it in a separate box
of its own that can be positioned almost anywhere, because the human ear
has difficulty sensing the direction of low-frequency sounds.)
The schematic that you just looked at and may have constructed is known as
a “crossover network,” and truly hardcore audiophiles have been known make
their own (especially for use in car systems) to go with speakers of their choice
in cabinets that they design and build themselves.
If you want to make a crossover network, you should use high-quality poly-
ester capacitors (which have no polarity, last longer than electrolytics, and are
better made) and a coil that has the right number of turns of wire and is the
right size to cut high frequencies at the appropriate point. Figure 5-44 shows
a polyester capacitor.
Figure 5-45 shows an audio crossover coil that I bought on eBay for $6. I was
curious to find out what was inside it, so I bought two of them, and took one
apart.
First I peeled away the black vinyl tape that enclosed the coil. Inside was some
typical magnet wire—copper wire thinly coated with shellac or semitransparent
plastic, as shown in Figure 5-46. I unwound the wire and counted the number
of turns. Then I measured the length of the wire, and finally used a micrometer
to measure the diameter of the wire, after which I checked online to find a con-
version from the diameter in mils (1/1,000 of an inch) to American wire gauge.
As for the spool, it was plain plastic with an air core—no iron or ferrite rod in
the center. Figure 5-47 shows the spool and the wire.
Figure 5-44. Some nonelec- Figure 5-45. What exotic Figure 5-46. The black tape is Figure 5-47. The audio crossover coil
trolytic capacitors have components may we find removed, revealing a coil of consists of a plastic spool and some
no polarity, such as this inside this high-end audio magnet wire. wire. Nothing more.
high-quality polyester film component that’s used with
capacitor. However, they tend a subwoofer to block high
to be much more expensive, frequencies?
and are hard to find in values
higher than 10 μF.
So here’s the specification for this particular coil in an audio crossover network.
Forty feet of 20-gauge copper magnet wire, wrapped in 200 turns around a
spool of 1/16–inch-thick plastic with a hub measuring 7/8 inch in length be-
tween the flanges and 1/2-inch external diameter. Total retail cost of materials
if purchased separately: probably about $1, assuming you can find or make a
spool of the appropriate size.
Conclusion: there’s a lot of mystique attached to audio components. They are
frequently overpriced, and you can make your own coil if you start with these
parameters and adjust them to suit yourself.
Suppose you want to put some thumping bass speakers into your car. Could
you build your own filter so that they only reproduce the low frequencies?
Absolutely—you just need to wind a coil, adding more turns until it cuts as
much of the high frequencies as you choose. Just make sure the wire is heavy
enough so that it won’t overheat when you push 100 or more audio watts
through it.
Here’s another project to think about: a color organ. You can tap into the out-
put from your stereo and use filters to divide audio frequencies into three sec-
tions, each of which drives a separate set of colored LEDs. The red LEDs will
flash in response to bass tones, yellow LEDs in response to the mid-range, and
green LEDs in response to high frequencies (or whatever colors you prefer).
You can put signal diodes in series with the LEDs to rectify the alternating cur-
rent, and series resistors to limit the voltage across the LEDs to, say, 2.5 volts
(when the music volume is turned all the way up). You’ll use your meter to
check the current passing through each resistor, and multiply that number
by the voltage drop across the resistor, to find the wattage that it’s handling,
to make sure the resistor is capable of dissipating that much power without
burning out.
Audio is a field offering all kinds of possibilities if you enjoy designing and
building your own electronics.
Download at WoweBook.com
254 Chapter 5
Experiment 29: Filtering Frequencies
Theory
Waveforms
If you blow across the top of a bottle, the mellow sound
that you hear is caused by the air vibrating inside the bottle,
and if you could see the pressure waves, they would have a
distinctive profile. b
a
If you could slow down time and draw a graph of the alter- b
a
nating voltage in any power outlet in your house, it would Start
have the same profile.
Figure 5-48. If a weight on the end of a string (length b, in
If you could measure the speed of a pendulum swinging the diagram) follows a circular path at a steady speed, the
slowly to and fro in a vacuum, and draw a graph of the speed distance of the weight from a horizontal center line (length a,
relative to time, once again it would have the same profile. in the diagram) can be plotted as a graph relative to time. The
graph will be a sine wave, so called because in basic trigonom-
That profile is a sine wave, so called because you can derive etry, the ratio of a/b is the sine of the angle between line b and
it from basic trigonometry. In a right-angled triangle, the the horizontal baseline, measured at the center of rotation.
Sinewaves occur naturally in the world around us, especially in
sine of an angle is found by dividing the length of the side
audio reproduction and alternating current.
opposite the angle by the length of the hypoteneuse (the
sloping side of the triangle).
To make this simpler, imagine a ball on a string rotating
around a center point, as shown in Figure 5-48. Ignore the
force of gravity, the resistance of air, and other annoying
variables. Just measure the vertical height of the ball and di- Ratio of a/b
vide it by the length of the string, at regular instants of time,
as the ball moves around the circular path at a constant Time
speed. Plot the result as a graph, and there’s your sine wave,
shown in Figure 5-49. Note that when the ball circles below
its horizontal starting line, we consider its distance negative,
so the sine wave becomes negative, too.
Why should this particular curve turn up in so many places
Figure 5-49. This is what a “pure” sinewave looks like.
and so many ways in nature? There are reasons for this
rooted in physics, but I’ll leave you to dig into that topic if it
interests you. Getting back to the subject of audio reproduc-
tion, what matters is this:
• Any sound can be broken down into a mixture of sine
waves of varying frequency and amplitude.
Or, conversely:
• If you put together the right mix of audio sine waves,
you can create any sound at all.
Suppose that there are two sounds playing simultaneously.
Figure 5-50 shows one sound as a red curve, and the other
as pale blue. When the two sounds travel either as pressure
waves through air or as alternating electric currents through
a wire, the amplitudes of the waves are added together to Figure 5-50. When two sinewaves are generated at the same
time (for instance, by two musicians, each playing a flute),
make the more complex curve, which is shown in black.
the combined sound creates a compound curve. The blue
Now try to imagine dozens or even hundreds of different sinewave is twice the frequency of the red sinewave. The
frequencies being added together, and you have an idea of compound curve (black line) is the sum of the distances of the
the complex waveform of a piece of music. sinewaves from the baseline of the graph.
Theory
Waveforms (continued)
You can create your own waveform as an input for your au- Now adjust the 100K potentiometer to create a low-pitched
dio amplifier with the basic astable 555 timer circuit shown note. You’ll find that it doesn’t have a “pure” sound. There
in Figure 5-51. You have to be careful, though, not to over- are some buzzing overtones. This is because the 555 timer
load the amplifier input. Note the 680K series resistor on the is generating square waves such as those shown in Figure
output pin of the timer. Also note the 500Ω potentiometer. 5-52, not sine waves, and a square wave is actually a sum
of many different sine waves, some of which have a high
9V frequency. Your ear hears these harmonics, even though
DC
they are not obvious when you look at a square-shaped
waveform.
Route one of the connections to your loudspeaker through
1K your spool of hookup wire, and now you should hear a
1 8 much purer tone, as the buzzing high frequencies are
2 555 7 blocked by the self-inductance of the coil. Remove the coil
680K timer 100K
3 6 and substitute the 10 μF capacitor, and now you hear more
buzzing and less bass.
500 4 5
ohms You’ve just taken a small step toward sound synthesis. If this
subject interests you, you can go online and search for oscil-
0.01uF lator circuits. For a thorough understanding of the relation-
ship between waveforms and the sounds you hear, you’ll
0.1uF
really need an oscilloscope, which will show you the shape
of each waveform that you generate and modify.
To input of
audio amplifier
256 Chapter 5
Experiment 30: Fuzz
Background
Clipping
In the early days of “hi-fi” sound, engineers labored mightily The first gadget to offer this on a commercial basis was
to perfect the process of sound reproduction. They wanted known as a “fuzz box,” which deliberately clipped the input
the waveform at the output end of the amplifier to look signal. An early fuzz box is shown in Figure 5-53. The clip-
identical with the waveform at the input end, the only dif- ping of a sine wave is shown in Figure 5-54.
ference being that it should be bigger, so that it would be
powerful enough to drive loudspeakers. Even a very slight
distortion of the waveform was unacceptable.
Little did they realize that their beautifully designed tube
amplifiers would be abused by a new generation of rock
guitarists whose intention was to create as much distortion
as possible.
The most common form of waveform abuse is techni-
cally known as “clipping.” If you push a vacuum tube or a
transistor to amplify a sine wave beyond the component’s
capabilities, it “clips” the top and bottom of the curve. This
makes it look more like a square wave, and as I explained in
the section on waveforms, a square wave has a harsh, buzz-
ing quality. For rock guitarists trying to add an edge to their
music, the harshness is actually a desirable feature.
Schematic
The output from the 555 timer is a square wave, so it already sounds quite
“fuzzy,” but we can make it more intense to demonstrate the clipping princi-
ple. I’ve redrawn the whole circuit in Figure 5-55, as several components have
changed. The principal alteration is the addition of two NPN transistors.
If you assemble this circuit on your breadboard, note carefully that the 33K
and 10K resistors at the bottom of the amplifier chip have been removed, and
there’s now just an 820Ω resistor in that location. The bottom of the adjacent
0.22 μF capacitor is still the input point for the amplifier, and if you follow the
connection around to the middle of the schematic, you’ll find it leading to a
100K potentiometer. This is your “fuzz adjuster.”
The two NPN transistors are arranged so that the one on the left receives out-
put from the 555 timer. This signal controls the flow of electricity through the
transistor from a 33K resistor. This flow, in turn, controls the base of the right-
hand transistor, and the flow of current through that is what ultimately con-
trols the amplifier.
When you power up the circuit, use the 100K potentiometer attached to the
555 timer to adjust the frequency (as before) and crank the “fuzz adjuster” po-
tentiometer to hear how it adds increasing “bite” to the sound until ultimately
it becomes pure noise.
The two transistors act as amplifiers. Of course, we didn’t need them for that
purpose—the input level for the amplifier chip was already more than ade-
quate. The purpose of the lefthand transistor is simply to overload the right-
hand transistor, to create the “fuzz” effect. And when you turn up the output
from the transistors with the “fuzz adjuster,” eventually they overload the input
of the amplifier chip, creating even more distortion.
If you want to tweak the output, try substituting different values for the 1K
resistor and the 1 μF capacitor that are positioned between the emitter of the
righthand transistor and the negative side of the power supply. A larger resis-
tor should overload the transistor less. Different capacitor values should make
the sound more or less harsh.
You can find literally thousands of schematics online for gadgets to modify
guitar sound. The circuit I’ve included here is one of the most primitive. If you
want something more versatile, you should search for “stomp box schematics”
and see what you can find.
258 Chapter 5
Experiment 30: Fuzz
9V
DC
100uF
1K
1 8
2
555 7
timer 100K
3 6
4 5
0.1uF
0.01uF 0.1uF
33K
8K2 390
0.01uF
1K 100K
8 ohms
1uF
1 16
0.15uF 0.15uF
2 15
3 14
100uF 100uF
TEA2025B
NP 4 13 NP
5 12
100uF 100uF
6 11
7 10
100uF 8 9
0.22uF
820
Audio Signal
input point
Figure 5-55. For a quick demo of clipping, insert a couple of transistors between the output
from the 555 timer and the input of the amplifier chip. One transistor overdrives the
other, so that when you adjust the potentiometer at the center of the circuit, you hear an
increasingly harsh, distorted sound.
Background
Stomp-box origins
The Ventures recorded the first single to use a fuzz box, Wireless World. In his fuzz circuit, he uses a very high-gain
titled “The 2,000 Pound Bee,” in 1962. Truly one of the most amplifier consisting of three field-effect transistors (FETs),
awful instrumentals ever made, it used distortion merely which closely imitate the rounded square-wave typical of an
as a gimmick and must have discouraged other musicians overdriven tube amp.
from taking the concept seriously.
Dellepiane offers dozens more schematics on his site, devel-
Ray Davies of the Kinks was the first to embody distortion oped and tested with a dual-trace oscilloscope, low-distortion
as an integral part of his music. Davies did it initially by plug- sinewave oscillator (so that he can give audio devices a “clean”
ging the output from one amp into the input of another, input), distortion meter, and precision audio volt meter.
supposedly during the recording of his hit “You Really Got This last item, and the oscillator, were built from his own
Me.” This overloaded the input and created clipping—the designs, and he gives away their schematics, too. Thus his
basic fuzz concept. From there it was a short step to Keith site provides one-stop shopping for home-audio electronics
Richards using a Gibson Maestro Fuzz-Tone when the Roll- hobbyists in search of a self-administered education.
ing Stones recorded “(I Can’t Get No) Satisfaction” in 1965.
Before fuzz, there was tremolo. A lot of people confuse this
Today, you can find thousands of advocates promoting with vibrato, so let’s clarify that distinction right now:
as many different mythologies about “ideal” distortion. In • Vibrato applied to a note makes the frequency waver
Figure 5-56, I’ve included a schematic from Flavio Dellepi- up and down, as if a guitarist is bending the strings.
ane, a circuit designer in Italy who gives away his work (with
• Tremolo applied to a note makes its volume fluctuate,
a little help from Google AdSense) at http://www.redcircuits.
as if someone is turning the volume control of a guitar
com. Dellepiane is self-taught, having gained much of his
up and down very quickly.
knowledge from electronics magazines such as the British
22uF
2N3819
9V
DC 3K3
2N3819
100pF
2N3819
0.1uF
Input 10K
Jack log
0.1uF
2K2
22uF
1M 100K
5K trimmer
Output
Jack
Figure 5-56. This circuit designed by Flavio Dellepiane uses three transistors to simulate the kind of distortion that used to be cre-
ated by overloading the input of a tube amplifier.
260 Chapter 5
Experiment 30: Fuzz
Background
Figure 5-57. Although electromechanical audio devices are Figure 5-58. Different stripe patterns could be used in conjunc-
obsolete now, some unexplored possibilities still exist. This tion with the imaginary electromechanical device in Figure
design could create various tremolo effects, if anyone had the 5-57 to create various tremolo effects.
patience to build it.
Figure 5-59. Just add wire and a coil, and • High-impedance headphone. Quantity: 1.
this is all you need to receive AM radio
signals. The black disc becomes the
The diode and headphone can be ordered from http://www.scitoyscatalog.com.
tuning dial, after it is screwed onto the You cannot use a modern headphone of the type you wear with an MP3 player.
variable capacitor (right). This is actually
an optional extra. A germanium diode Some of these items are shown in Figure 5-59.
(center) rectifies the radio signal. The
high-impedance earphone (top) creates a First, you need to make a coil. It should be about 3 inches in diameter, and you
barely audible sound. can wind it around any empty glass or plastic container of that size, so long
as it’s rigid. A soda bottle or water bottle isn’t suitable, because the cumula-
tive squeezing force of the turns of wire can deform the bottle so that it isn’t
circular anymore.
I chose a vitamin bottle that just happened to be exactly the right size. To re-
move the label, I softened its adhesive with a heat gun (lightly, to avoid melt-
ing the bottle) and then just peeled it off. The adhesive left a residue, which
I removed with Xylol (also known as Xylene). This is a handy solvent to have
around, as it can remove “permanent” marker stains as well as sticky residues,
but you should always use latex or nitrile gloves to avoid getting it on your
skin, and minimize your exposure the fumes. Because Xylol will dissolve some
plastics, clearly it’s not good for your lungs.
After you prepare a clean, rigid bottle, drill two pairs of holes in it, as shown in
Figure 5-60. You’ll use them to anchor the ends of the coil.
Now you need about 60 feet of 22-gauge solid-core wire. If you use magnet
wire, its thin insulation will allow the turns of the coil to be more closely spaced,
and the coil may be slightly more efficient. But everyday vinyl-insulated wire
will do the job, and is much easier to work with.
Begin by stripping the first 6 inches of insulation from the end of the wire.
Figure 5-60. A large, 3-inch diameter empty
Now measure 50 inches along the insulated remainder and apply your wire
vitamin bottle makes an ideal core for a
crystal radio coil. The drilled holes will strippers at that point, just enough to cut the insulation without cutting the
anchor wire wrapped around the bottle.
262 Chapter 5
Experiment 31: One Radio, No Solder, No Power
wire. Use your two thumb nails to pull the insulation apart, revealing about a
half-inch of bare wire, as shown in Figure 5-61. Bend it at the center point and
twist it into a loop, as shown in Figure 5-62.
You just made a “tap,” meaning a point where you will be able to tap into the
coil after you wind it. You’ll need another 11 of these taps, all of them spaced
50 inches apart. (If the diameter of the bottle that you’ll be using as the core
of your coil is not 3 inches, multiply its diameter by 16 to get the approximate
desired spacing of taps.)
After you have made 12 taps, cut the wire and strip 6 inches off that end. Now
bend the end into a U shape about a half-inch in diameter, so that you can
hook it through the pair of holes that you drilled at one end of the bottle. Pull
the wire through, then loop it around again to make a secure anchor point. Figure 5-61. Wire strippers expose the solid
conductor at intervals along a 22-gauge
Now wind the rest of the wire around the bottle, pulling it tightly so that wire.
the coils stay close together. When you get to the end of the wire, thread it
through the remaining pair of holes to anchor it as shown in Figure 5-63. The
completed coil is shown in Figure 5-64.
Figure 5-62. Each exposed section of wire Figure 5-63. The stripped end of the wire Figure 5-64. The completed coil, wrapped
is twisted into a loop using sharp-nosed is secured through the holes drilled in the tightly around the bottle.
pliers. bottle.
Your next step is to set up an antenna. If you live in a house with a yard outside,
this is easy: just open a window, toss out a reel of 16-gauge wire while holding
the free end, then go outside and string up your antenna by using polypro-
pylene rope (“poly rope”) or nylon rope, available from any hardware store, High Voltage!
to hang the wire from any available trees, gutters, or poles. The total length The world around us is full of electric-
of the wire should be about 100 feet. Where it comes in through the window, ity. Normally we’re unaware of it, but
suspend it on another length of poly rope. The idea is to keep your antenna a thunderstorm is a sudden reminder
wire as far away from the ground or from any grounded objects as possible. that there’s a huge electrical poten-
tial between the ground below and
If you live in an apartment where you don’t have access to a yard outside, you the clouds above.
can try stringing your antenna around the room, hanging the wire from more If you put up an outdoor antenna,
pieces of poly rope. The antenna should still be about 100 feet long, but obvi- never use it if there is any chance of a
ously it won’t be in a straight line. lightning strike. This can be extreme-
ly dangerous. Disconnect the indoor
Hook the free end of your antenna to one end of your coil. At this point, you also end of your antenna, drag it outside,
need to add a germanium diode, which functions like a silicon-based diode but and push the end of the wire into the
is better suited to the tiny voltages and currents that we’ll be dealing with. The ground to make it safe.
other end of the diode attaches to one of the wires leading to a high-impedance
earphone. A normal modern earphone or headphone will not work in this circuit.
The return wire from the headphone is connected to a jumper wire, the other
end of which can be clipped to any of the taps in your coil.
One last modification, and you’ll be ready to tune in. You have to ground the
jumper wire. By this I mean connect it to something that literally goes into
the ground. A cold-water pipe is the most commonly mentioned option, but
(duh!) this will work only if the pipe is made of metal. Because a lot of plumb-
ing these days is plastic, check under the sink to see if you have copper pipes
before you try using a faucet for your ground.
Another option is to attach the wire to the screw in the cover plate of an elec-
trical outlet, as the electrical system in your house is ultimately grounded. But
the sure-fire way to get a good ground connection is to go outside and ham-
mer a 4-foot copper-clad grounding stake into reasonably moist earth. Any
wholesale electrical supply house should be able to sell you a stake. They’re
commonly used to ground welding equipment.
Figure 5-65. The simple pleasure of picking up a radio signal with ultra-simple components
and no additional power.
264 Chapter 5
Experiment 31: One Radio, No Solder, No Power
If you’ve managed to follow these instructions (one way or another), it’s time
to tune your radio to the nearest station. Move the alligator clip at the end of
your patch cord from one tap to another on your coil. Depending on where
you live, you may pick up just one station, or several, some of them playing
simultaneously.
It may seem that you’re getting something for nothing here, as the earphone
is making noise without any source of power. Really, though, there is a source
of power: the transmitter located at the radio station. A large amplifier pumps
power into the broadcasting tower, modulating a fixed frequency. When the
combination of your coil and antenna resonates with that frequency, you’re
sucking in just enough voltage and current to energize a high-impedance
headphone.
The reason you had to make a good ground connection is that the radio sta- To To Ground
Earphone
tion broadcasts its signal at a voltage relative to ground. The earth completes
the circuit between you and the transmitter. For more information on this and Figure 5-66. A signal from the antenna
other concepts relating to radio, see the upcoming section “Theory: How radio can pass through the coil to ground. If the
jumper wire is attached to an appropriate
works.” tap on the coil, it resonates with the radio
signal, just powerfully enough to energize
the earphone which is wired in series with
Enhancements a diode.
The higher your antenna is, the better it should work. In my location, this is a
major problem, as I live in a desert area without any trees. Still, just stringing
the wire out of my window and tethering it (with rope) to the front bumper of
my car enabled me to pick up a faint radio signal.
To improve the selectivity of your radio, you can add a variable capacitor, as
shown in the following section. This allows you to “tune” the resonance of your
circuit more precisely. Variable capacitors are uncommon today, but you can
find one at the same specialty source that I recommended for the earphone and
the germanium diode: the Scitoys Catalog (http://www.scitoyscatalog.com).
This source is affiliated with a smart man named Simon Quellan Field, whose
site suggests many fun projects that you can pursue at home. One of his clever
ideas is to remove the germanium diode from your radio circuit and substi-
tute a low-power LED in series with a 1.5-volt battery. This didn’t work for me,
because I live 40 miles from the nearest AM broadcaster. If you’re closer to a
transmitter, you may be able to see the LED varying in intensity as the broad-
cast power runs through it.
Theory
Chopped by
diode
Audible earphone
response
266 Chapter 5
Experiment 31: One Radio, No Solder, No Power
Theory
268 Chapter 5
Experiment 32: A Little Robot Cart
plywood to complete the two little robotics projects here (ideally, the kind of
thin, high-quality plywood sold by hobby stores) but I recommend something
that looks better and is easier to work with: ABS plastic. Before you start on the
robotic cart, you may want to check the section “Fundamentals: All about ABS.”
Fundamentals
Figure 5-76. The perils of kickback. Plastic easily sticks to the blade of a table saw,
which will hurl it at you unexpectedly. Use other tools to cut plastic.
270 Chapter 5
Experiment 32: A Little Robot Cart
Curving Cuts
Curving cuts involve relatively little danger, although eye protection and
gloves are still advisable. My preferred tools:
• Band saw with a 3/8- or 1/4-inch blade designed for thin wood or plywood.
• Jigsaw. I have a special liking for the DeWalt XRP using Bosch blades that
are designed for hardwood or plastic. This will cut complex curves in ABS
as easily as scissors cutting paper.
No matter what type of saw you use, you’ll have to clean ragged bits of plas-
tic off the cut afterward, and the absolutely necessary item for this purpose
is a deburring tool, available from http://www.mcmaster.com and most other
online hardware sources. A belt sander or disc sander is ideal for rounding
corners, and a metal file can be used to remove bumps from edges that are
supposed to be straight.
Figures 5-77 through 5-80 show various cutting tools. Figure 5-81 shows a de-
burring tool, and Figure 5-82 shows a disc sander.
Figure 5-80. This DeWalt jigsaw can run at Figure 5-81. A deburring tool will clean and Figure 5-82. A belt sander or disc sander
very slow speeds, enabling precise and bevel the sawn edge of a piece of plastic in is the ideal tool for rounding corners when
careful work with plastic. just a couple of quick strokes. working with ABS plastic.
Making Plans
I like to use drawing software to create plans, and I try to print them at actual
scale. I tape them to the smooth side of a piece of white or natural-color ABS,
then use an awl to prick through the plan into the soft surface beneath. I re-
move the paper and connect the awl marks by drawing onto the plastic using
a pencil or a fine-point water-soluble pen. Its lines can be wiped away later
with a damp cloth. Don’t use a permanent marker, as the solvents that you will
need to clean it may dissolve the plastic.
Because ABS will tend to open a fissure when you bend it at any inside corner
where you don’t have a smooth radius, you need to drill holes at these loca-
tions, as shown in the cart plans in Figure 5-92 on page 275.
A regular half-inch drill bit is too aggressive; it will tend to jam itself into the
plastic within one turn of the drill. Use Forstner bits (shown in Figures 5-83 and
5-84) to cut nice smooth circles.
Figure 5-83. A Forstner drill bit makes
clean, precise holes; a large regular drill bit Note that the heat from bending will tend to make any marks on the plastic
will chew up ABS plastic and make a mess. permanent.
Bending It
A big advantage of plastic over wood is that you can make complex shapes by
bending them, instead of cutting separate pieces and joining them with nails,
screws, or glue. Unfortunately, bending does require an appropriate bender: an
electric heating element mounted in a long, thin metal enclosure that you place
on your workbench. The bender I use is made by FTM, a company that offers all
kinds of neat gadgets for working with plastic. Their cheapest bender, shown in
Figure 5-85, is just over $200 with a 2-foot element. You can get a 4-foot model
for about $50 more. Check them out at http://thefabricatorssource.com.
To bend plastic, lay it over the hot element of a plastic bender for a brief time
(25 to 30 seconds for 1/8-inch ABS, 40 to 45 seconds for 3/16-inch, and up to a
minute for 1/4-inch). If you overheat the plastic, you’ll smell it, and when you
turn it over you’ll find it looks like brown melted cheese. Naturally you should
learn to intervene before the plastic reaches that point.
ABS is ready to bend when it yields to gentle pressure. Take it off the bender
Figure 5-85. Making clean, precise bends and bend it away from the side that you heated. If you bend it toward the hot
in ABS is simply a matter of resting the side, the softened plastic will bunch up inside the bend, which doesn’t look
plastic over a bender that consists of an nice.
electric heating element.
272 Chapter 5
Experiment 32: A Little Robot Cart
You can work with it for about half a minute, and when you have it the way
you want it, spray or sponge water onto it to make it set quickly. Alternatively,
if you need more time, you can reheat it. The amount of force necessary to
bend the sheet increases in proportion with the length of the bend, so a long
bend can be difficult, and I usually insert it into a loose vise, push it a bit, move
it along to the next spot, and push it again.
Because plastic bending is very similar to making shapes in origami, it’s a good
idea to model your projects in paper before you commit yourself to ABS.
If you decide that you don’t want to spend money on a bender, don’t aban-
don plastic just yet—you can use screws to assemble separate sections with
greater ease and convenience than if you were working with wood.
Figure 5-86
2. Hold or clamp the pieces in place and poke a pen or pencil through the
holes to mark the edge of the 1/4-inch plastic beneath.
3. Remove the thin plastic, clamp the 1/4-inch plastic in a vise, and drill
guide holes for the screws at each mark, centered within the thickness of
the plastic. Because ABS does not compress like wood, the holes must be
larger than you may expect; otherwise, the plastic will swell around the
screw. A 3/32-inch bit is just right for a #4 screw.
4. Assemble the parts. Be careful not to overtighten the screws; it’s easy to
strip the threads that they cut in the soft plastic. Figure 5-87
Figure 5-88 Figure 5-89. Figures 5-86 through 5-89 Figure 5-90. Three #4 screws driven into
illustrate four steps to join two pieces of the edge of ABS, using a 1/16-inch guide
ABS using #4 sheet-metal screws. Cut hole, a 5/64-inch guide hole, and a 3/32-
7/64-inch holes on a line 1/8 inch from the inch guide hole. respectively Because the
edge of the first piece, then mark through first two guides holes were too small, the
the holes to the edge of the second piece. plastic swelled around the screw (but did
Drill 3/32-inch holes that are precisely not break).
centered in the edge, then screw the
pieces together.
Download at WoweBook.com
274 Chapter 5
Experiment 32: A Little Robot Cart
8"
2 1/2" 2 1/2"
3"
A
3"
9" Bend
Drill half-inch
holes to make
Bend
rounded inside
corners
3"
5"
B
1/4" 3"
Make C 2"
four
wheels
1/2 "
3"
4"
2"
E 2" F 2 1/2"
D
Figure 5-92. These sections of 1/4-inch plastic can be assembled to create the simple cart
described in Experiment 31.
Part B is a wheel, of which you will need four. I cut them using a 3-inch hole
saw. The front wheel is screwed to whatever disc or arm you obtained to mate
with the shaft of your motor. See Figure 5-93.
Parts C, D, and E assemble to form a yoke in which the rear wheel is mounted. I
Figure 5-93. A 3-inch wheel is screwed to
used a 2-inch hinge to pivot the yoke. The hinge is mounted on Part F, which is the disc that mates with the drive shaft of
a partition located midway in the frame of the cart. The photographs in Figures the motor.
5-94 and 5-95 will help to make this clear. Initially, when you install Part F, use
only two screws, one each side, so that you can adjust its angle a little. This will
be necessary to optimize the contact of the wheels with the floor.
The side wheels and rear wheel must spin freely, but on the other hand, they
shouldn’t wobble. I simply tightened the nuts on the bolts that serve as axles
for the wheels, until there was maybe half a millimeter of clearance. I added a
drop of Loctite to stop the nuts from getting loose.
The plans don’t show precisely where to drill holes for the axle bolts, because
Figure 5-94. The assembled body of the
cart, before adding control electronics. the location will depend on the size of your wheels. You can figure this out as
The wheel at the righthand end will pull the you go along. Just make sure that the side wheels aren’t mounted too low. We
cart from left to right. The hinged trailing don’t want them to lift the front wheel or the rear wheel off the floor. If the
wheel will allow the cart to move in a rela-
side wheels are a fraction higher off the ground than the front and rear wheels,
tively straight line when it moves forward,
but will tend to turn it when it backs up. that’s good.
If you have tile or wood floors, your cart may acquire better traction if you
wrap a thick rubber band around each disc that you use for the drive wheel
and the steering wheel.
The most important aspect of the construction is to place microswitches
where they’ll be triggered when the cart runs into something. I placed mine
at the front corners, as shown in Figures 5-96 and 5-97. And that brings me to
the electronics.
The Circuit
The schematic is very, very simple, with only four principal components: two
microswitches that sense obstacles in front of the cart, one relay, and one 555
timer. You will also need a small power switch, a battery or battery pack, and
a resistor, and capacitors to go with the timer. A trimmer potentiometer will
allow you to adjust the “on” time of the 555 timer, which will determine how
long the cart takes to back up. See Figure 5-98.
276 Chapter 5
Experiment 32: A Little Robot Cart
50K
1 8
100K
2 7
10K 3 6
4 5 47uF
0.01uF
Motor
Figure 5-98. This ultrasimple schematic is all the cart needs to enable it to back up when it
hits an obstacle.
The motor I chose requires 5 volts, so I had to use a voltage regulator with a
9-volt battery. If your motor uses 6 volts, you can wire four AA batteries to it
directly. If you have a 12-volt motor, you can use two 9-volt batteries in series,
supplying power through a 12-volt voltage regulator.
Assemble the components, mount them on the cart, and switch it on, and it
should move forward slowly in a more-or-less straight line. If it moves back-
ward, reverse your connection to the terminals on the motor.
When the cart bumps into something, either of the microswitches will con-
nect negative voltage to the input pin of the 555 timer. This triggers the timer,
which runs in monostable mode, generating a single pulse lasting about 5
seconds, which closes the relay, which is wired so that it reverses the voltage
to the motor.
When the voltage is reversed to a simple DC motor, it runs backward. So the
cart backs up. Because the rear wheel is mounted in a yoke that pivots, the
yoke will tend to flip one way or the other, causing the cart to describe an
arc as it moves backward. At the end of the timer cycle, the relay relaxes and
the cart starts moving forward again. In forward mode, the rear wheel just
follows along without applying any steering force, so the cart tends to follow
a straight line—until it hits another obstacle, at which point it backs up, and
tries another path.
Fundamentals
278 Chapter 5
Experiment 32: A Little Robot Cart
Fundamentals
Figure 5-99. The three diagrams, from top to bottom, show Figure 5-100. When the on/off switch at bottom-right opens,
three snapshots of a motor controlled by a DPDT relay and the relay connects its upper contacts. This causes the motor
two limit switches. When the on/off switch at bottom-right to run clockwise until its arm opens the lower limit switch.
sends power to the relay, the lower relay contacts cause the Limit switches avoid the overheating and possible damage
motor to run counterclockwise until it stops itself as its arm that are likely when power is delivered to a motor that is
opens the upper limit switch. prevented from turning.
Fundamentals
• Simple
• Reliable
• Will run in reverse when voltage reverses
In addition, brushed motors are often sold with reduc- Magnet
280 Chapter 5
Experiment 32: A Little Robot Cart
Mechanical Power
In the United States, the turning force, or torque, of a motor is usually mea-
sured in pound-feet or ounce-inches. In Europe, the metric system is used to
measure torque in dynes.
A pound-foot is easy to understand. Imagine a lever pivoted at one end, as
shown in Figure 5-102. If the lever is one foot long, and you hang a one-pound
weight at the end of it, the turning force is one pound-foot.
One foot
Rotational
force
(torque)
of one
pound-foot
1 lb. weight
Figure 5-102. The rotational force created by a motor is known as “torque,” and in the
United States it is measured in pound-feet (or ounce-inches, for small motors). In the
metric system, torque is measured in dynes. Note that the torque created by a motor will
vary according to the speed at which the motor is running.
Fundamentals
Wire gauges
If you’re going to power larger motors, or Diameter Ohms Feet Maximum
other components that take more current than AWG
in per per amps
LEDs or small relays, you really need to know inches 1,000 ft ohm (insulated)
about wire gauges. In particular, what’s the
relationship between wire thickness and AWG
(American Wire Gauge)? And what gauge of 0000 0.46 0.049 20,400 225
wire should you use for any given current?
You can find numerous charts and tables if you 000 0.41 0.062 16,200 200
go online, but many of these sources con-
tradict each other, especially on the topic of 00 0.365 0.078 12,800 175
how much current is safe to run through each
gauge of wire.
0 0.325 0.098 10,200 150
After making several comparisons (and testing
some wire samples myself ), I’ve compiled the 1 0.289 0.124 8,070 125
table in Figure 5-103, which I recommend as a
compromise. Note the following: 2 0.258 0.156 6,400 100
• This table applies to solid-core copper
3 0.229 0.197 5,080 90
wire.
• For stranded wire, or copper that has 4 0.204 0.249 4,020 80
been tinned (giving it a silver appear-
5 0.182 0.313 3,190 70
ance), the number of ohms per foot will
increase, the number of feet per ohm will 6 0.162 0.395 2,510 60
decrease, and the maximum amperage
7 0.144 0.498 2,010 51
will decrease, probably by around 20%.
The maximum amperage assumes that the 8 0.128 0.628 1,590 44
wire is insulated, preventing it from radiating 10 0.102 0.999 1,000 32
heat as effectively as a bare conductor. I am
also assuming that the wire is likely to be at 12 0.081 1.59 630 23
least partially enclosed, inside a box or cabi- 14 0.064 2.53 396 17
net. At the amperages listed for each gauge of
wire, you should expect the wire to become 16 0.051 4.02 249 13
noticeably warm, and personally I would tend 18 0.04 6.39 157 10
to use thicker wire instead of the maximums
indicated in the table. 20 0.032 10.2 99 8
Most tables of this type only tell you the resis- 22 0.025 16.1 62 5
tance of each gauge of wire in ohms per 1,000 24 0.02 25.7 39 2.5
feet. I have included that number but have
also expressed the function the other way 26 0.016 40.1 25 1.5
around, as the number of feet per ohm, as this 28 0.013 64.9 15 1.0
doesn’t require you to do so much arithmetic
with decimals. 30 0.010 103.2 10 0.5
Figure 5-103. American wire gauges (AWG) and their properties.
282 Chapter 5
Experiment 32: A Little Robot Cart
Theory
22 gauge wire
1.5 ohms
1.5 ohms
100 feet
100 feet
Bearing these factors in mind, I have compiled a table for
you. I’ve rounded the numbers to just two digits, as varia-
tions in the wire that you use make any pretense of greater
accuracy unrealistic.
To use this table, you need to know how much current is
passing through your circuit. You can calculate it (by adding 12 volt 12 volt
up all the resistances and dividing it into the voltage that battery battery
you are applying) or you can simply measure the current
with a meter. Just make sure that your units are consistent Approx. 10 mA current Approx. 1A current
(all in ohms, amps, and volts, or milliohms, milliamps, and 15mV voltage drop 1.5 volts voltage drop
millivolts).
Figure 5-104. The voltage drop imposed by wiring will depend
In the table, I have arbitrarily assumed a length of 10 feet on the current and the resistance in the circuit. The drop will
of wire. Naturally you will have to make allowances for the be greatest when the resistance of the circuit is low and the
actual length of wire in your circuit. The shorter the wire, amperage is high.
the less the loss will be. A circuit with only 5 feet of wire,
Theory
Wire Amperes
Gauge
1 2 3 4 5 6 7 8 9 10
10 0.08 0.17 0.25 0.33 0.42 0.50 0.58 0.67 0.75 0.83
12 0.13 0.27 0.40 0.53 0.66 0.80 0.93 1.1 1.2 1.3
14 0.21 0.42 0.63 0.84 1.1 1.3 1.4 1.5 1.9 2.1
16 0.33 0.67 1.0 1.3 1.7 2.0 2.3 2.7 3.0 3.4
18 0.53 1.1 1.6 2.1 2.7 3.2 3.7 4.3 4.8 5.3
20 0.85 1.7 2.6 3.4 4.3 5.1 6.0 6.8 7.7 8.5
22 1.3 2.7 4.0 5.4 6.7 8.1 9.4 11 12 13
24 2.1 4.3 6.4 8.6 11 13 15 17 19 21
26 3.4 6.8 10 14 17 20 24 27 31 34
28 5.4 11 16 22 27 32 38 43 49 54
30 8.6 17 26 34 43 52 60 69 77 86
Remember, though, that the wire resistance will be higher if you are using stranded copper wire or tinned copper wire, and
this will increase the percentage of voltage lost.
284 Chapter 5
Experiment 33: Moving in Steps
The data sheet will tell you in what sequence to apply power to the wires. You
can figure this out by trial and error if necessary. One thing to bear in mind: a
stepper motor is very tolerant. As long as you apply the correct voltage to it,
you can’t burn it out.
To see exactly what the motor is doing, stick a piece of duct tape to the end of
the shaft. Then apply voltage to wires, one at a time, by moving your negative
power connection from one to the next. You should see the shaft turning in
little steps.
Inside the motor are coils and magnets, but they function differently from Figure 5-106. The simplest test of a step-
those in a DC motor. You can begin by imagining the configuration as being per motor is to apply voltage manually
to each of its four control wires, while a
like the diagram in Figure 5-107. Each time you apply voltage to a different piece of duct tape, attached to the output
coil, the black quadrant of the shaft turns to face that coil. In reality, of course, shaft, makes it easy to see how the motor
the motor turns less than 90° from one coil to the next, but this simplified responds.
model is a good way to get a rough idea of what’s happening. For a more pre-
cise explanation, see the upcoming section “Theory: Inside a stepper motor.”
Bear in mind that as long as any of the wires of the motor are connected, it
is constantly drawing power, even while sitting and doing nothing. Unlike a
regular DC motor, a stepper motor is designed to do nothing for much of the
time. When you apply voltage to a different wire, it steps to that position and
then resumes doing nothing.
1 The coil inside the motor is holding the shaft in position, and the power that
the motor draws will be dissipated as heat. It’s quite normal for the motor to get
2
warm while you’re using it. The trouble is, if you use a battery to power it, and you
forget that you have it connected, the battery will not hold its charge for long.
3 Quick Demo
4 Now that you’ve proved that your motor is functional, how can you actually
run it? You need to send a pulse to each of the four wires in turn, in a rapidly
Figure 5-107. This greatly simplified repeating sequence. If you can also adjust the speed of the pulses, so much
diagram helps in visualizing the way in the better. I’m thinking that for a quick and simple demo, you can handle the
which a stepper motor works. In reality,
almost all motors rotate by less than 90° in challenge simply by using four 555 timers, all of them in monostable mode,
response to each pulse. with each one triggering the next.
The schematic in Figure 5-108 shows what I have in mind. It looks more com-
plex than it really is. Each timer has the same pattern of components around it,
so after you create the first module, you just make three copies of it.
10K 8K2
555
1K
22uF
0.01uF
10K 10K
555
1K
22uF
0.01uF
10K 10K
555
1K
22uF
0.01uF
10K 10K
555
1K
22uF
0.01uF
Stepper
Motor Figure 5-108. A very quick and simple
circuit to control a stepper motor uses
four 555 timers, each in monostable
mode, triggering each other in a
repeating sequence.
286 Chapter 5
Experiment 33: Moving in Steps
I’ve used a 10K resistor to pull up the input to each 555, so that the timers are
naturally in their quiescent state. A 0.01 μF capacitor links the output from one
timer to the input of the next so that they are electrically isolated from each
other, and the capacitor just conveys a “spike” of voltage when one timer fin-
ishes its “on” cycle, and its output goes low, which triggers the next.
On the righthand side, I’ve used 10K resistors and 22 μF capacitors to generate
a cycle of about a quarter of a second—except that the topmost timer has a
8K2 timing resistor. The reason for this is that when power is first applied, the
timers will all be waiting for each other to begin, and timers 2 and 4 or 1 and
3 may fire together. By giving one timer a shorter cycle than the others, I mini-
mize this problem. Figure 5-109. To test the control circuit for
errors, four LEDs show the outputs from
The LEDs are included just to give you some visual verification of what’s hap- the four 555 timers. The loose yellow wire
pening. Without them, if you make a wiring error, the motor may turn to and at the righthand side connects to pin 2
of the first timer. Touch the free end of
fro erratically, and you won’t know why. Initially you can run your circuit with
this wire to the positive side of the power
only the LEDs connected, just to make sure it works. Figure 5-109 shows the supply to reset the timers, and then, if nec-
breadboarded circuit before the motor is plugged in. Then add the motor by essary, make a brief negative connection
plugging its wires into the breadboard, where you’ll make connection with the with the free end of the wire to restart their
sequence.
outputs (pins 3) of the timers. See Figure 5-110.
Apply power, and you should see the motor turning in steps, in sequence with
the LEDs. If the LED sequence isn’t stable:
1. Connect a wire directly from the input (pin 2) of the topmost timer to the
positive side of the voltage supply, and wait for the timers to calm down.
2. Restart the sequence by disconnecting the free end of this wire, or (if nec-
essary) touch the free end of it briefly to the negative side of the supply,
to trigger the first timer.
One thing you may have noticed, if you’re paying very close attention: the
common terminal of the motor is connected to positive. Therefore, when each
timer flashes positive, that positive signal isn’t actually powering the motor.
The low outputs from the three timers that are not firing at any given moment Figure 5-110. After the circuit has been
are sinking current from the motor. It seems quite happy with this arrange- tested, the motor can be added by hook-
ment. You’ll need some theory to understand why. ing its control wires to the outputs of the
four 555 timers.
Theory
Step 1 Step 3
S N S N S N S N S N S N S N S N
Step 2 Step 4
S N S N S N S N S N S N S N S N
Figure 5-111. This sequence shows the first two steps as the rotor Figure 5-112. After taking another two steps, the motor will be
of a stepper motor (shown as a series of north-south magnets) back where it started at Step 1 in Figure 5-111.
moves in response to pulses through electromagnets.
288 Chapter 5
Experiment 33: Moving in Steps
Theory
S N S N S N S N
Speed Control
If you are a truly exceptionally observant, you may have noticed that I left pin 5 of
each of the timers unconnected in the schematic for driving the stepper motor in
Figure 5-108. Normally, pin 5 should be grounded through a capacitor to prevent
it from picking up stray voltages which can affect the accuracy of the chip.
I left the pins unconnected because I had a plan for them. In fact, changing the
timing of the chip is exactly what we want to do now, as a way to change the
speed of the stepper motor.
If you tie pin 5 of all four timers together, as shown in Figure 5-116, and put
a 2K trimmer potentiometer (shown in Figure 5-117) between them and the
negative side of the power supply, you’ll find that as you turn the trimmer
to reduce its resistance, the timers start to run faster. Figure 5-118 shows the
breadboard layout. Eventually, when the resistance goes below around 150
ohms, everything stops. The LEDs go dark, because you’ve reduced the volt-
age on pin 5 below the threshold level that the 555 timer finds acceptable.
10K 8K2
555
1K
22uF
0.01uF
10K 10K
555
1K
22uF
0.01uF
10K 10K
555
1K
22uF
0.01uF
2K
Stepper
Motor
Figure 5-116. To adjust the speed of the sequence of 555 timers, their control pins (pin
5 on each timer) are linked together and attached to a trimmer potentiometer that Figure 5-118. The trimmer potentiometer has been
adjusts the resistance between the pins and the negative side of the power supply. added to the circuit, allowing motor speed control.
290 Chapter 5
Experiment 33: Moving in Steps
Initially I suggested a step time of 1/4 second just so that you could see what
was happening. When you’re actually using this circuit, you’ll never need it to
run as slowly as that. So you can increase the entire range of speeds. Remove
the 22 μF timing capacitors and substitute, say, 4.7 μF capacitors, or smaller.
Now when you adjust the potentiometer, you’ll get a useful range of speed.
Adding Autonomy
Currently, the circuit simply does what you tell it to do. The next step is to
make it autonomous—in other words, give it the illusion of making up its own
mind. I’m thinking that instead of a trimmer potentiometer, we could substi-
tute a photocell, properly known as a photoresistor. Typically, the resistance of
a cadmium sulfide photo resistor is highest in the dark, and lowest when light
shines on it.
One problem with photoresistors is that they’re not as widely available as
many other types of electronic components. If you search Mouser.com, for
instance, you’ll find virtually nothing. Partly this is because the online search
function at Mouser is the weakest feature of the site, and partly it’s because
Mouser is not oriented toward hobbyists. What you need to do is conduct a
“product search.” Go to http://www.google.com/products, enter the search terms
“CdS” and “photocell,” and you’ll find a bunch of cheap cadmium sulfide com-
ponents from places you may never have heard of.
Because photoresistors seem to come and go as erratically as DC motors, I am
not offering any part numbers. You can buy any product that has an appropri-
ate minimum resistance (in bright light) and maximum resistance (in the dark).
If you find a component that ranges from 500 to 3,000Ω, that would be a good
choice. If the only ones you can find have a higher minimum than 500Ω, you
could consider putting a couple of them in parallel. Photo-
Resistors
Photo- the chip functions as an inverter, so that when the input goes high, the output
Resistors
goes low and sinks current. This is of course just what we need for our stepper
motor that has a common positive connection.
The ULN2001A is only an amplification device, so you have to precede it with
a counter that runs from 1 to 4 and then repeats. You can stick with your 555
555 Timer 555 Timer
timers, as you’ve already assembled them, or substitute almost any CMOS oc-
tal or decade counter that sends its output pulses to a series of pins. Just use
Counter Counter
the output from the fifth pin as the “carry” output to restart the counting se-
Amplifier Amplifier
quence. I suggest a CMOS counter simply because it will run on 12 volts, so
you can use the same power supply that suits your stepper motors.
If you switch to CMOS counters, you will still need a pair of 555 timers send-
ing pulses to the counters. The timers will be free-running in astable mode,
and your photoresistors will control their speed. Figure 5-120 shows the
configuration.
One last item: you’ll need a 12-volt battery. You can of course put eight AA cells
Stepper
together, but I think you should consider a rechargeable pack from a source
Motors such as http://www.all-battery.com, which has a section entirely devoted to “ro-
bot batteries.”
Figure 5-120. A more efficient way to drive
the motors is to use just one timer to set If you put it all together, you should find that when you place your robot cart in
the speed of each, with a counter and
amplifier (such as a Darlington array chip)
a very dimly lit room, it will turn toward the beam from a bright, well-focused
sending the pulses down the wires. The flashlight. To get reliable results, you may have to recess each of the photo-
principle is still the same, though. resistors in little tubes, so that they receive much more light when they face
your flashlight than when they face away from it. Figure 5-121 is a 3D render-
ing of the concept.
Another idea is to rewire your cart so that it actually runs away from the light.
Can you imagine how this might be done?
Just one more thought: if you use infrared photoresistors, you can control your
cart with beams from infrared LEDs, in normal room lighting. If you and a cou-
ple of friends all have infrared transmitters, you can get your cart to run from
one of you to the next, like an obedient dog.
This takes us about as far as I’m going to go into robotics. I urge you to check
out the sites online if you want to pursue the topic further. You can also buy a
Figure 5-121. This 3D rendering shows a wide variety of robot kits, although of course I feel that it’s more fun to invent
possible configuration of the light-seeking
cart, with two photoresistors enclosed in
or develop things for yourself.
small tubes to restrict their response to All that’s left now is to perform one last introduction: to a device that should
light.
make your life much easier, even though the device is much more complicated
than anything we have dealt with so far.
292 Chapter 5
Experiment 34: Hardware Meets Software
Background
294 Chapter 5
Experiment 34: Hardware Meets Software
Supplies
Figure 5-122 shows some of the chips in the PICAXE range. I’ll be telling you
how to use the smallest—the 08M—which costs less than $5 and is cheaper
than any other MCU that I’ve found. It has only 256 bytes of memory to store a
program (not gigabytes, megabytes, or kilobytes, just 256 bytes!), but you’ll be
surprised how many possibilities this amount allows for. Figure 5-123 shows
a closeup of the 08M with its legs safely embedded in a piece of conductive
foam.
In the United States, there are three distributors of this chip:
• http://www.advancedmicrocircuits.com
• http://www.phanderson.com/picaxe
• http://www.sparkfun.com
I like P. H. Anderson for its grass-roots hobbyist approach, and they have good
prices if you want to buy multiple chips. But SparkFun Electronics offers other
associated products that you may find interesting.
All the distributors will want to sell you “starter kits,” such as the one in Figure
Figure 5-122. A page from the PICAXE cata-
5-124, perhaps because the PICAXE itself is so cheap that it doesn’t offer much
log lists only some of the chips that are
of a profit margin. Still, for our purposes, you should buy the chip as a stand- available. What began as an educational
alone item. And buy two of them, just in case you damage one (for example, aid has become a useful prototyping tool.
by connecting voltage to it incorrectly).
Figure 5-123. When supplied by one of its Figure 5-124. A typical PICAXE kit includes
American distributors, a PICAXE 08M a printed circuit board, which you may not
arrives embedded in a little square of really need, and some other not-entirely-
conductive foam. The chip is the same size essential items. But the 3.5-mm stereo
as a 555 timer but has the power of a tiny jack socket (top, center) is absolutely
computer. necessary.
To download your programming instructions into the chip, first you’ll type the
instructions on a computer, and then you’ll feed them through a cable into
the PICAXE memory. So you’ll need to buy a cable, and you’ll need software to
help you to write the program.
You can use the PICAXE with a serial cable, but I don’t recommend it. The old RS-
232 serial communications standard on PCs is pretty much obsolete, and PICAXE
has recognized this by offering a USB cable (which contains a serial converter
inside its plug). The USB cable is a little more expensive, but is also simpler and
compatible with Apple computers. From any of the U.S. distributors, buy USB
cable part AXE027, also sold as part PGM-08312 by http://www.sparkfun.com
(quantity: 1). The cable is shown in Figure 5-125.
To write your software and send it down the wire to the chip, the PICAXE
Programming Editor is the tool of choice. It comes in only a Windows ver-
sion. For those who prefer Mac OS or Linux, you can get a free download of
another piece of software known as AXEpad, which has fewer features, but
Figure 5-125. The USB download cable will do the job. All the downloadable software is freely available from http://
made for use with the PICAXE terminates
in a 3.5-mm audio plug. This should not be www.rev-ed.co.uk/picaxe/software.htm.
inserted in any audio device. It establishes
a serial connection with a computer, allow-
Finally, you need a 3.5-mm stereo audio socket with solder connections. The
ing program code to be downloaded into reason for this is that the manufacturers of the PICAXE have used a stereo au-
the chip. dio plug on the free end of their USB cable, and you have to be able to plug
it into something. The PICAXE breadboard adapter, SparkFun stock number
DEV-08331, contains the necessary stereo socket in addition to a few other
little items. Quantity: 1. See Figure 5-126.
Oddly enough, the USB cable is the most expensive item on the list, because
of the electronics hidden inside it.
296 Chapter 5
Experiment 34: Hardware Meets Software
Scroll down past all the software until you get to Additional Resources. Look
for the AXE027 PICAXE USB Download Cable. At first glance, it looks as if they
Be careful not to download the driver
want to sell you a cable, but in fact this is the list of drivers. Double-click the
for the USB010 USB-Serial adapter
one appropriate to your computer, and choose a destination on your com- by mistake. The USB-Serial adapter is
puter for the download—a place where you will find it easily, such as your something else entirely.
desktop.
The download will leave you with a zipped file folder. You will have to unzip it.
On Windows XP, right-click the folder and choose “Extract all.” View the extract-
ed files and you will find a PDF installation guide. Linux and Mac users can find
instructions currently stashed at http://www.rev-ed.co.uk/docs/AXE027.pdf.
When installing the driver on a Windows platform, here are a few tips to mini-
mize your exasperation level:
1. Remember, the special USB cable contains some electronics. It is not just
a cable, but a device designed for interacting with a PICAXE chip. Don’t try
to use it for anything else!
2. You have to plug the cable into a USB port before you install the driver, be-
cause your computer will need to verify that the driver matches the cable.
3. You must not attach the PICAXE to the other end of the cable until after
you have installed the driver.
4. Every USB port on your computer has a separate identity. Whichever one
you choose when you first plug in the cable, you should use that port
every time in the future. Otherwise, you will have to repeat the process of
telling your computer what the cable is.
5. Bearing in mind Tip #4, you should avoid using the cable in a standalone
USB hub.
6. The cable is fooling the PICAXE into thinking that it’s talking to a serial
port on your computer. Those “communication” ports are known as COM1,
COM2, COM3, or COM4. When you install the driver, the installer will
choose one of those COM ports for you, and later you will have to know
which one it is. The PDF guide should help you through this procedure.
Unfortunately, you cannot skip it.
In the Programming Editor, go to View→Options and click the Mode tab, then
click the button to select the 08M chip.
Figure 5-127. This screenshot shows the options win- Figure 5-128. Another screenshot of the options window
dow of the PICAXE Program Editor, which you must use shows the second essential choice that you must
to select the type of chip that you intend to program (in make: selection of the COM port that the installer
our case, the 08M). chose on your computer.
Are we having fun yet? Obviously not, but you’re through with software has-
100uF sles for the time being. The last step before you’re ready to use the PICAXE is to
mount it, and its socket, on your breadboard.
0.1uF
0.1uF
9V DC input
100uF Setting up the hardware
(unregulated)
The PICAXE 08M looks like a 555 timer. (Other chips in the PICAXE range have
more pins and more features.) It requires a properly regulated 5 volts, just like
the logic chips you dealt with previously. In fact, the PICAXE people are rather
emphatic about protecting it from voltage spikes. They want you to use two
capacitors (one 100 μF, one 0.1 μF) on either side of an LM7805 regulator. This
5V DC output
(regulated) seems like overkill, but the PICAXE is more inconvenient to replace than a 555
Figure 5-129. PICAXE documentation
timer. You certainly can’t run down to RadioShack to buy one. So let’s do what
specifies a 100 μF and 0.1 μF capacitor the manufacturer says, just in case, and set up a breadboard as shown in Fig-
on the input side of a 5-volt regulator, and ures 5-129 and 5-130.
a similar pair of capacitors on its output
side. On a breadboard, they can be ar- Now for the chip itself. Note that the pins for positive and negative power are
rayed like this. exactly opposite to those for the 555 timer, so be careful!
Set up your breadboard following the schematic shown in Figure 5-131. Note
that I am showing the stereo socket on its underside, because I think that’s
how you’ll have to use it with the breadboard. If you try to stick its pins into the
holes in the board, they will fit, but when you insert the plug into the socket,
the thickness of the plug will tend to raise the socket up so that it loses con-
tact. I really think the way to go is to solder wires to the pins on the socket and
push the wires into the breadboard. See Figure 5-133.
298 Chapter 5
Experiment 34: Hardware Meets Software
a
10K b c
22K
1 8
2 7
PICAXE
08M
3 6
4 5
330
Figure 5-131. The schematic of a test circuit for the PICAXE 08M shows the underside of
the stereo socket, the essential 10K and 22K resistors on the input pin, and an LED to
show an output from the chip. Pin 2 Pull-Down
Be aware that the PICAXE manual shows things differently (although I have Always include the 22K resistor and
retained their labeling convention for the parts of the socket and the parts of the 10K resistor in the configura-
tion shown in Figure 5-131. These
the plug, identified as a, b, and c).
resistors apply correct voltage to the
One little detail about the socket that is commonly supplied for use with the serial connection, and when you’re
PICAXE: typically it has two pairs of contacts for the connections labeled b and using the PICAXE on its own, they pull
down the voltage on pin 2.
c in the manual, and in my diagram. When you solder a connection, your sol-
der joint should include both of the contacts in each pair, as shown in Figure If pin 2 is left unconnected (floating),
5-132. it may pick up random voltages,
which the chip can misinterpret as a
Remember that the PICAXE must have 5 volts DC, and remember that your new program or other instructions,
voltage regular will deliver this voltage reliably only if you give it extra voltage with unpredictable and undesirable
on its input side. If you provide it with 9 volts, that will provide a good amount results.
of headroom. The 22K and 10K resistors should be
regarded as permanent items ac-
The 22K and 10K resistors are essential for using the chip; see the following
companying your PICAXE regardless
warning note for an explanation. My schematic also includes an LED and of whether you have it attached to
a 330Ω resistor, but they are needed only for the test that we’ll be making your computer.
momentarily.
Negative
Out to Power
In from
Computer
Computer
Figure 5-132. Correct wiring of the socket is essential. When soldering wires to Figure 5-133. The breadboard version of the test
the lower terminals, make sure that you attach the wires to both of the terminals schematic, with the plug of the USB download
in each pair. cable inserted in the socket on the board. The
PICAXE chip can now receive a downloaded pro-
gram, and will immediately start to execute it.
300 Chapter 5
Experiment 34: Hardware Meets Software
If you detect the voltage, the software is installed and working properly. In
that case, there’s a problem on your breadboard, either in the chip or in the
wiring around it.
If you cannot detect any voltage, the software probably wasn’t installed prop-
erly, or is looking for the wrong serial port. Try uninstalling it and reinstalling it.
Be sure to include the colon after the word “main” on the first line. See Figure
5-136 for a screenshot. The indents are created by pressing the Tab key. Their
only purpose is to make program listings more legible. The software ignores
Type a program
them.
using the
Program Editor
Click the
PROGRAM button
to download it
Figure 5-136. This screenshot shows the first test program as it should be displayed by the
The PICAXE
Programming Editor (on a Windows computer).
Click the Program button in the Programming Editor to download this program starts running
into the chip. As soon as the download is complete, the chip should start flash- the program
ing the LED, lighting it for 1 second and then switching it off for 1 second. Figure
5-137 shows the steps that you should have followed to program the chip.
Now for the interesting part: disconnect the USB cable from the breadboard.
The chip should continue flashing.
You can now
Disconnect the power supply from the breadboard and wait a minute or two
for the capacitors to lose their charge. Reconnect the power, and the chip will unplug the
start flashing again. stereo plug
The program that you downloaded to the chip will remain in the memory in- Figure 5-137. Four steps to create and run a
side the chip and will begin running every time power is applied to the chip. program on the PICAXE controller chip.
1 8
2 7
PICAXE
(Logic Pin 0)
08M
Logic Pin 4 3 6 Logic Pin 1
1 8 Out to Computer
In from Computer Digital Output Pin0
2 7
PICAXE
Infra-Red Output
08M
3 6
Digital Output Pin4 Digital Output Pin1
Digital Input Pin4 4 5 Digital Input Pin1
Analog-Digital Converter Pin4 Analog-Digital Converter Pin1
302 Chapter 5
Experiment 34: Hardware Meets Software
Editing
What if you want to change the program? No problem! Use the Programming
Editor to change one of the lines in the program. Substitute 100 instead of
1000 milliseconds, for instance. (The pause command can be followed by any
number up to 65535.) In your program, don’t use a thousands comma in any
of the numbers that you specify.
Plug the USB cable into the breadboard again, hit the Program button on the
screen, and the new version of the program will be automatically downloaded
to the chip, overwriting the old version.
What if you want to save the program for future use? Just go to the File menu
in the Programming Editor and save the program onto your computer’s hard
drive. Because the PICAXE uses a variant of the BASIC computer language, it
adds a .bas filename extension.
Simulation
If you make a simple typing error, the Programming Editor will find it and stop
You’ll need to check the second
you from downloading your program. It will leave you to figure out how to fix
part of the PICAXE documentation,
the line that contains the error. which contains all the programming
Even if all the statements in your program are correctly typed, it’s a good idea statements and their correct syntax.
At the time of writing, this is stored
to run a simulation of what they’ll do, before you download them. This is easily
at http://www.rev-ed.co.uk/docs/
done: click the “simulate” button on the menu bar of the Programming Editor. picaxe_manual2.pdf.
A new window will open, displaying a diagrammatic view of the PICAXE chip
and showing you the states of its pins. (Note that if you use very short pause
commands, the simulation won’t run fast enough to display the time accu-
rately.) A simulation screenshot is shown in Figure 5-140.
The >> button at the bottom-right corner of the simulation window will open
up a list of all the variables in your program. So far, it doesn’t have any vari-
ables, but it soon will. All the zeros on the righthand side are binary numbers,
which you can ignore for now.
Loops
Here’s another thing I’d like you to try. Rewrite your program code as shown
here and download it onto the PICAXE:
main:
for b0 = 1 to 5
high 1
pause 200
low 1
pause 200
next
wait 2
goto main
Note that b0 is letter b followed by a zero, not letter b followed by letter O. The
extra indents once again are added to make the listing easier to understand.
The four lines beginning “high 1” and ending “pause 200” will be executed re-
peatedly. It’s helpful to see them as a block.
Watch the light and see what happens. It should flash five times quickly, then
wait for two seconds, and then repeat. You just added a loop to your program.
You can use a loop if you want something to happen more than once.
b0 is known as a variable. Think of it as being like a little “memory box” with its
name, b0, on a label on the outside. Figure 5-141 illustrates this concept. This
particular memory box can contain any number from 0 through 255. The loop
begins by telling the computer to put number 1 in the box, then process the
remaining statements, until the word “next” sends the processor back to the
first line, at which point it adds 1 to the contents of b0. If the value of b0 is 5 or
less, the loop repeats. If the value is 6, the loop has run five times, so it’s over,
and the PICAXE skips down to the “wait 2” statement after “next.” See Figure
5-142 for an annotated version of the program listing.
Figure 5-141. To understand how a program “Wait” is a PICAXE command that is measured in whole seconds, so “wait 2”
works, visualize a variable as being like a
“memory box” with its name on the out- waits for 2 seconds. Then “goto main” begins the procedure all over again.
side and a number stored on the inside.
If your flashing-light demo worked out as planned, it’s time to take the next
step and make the chip do something more useful.
Label identifying
this piece of the program.
Use b0 to count
from 1 to 5.
Has b0 reached 6 yet?
If so, skip down beyond Obey these
the "next" statement. instructions
five times.
Go back to line 2
and add 1 to b0.
Figure 5-142. The blue annotations explain what the program, on the right, is telling the
PICAXE to do.
304 Chapter 5
Experiment 34: Hardware Meets Software
Fundamentals
PICAXE
through 255.
08M
• No negative or fractional values are allowed in 3 6
variables.
4 5
• You also have 7 double-byte variables, named w0
through w6. The “w” stands for “word.” Each can hold a
value ranging from 0 through 65535.
• The “b” variables share the same memory space as the 10K 10K
“w” variables. Thus:
• b0 and b1 use the same bytes as w0.
• b2 and b3 use the same bytes as w1.
• b3 and b4 use the same bytes as w2. Figure 5-143. The PICAXE can respond to the state of a switch
or button attached to any of its input-capable pins. A 10K resis-
• b5 and b6 use the same bytes as w3. tor must be used to pull down the state of the pin when the
• b7 and b8 use the same bytes as w4. contact of the switch or button is open. Otherwise, you may
• b9 and b10 use the same bytes as w5. get unpredictable results.
• b11 and b12 use the same bytes as w6.
• b13 and b14 use the same bytes as w7.
Therefore, if you use w0 as a variable, do not use b0 or
b1. If you use b6 as a variable, do not use w3, and so on.
Procedure
Take the same trimmer potentiometer that you used in Experiment 32 and
wire its center terminal to Logic Pin 2 of the PICAXE (which is hardware pin
5). The other two terminals of the 2K trimmer go to positive and to negative,
respectively. So depending how you set the trimmer, the pin of the PICAXE is
directly connected to positive (at one end of the scale), or directly connected
to negative (at the other end of the scale), or somewhere in between. See Fig-
ure 5-144 for the revised schematic, and Figure 5-145 for a photograph of the
breadboarded circuit.
a
10K b c
22K
1 8
2 7
PICAXE
08M
3 6
4 5
330
2K
Figure 5-144. This schematic, drawn in a layout suitable Figure 5-145. The trimmer potentiometer added to the previ-
for breadboarding, shows how a 2K potentiometer can be ously breadboarded circuit.
used to apply a varying voltage to one of the pins of the
PICAXE that is capable of converting an analog signal to a
digital value.
306 Chapter 5
Experiment 35: Checking the Real World
Now we need a program to tell the chip what to do. Using the Programming
Editor, start a new document. The code should look like this:
main:
readadc 2,b0
debug b0
goto main
The command “readadc 2,b0” means “read the analog input on Logic Pin 2,
convert from analog to digital, and store the result in b0.”
The command “debug b0” tells the chip to go into program debugging mode,
in which it uses its USB cable to tell the Programming Editor the values of all
the variables while the program is running. The variables are displayed in a
debugging window.
Download the program, and as the program starts to execute, the debugging
window should open. Start adjusting the trimmer while looking at the value of
b0, and you’ll see b0 change its value.
You can make a table and draw a graph showing the relationship between the
resistance between Logic Pin 2 and ground, and the value of b0. Just pull the
trimmer off the breadboard, measure its resistance with a meter, then increase
its resistance by, say, 200Ω, put it back into the breadboard, and look at the
value of b0 again.
This is laborious, but calibrating equipment is always laborious—and in any
case, I decided to do it for you. The graph is shown in Figure 5-146. You can
also see the raw data numbers in the following table. I was pleased to find that
the PICAXE gives a very precise, linear response to the input voltage. In other
words, the graph is a straight line.
2000
Resistance in Ohms Between Pin and Negative Ground
1500
1000
500
Now we can modify the program to make it do something with the informa-
tion that it’s taking in:
main:
readadc 2,b0
let w1 = 5 * b0
high 1
pause w1
low 1
pause w1
goto main
308 Chapter 5
Experiment 35: Checking the Real World
Notice what’s happening here. First we get a value in b0, and then on the next
line, we do some arithmetic with it. The asterisk means “multiply.” So the state-
ment says, “Take whatever value is in b0, multiply by 5, and transfer it to an-
other variable, w1.” We have to use a w variable, because when we multiply the
value of b0 by 5, we may get a number that is bigger than 255—too big to fit
into a byte variable.
Finally, we take variable w1 and use it with a “pause” statement instead of a
fixed number value. We’re saying to the PICAXE, “pause for whatever number
of microseconds you get by checking the value of w1.”
So the software checks a variable resistance, turns it into a number, and ap-
plies that number to adjust the flashing speed of the LED.
Think back to the need of the cart powered by stepper motors. It was supposed
to check two photoresistors, and adjust the speed of each motor accordingly.
Well, this PICAXE program is a step in that direction. It can measure voltage on
a pin and change the output frequency on another pin. If you had two PICAXE
chips, you could wire each of them to a photoresistor and a motor. Then you
could adjust the behavior of your cart by editing the second line in the pro-
gram, where it converts the value of b0 to the value of w1 which will be used in
the “pause” command to determine the number of pulses per second. Instead
of multiplying by 5 you could multiply by 7 or whatever number gives you the
result you need. This leads to an important conclusion: a big advantage of a
programmable chip is that you can make adjustments in software.
Because the PICAXE 08M actually has more than one ADC input, and has three
pins that can be used for output, you might wonder whether you could use
just the one chip to control both motors in response to inputs from two sen-
sors. The problem is that the three output pins on the 08M also function as the
three ADC input pins. You’d do better to buy one of the more advanced PICAXE
chips, such as the 18M, which has more pins to choose from. It uses the same
basic set of programming instructions, and doesn’t cost much more money.
Also, you should read the PICAXE documentation and look up the “pwmout”
command, which is short for “pulse-width modulation output,” but you can
think of as meaning “power motor output.” This is specifically intended to run
stepper motors. It establishes an output frequency of pulses that will continue
while the chip obeys other instructions in its program.
Fundamentals
Extra features
A complete guide to the 08M would fill a book of its own, and of course such
books already exist (just search the books section of Amazon.com for keyword
“picaxe”). But I’ll finish my introduction to the controller by listing some of its
extra capabilities, leaving you to look them up and explore them. Then I’m go-
ing to suggest one last experiment.
Interrupts
The PICAXE 08M allows you to set one “interrupt.” This feature tells the chip
to make a mental note that if a particular event occurs—such as a switch
applying voltage to one pin—it should stop doing whatever else it was
doing, and respond to the interruption.
Infrared
One pin on the PICAXE 08M can be used to receive infrared signals from
a TV-style remote that you can buy from the same suppliers that sell the
PICAXE itself. With an infrared sensor attached to the chip, you can issue
commands remotely. If you want to build a remote-controlled robot, the
chip is specifically designed with this in mind.
Servo motors
Every PICAXE chip has at least one pin that can send a stream of pulses to
control a typical servo motor. On the 08M chip, it’s Logic Pin 2. The width of
each pulse tells the motor how far to rotate from its center position before
stopping. A 555 timer can send this stream, but the PICAXE makes it easier.
You can search online for more information about servo motors, which are
especially useful for applications such as steering model vehicles, adjusting
the flaps on model airplanes, and actuating robots.
Music
The PICAXE has an onboard tone generator that can be programmed with
a “tune” command to play tunes that you write using a simple code.
Alphanumeric input/output
The “kbin” programming command is available in the PICAXE models 20X2,
28X1 and 28X2, and 40X1 and 40X2. You can plug a standard computer
keyboard into the chip, and it will read the keypresses. You can also attach
alphanumeric displays, but these procedures are nontrivial. For instance,
when you’re trying to figure out which key someone has pressed on a key-
board, your program has to contain a list of the special hexadecimal codes
that the keyboard creates.
Pseudorandom number generation
All PICAXE models can generate pseudorandom numbers using a built-in al-
gorithm. If you initialize the number generator by asking the user to press a
button, and you measure the arbitrary time that this takes, you can seed the
pseudorandom number generator with the result, and the pseudorandom
number generator will have a less repeatable sequence.
Visit http://www.rev-ed.co.uk/docs/picaxe_manual1.pdf to learn more.
310 Chapter 5
Experiment 36: The Lock, Revisited
say that the value will be between 71 and 83. If we specify a range as shown in
the following table, we have a much better chance of interpreting each button
correctly.
Suppose you attach the common pin of your keypad to ADC Logic Pin 2 of the
PICAXE. You can now use the Program Editor to write a program that looks like
this:
getkey:
readadc 2,b0
let b1 = 9
if b0 < 84 then finish
let b1 = 6
if b0 < 97 then finish
let b1 = 3
if b0 < 109 then finish
let b1 = 0
if b0 < 122 then finish
let b1 = 8
if b0 < 135 then finish
let b1 = 5
if b0 < 148 then finish
let b1 = 2
if b0 < 161 then finish
let b1 = 7
if b0 < 173 then finish
let b1 = 4
if b0 < 186 then finish
let b1 = 2
finish:
return
What does the word “return” mean at the end? I’ll get to that in a second. I want
to explain the rest of the routine first.
312 Chapter 5
Experiment 36: The Lock, Revisited
PICAXE
ADC pin
500
100
100
1 2 3
100
100
100
4 5 6
100
100
100
7 8 9 600
100
Reset
0 relay
* #
Figure 5-147. A quick and simple way of attaching a keypad to provide numeric input to the
PICAXE uses a chain of resistors totalling 2,000Ω. When a button is pressed, it connects the
ADC input pin to a point in the chain. The resistance detected by the input pin can then be
converted by the program in the chip to determine which key has been pressed.
I have chosen an arbitrary combination of 7-4-1 for our combination lock. Us-
ing these numbers, the main section of the program looks like this:
main:
low 1
gosub getkey
if b1<>7 then main
gosub getkey
if b1<>4 then main
gosub getkey
if b1<>1 then main
high 1
end
I should explain that the <> pair of symbols mean “is not equal to.” So the
fourth line of the program means, “if b1 is not equal to 7.”
The value of b1 is supposed to be 7 if the user is putting in the correct com-
bination. So if it’s not 7, the user has entered the wrong value, and the if-then
statement sends the PICAXE back to the beginning. In fact anytime the user
inputs a number that is not in the correct 7-4-1 sequence, the program sends
the PICAXE back to the beginning. This is the way the pure-hardware version
of this experiment was set up.
But what is this word “gosub”? It means “go to a subroutine.” A subroutine is
any sequence of program statements that ends with the instruction to “return.”
So “gosub getkey” tells the PICAXE to mark its current place in the program
while it skips to the getkey: section of code, which it obeys, until it finds the
word “return,” which returns it to the place from where it came.
The PICAXE continues in this fashion until it reaches the word “end.” I had to in-
sert the word “end” because otherwise the PICAXE will continue executing the
program and will fall into the subroutine. “End” stops it from doing so. Figure
5-148 shows a screenshot of the complete listing.
So—is that all? Yes, that’s it. If you enter the code into the Programming Editor
exactly as I have supplied it, you should be able to run it in simulation mode,
and in the simulation window, click the right-arrow beside Logical Pin A2 to
increase its value in steps. Each time you pass one of the values in the getkey:
subroutine, you should see the value for variable b1 change in the display.
This is really all you need to perform the functions of the combination lock.
When the PICAXE runs this program, it waits for the correct combination. If it
receives the combination, it sends the output from logical pin 1 high; other-
wise, logical pin 1 stays low.
The only additional item you need is a transistor or CMOS gate between logi-
cal pin 1 and the relay that unlocks the computer, because the PICAXE cannot
deliver enough current to operate the relay by itself.
Putting this procedure into a controller chip not only simplifies the circuit, but
offers another advantage: you can change the combination simply by rewrit-
ing the program and downloading the new version into the chip.
314 Chapter 5
Experiment 36: The Lock, Revisited
Fundamentals
Limitations of MCUs
The PICAXE does have some disadvantages. Its voltage The PICAXE, for instance, doesn’t protect you if a number
requirements alone restrict you from using it with the kind is assigned to a variable that exceeds the limit for that type
of freedom of a 555 timer. of variable. Suppose b1=200 and b2=60 and your program
tells the PICAXE:
Also, although I can get an instant result by plugging a 555
timer into a breadboard and adding a couple of resistors let b3 = b1 + b2
and a couple of capacitors, the PICAXE requires me to add The result should be 260, but byte-size variables can only
a download socket, hook it up to my computer, write a count up to 255. What happens? You will find that b3 ac-
program in the Programming Editor, and download the quires a value of 4, without any warning or explanation. This
program. is known as an “overflow error,” which can be very difficult
to predict, because it happens at runtime, when external
Some people don’t like writing software, or they have dif- factors are in control. The code looks perfectly good; the
ficulty thinking in the relentlessly left-brain way that com- Programming Editor doesn’t find any syntax errors; the
puter programming requires. They may prefer the hands-on simulation behaves properly. But in the real world, days or
process of assembling hardware. even months later, an unexpected set of circumstances re-
Other people may have the opposite preference. This of sults in an input that causes the overflow, and because the
course is a matter of taste, but one thing we know beyond code is residing inside the chip at this point, you may have a
all doubt is that computer programs often contain errors hard time figuring out what on earth went wrong.
that may not reveal themselves until weeks or months later. Software has its problems. Hardware has its advantages.
Fundamentals
Unexplored territory
If you’ve taken the time to complete most of the projects in this book with your
own hands, you have gained a very rapid introduction to the most fundamental
areas of electronics.
What have you missed along the way? Here are some topics that remain wide
open for you to explore. Naturally you should search online if they interest you.
The informal, learning-by-discovery approach that I have used in this book
tends to be light on theory. I’ve avoided most of the math that you’d be expect-
ed to learn in a more rigorous course on the subject. If you have mathematical
aptitude, you can use it to gain a much deeper insight into the way in which
circuits work.
I didn’t deal much with computer architecture, either. We didn’t go very far into
binary code, and you didn’t build a half-adder, which is a great way to learn how
computers function on the most fundamental level. Perhaps you should think
about assembling one.
I avoided going deeply into the fascinating and mysterious properties of
alternating current. Here again, some math is involved, but just the behavior of
current at high frequencies is an interesting topic in itself.
For reasons already stated, I avoided surface-mount components—but you
can still go into this area yourself for a relatively small investment, if you
like the idea of creating fascinatingly tiny devices. This may be the future of
hobby electronics, so if you stick with it, you’ll probably end up in the world of
surface-mount.
Vacuum tubes were not mentioned, because at this point, they are mainly of
historical interest. But there’s something very special and beautiful about tubes,
especially if you can enclose them in fancy cabinetwork. In the hands of a
skilled craftsperson, tube amplifiers and radios become art objects.
I didn’t show you how to etch your own printed circuit boards. This is a task that
appeals to only certain people, and the preparation for it requires you to make
very neat drawings or use computer software for that purpose. If you happen to
have those resources, you might want to do your own etching. It could be a first
step toward mass-producing your own devices.
I didn’t cover static electricity at all. High-voltage sparks don’t have any practi-
cal applications, and they entail some safety issues—but they are stunningly
impressive, and you can easily obtain the necessary information to build the
equipment. Maybe you should try.
316 Chapter 5
In Closing
Other Controllers
If you want something more powerful, a BASIC Stamp is the logical next step
after a PICAXE. the BASIC Stamp is so called because it originally looked like a
postage stamp. The BASIC Stamp has a larger vocabulary of commands and a
bigger range of add-on devices (including displays with graphical capability,
and a little keyboard that is specifically designed for use with the controller).
The BASIC Stamp is shown in Figure 5-149.
On the downside, you’ll find that everything associated with the BASIC Stamp
is a bit more expensive than in the PICAXE world, and the download procedure
isn’t quite as simple.
One of the more recent developments in the world of MCUs is the Arduino,
which is both sophisticated and powerful. It does require programming in Figure 5-149. The BASIC Stamp controller
consists of surface-mounted compo-
the C language. This language is a little more difficult to understand, and has nents on a platform that has pins spaced
only the vaguest similarity to the syntax that is used in the PICAXE and BASIC at 1/10-inch intervals, for insertion in a
Stamp. On the other hand, because C dominates the larger world of comput- breadboard or perforated board. This
ing, learning it might not be such a bad idea—and the Arduino offers some component uses a version of BASIC that
is similar to the programming language of
truly amazing capabilities. Because it is so popular, there are also many soft- the PICAXE, but has many more exten-
ware tools, documentation, user forums, and many enthusatic hobbyists to sions. The BASIC Stamp is available
help you. Two other Make: Books titles that I mentioned previously, Getting for use with a wide range of peripheral
Started with Arduino and Making Things Talk, provide a great introduction. devices, including many alphanumeric
dot-matrix displays.
In Closing
I believe that the purpose of an introductory book is to give you a taste of a
wide range of possibilities, leaving you to decide for yourself what you want to
explore next. Electronics is ideal for those of us who like to do things ourselves,
because almost any application—from robotics, to radio-controlled aircraft, to
telecommunications, to computing hardware—allows opportunities that we
can explore at home, with limited resources.
As you delve deeper into the areas of electronics that interest you most, I trust
you’ll have a satisfying learning experience. But most of all, I hope you have
lots of fun along the way.
319
320 Appendix
Download at WoweBook.com
325
326 Index
74HC32 (see Experiment 21: Race coulomb, 36 electromagnet (see Experiment 25:
to Place) countersink, hand-cranked, 99 Magnetism)
74LS06 open-collector inverter CraftAmerica, 319 Electronics Club, 233
chip, 150 crossover networks, 253–257 electronic solder, 100
74LS27 (see Experiment 23: Nice current electronics-tutorials.ws, 233
Dice) alternating, 248 Elenco, 320
74LS27 triple-input NOR chip, 150 checking flow, 21–25 helping hand, 96
74LS92 counter chip, 150 direct and alternating, 12 The Encyclopedia of Electronic
74LS92 (see Experiment 23: Nice transistors and, 80–81 Circuits, 235
Dice) Essentials
555 timer (see 555 timer chip)
4026, 150
D All about diodes, 134
All about NPN and PNP transistors,
(see also Experiment 18: Reaction Darice, 319 76–77
Timer) Darice Mini-Storage boxes, 230 All about programmable
choosing, 148–149 Davies, Ray, 260 unijunction transistors, 83–84
common part numbers, 193 DC (direct current), 12 Battery life, 123
floating pins, 175 DC power plug, 103 Logic gate basics, 186–189
history, 152 DC stepper motor, 280 Perfboard soldering procedure,
logic chips, 150 DeArmond, Harry, 261 137
power supplies, 154 deburring tool, 99, 271 Real-world fault tracing, 139
programmable chips, origins, 294 decimals, 29 Transistors and relays, 79
Churchill, Sir Winston, 29 Dellepiane, Flavio, 260 Everlight, 320
circuit chips (see chips) desoldering wick, 98 low-power LEDs, 150
The Circuit Designer’s Companion, DeWalt, 320 Experiment 1: Taste the Power!, 5–9
235 DeWalt XRP jigsaw, 271 cleanup and recycling, 9
C&K diesel engine, 236 further investigation, 8
pushbutton, 42 Digi-Key, xi, 320 procedure, 7
switch, 319 patch cords, 41 tools, 5
clip-on meter test leads, 97 diodes, 103, 134 Experiment 2: Let’s Abuse a Battery!,
clipping, 257 capacitors, 241 9–13
CMOS chips, floating pins, 175 schematics, 134 cleanup and recycling, 13
CMOS Sourcebook, 234 direct current, 12 procedure, 9–12
coil schematics, 238 Directed switches, 320 Experiment 3: Your First Circuit,
coil voltage, 58 distortion (see Experiment 30: Fuzz) 13–17
cold-weld, 106 Doctronics, 233, 320 cleanup and recycling, 17
combination lock circuit schematic, Doing the math on your tongue, 30 lighting LEDs, 16–17
198, 201 double-throw switch, 42, 46 setup, 13–15
Common (COM) socket, 5, 6 DPDT relay, 103 Experiment 4: Varying the Voltage,
Complementary metal–oxide Dummer, Geoffrey W. A., 152 18–31
semiconductor (CMOS), checking flow, 21–25
190–192
computers, 232
E cleanup and recycling, 29
dimming LEDs, 19–25
magnets, 240 eBay, xii, 320 manufacturer’s data sheet, 26
conductor, 6 electrical potential, 36 Ohm’s Law, 26
control knobs, 229 electricity potentiometers, 18
controller chips magnetism, relationship, 236 size of resistor required by LED, 28
limitations, 315 nature of, 33 Experiment 5: Let’s Make a Battery,
programmable chips, origins, 294 sound into, 244–245 32–38
(see also Experiment 34: Hardware electrolytic capacitors, 42, 61 cleanup and recycling, 34
Meets Software) electromagnetism, father of, 13 practical purposes, 37
Index 327
Experiment 6: Very Simple Switching, Experiment 15: Intrusion Alarm enhancements, 210
43–54 Revisited, 127–146 goal, 205
connection problems, 45 alarm installation, 145–146 (see also Experiment 36: The Lock,
schematics, 50–54 blocking bad voltage, 132–134 Revisited)
testing, 45–49 breadboard alarm circuit, 135–136 Experiment 22: Flipping and
tools, 44–45 break-to-make transistor circuit, Bouncing, 211–213
Experiment 7: Relay-Driven LEDs, 129–130 how it works, 212–214
55–59 conclusion, 146 Experiment 23: Nice Dice, 214–222
AC adapter plugs, 55–56 final test, 145 binary code, 214–220
how it works, 59 installing switches, 142–143 enhancements, 220–222
operating current, 58 magnetic sensor switches, 128 Experiment 24: Intrusion Alarm
procedure, 59 perfboarding, 136–139 Completed, 223–226
Experiment 8: A Relay Oscillator, self-locking relay, 131–132 delay before deactivation, 225–226
60–67 soldering switches, 143–144 delayed activation, 223
adding capacitance, 61–64 switches and inputs for alarm, keypad deactivation, 223–224
breadboarding circuits, 65–67 140–141 summary, 226
Experiment 9: Time and Capacitors, Experiment 16: Emitting a Pulse, Experiment 25: Magnetism, 236–238
68–72 153–161 procedure, 236
voltage, resistance, and procedure, 153–162 Experiment 26: Tabletop Power
capacitance, 69–72 Experiment 17: Set Your Tone, Generation, 239–241
Experiment 10: Transistor Switching, 162–169 procedure, 239–242
73–81 astable modifications, 166–167 Experiment 27: Loudspeaker
fingertip switching, 74–75 chaining chips, 167–170 Destruction, 242–245
Experiment 11: A Modular Project, procedure, 162–166 procedure, 242
82–93 Experiment 18: Reaction Timer, Experiment 28: Making a Coil React,
amplification, 87–89 170–181 246–248
beyond persistence of vision, counting, 171–174 procedure, 246–248
86–87 delay, 178–179 Experiment 29: Filtering Frequencies,
enhancements, 92–93 display, 170–171 249–256
pulsed output, 90–92 enhancements, 180 adding an amplifier, 250–252
slow-speed oscillation, 85 pulse generation, 175 crossover networks, 253–257
wish list, 93 refinements, 176 procedure, 250
Experiment 12: Joining Two Wires reflex tester, 179 Experiment 30: Fuzz, 257–261
Together, 104–113 summary, 181 schematic, 258
adding insulation, 110–111 Experiment 19: Learning Logic, Experiment 31: One Radio, No
first solder join, 104–107 181–196 Solder, No Power, 262–267
modifying AC adapter, 111 Experiment 20: A Powerful enhancements, 265
second solder join, 108 Combination, 197–204 Experiment 32: A Little Robot Cart,
shortening power cords, 111–113 breadboarding, 200–201 268–284
Experiment 13: Broil an LED, 114–116 computer interface, 202–203 bending, 272–273
heat-sinking, 115 enhancements, 203 circuit, 276–281
Experiment 14: A Pulsing Glow, incorrect inputs, 200 curving cuts, 271
117–126 questions, 200 framing your cart, 274–276
finishing, 121–126 schematic, 198–199 making 90 degree joints, 273–274
procedure for building this circuit, Experiment 21: Race to Place, making plans, 272
120 205–210 mechanical power, 281–284
resizing the circuit, 119–120 breadboarding, 209–210
conceptual experiment, 205–209
328 Index
Index 329
insulated binding posts, 103 lemon battery, 32–38 McMaster-Carr, xii, 230, 320
insulator, 6 lightbulb, 53 deburring tool, 99
integrated circuit chips (see chips) light-emitting diodes (see LEDs) hand-cranked countersink, 99
intrusion alarm (see Experiments 11, lightning, 35 hookup wire, 41
15, and 24) limit switches, 278 soldering iron, 96
lithium batteries, 9, 30 MCUs
J LM7805 voltage regulator (see
Experiment 19: Learning
limitations, 315
programmable chips, origins, 294
jacks, 49 Logic) (see Experiment 34: Hardware
Jameco, 320 logic chips, 150 Meets Software)
potentiometer, 42 logic gates measurements, 36
solder, 100 basics, 186–189 conversion table, 124–126
joules, 36 origins, 192 in inches, 124
jumper wire assortment, 41 rules for connecting, 194–195 Megahobby, 320
(see also Experiments 19-24) miniature vise, 99
K loudspeakers, 43, 104
amplification, 87
Meter Superstore, 97, 320
metric system, 124
Kellogg, Edward, 243 mounting, 87 Michaels craft stores, 229, 320
keypads origins, 243 microcontrollers, 227
(see Experiment 20: A Powerful sound into electricity, 244–245 PICAXE (see PICAXE)
Combination) (see also Experiments 17, 27, and microfarads, 61
Kilby, Jack, 152 29) Mill-Max, 320
Kingbright, 320 Lowe’s hardware, xii, 320 single inline sockets and headers,
Kinks, 260 plywood, 102 103
K&J Magnetics, 320 wire, 101 miniature hand saw, 99
Kobiconn, 320 Lumex, 320 miniature screwdriver set, 98
clip-on meter test leads, 97 diodes, 103 miniature vise, 99
Kronus Automatic Wire Strippers, 40 Mitutoyo, 320
KVM Tools, 320
deburring tool, 99
M calipers, 100
Motorola, 320
machine screws, 102 transistor, 42
L magnetic sensor switches, 128
magnetism and electricity,
motors, 227, 280
stepper (see Experiment 33:
labeling, 231 relationship, 236 Moving in Steps)
Lancaster, Don, 233 magnetism generating electricity Mouser Electronics, xi, 320
latching relays, 151 (see Experiment 26: Tabletop battery holders and connectors, 3
leads, 5 Power Generation) potentiometers, 4
LED numeric displays, 150 magnets moving-coil microphone, 244
LEDs, 4 warnings, 240 Mueller alligator clips, 101, 320
dimming, 19–25 (see also Experiments 25 and 26) multimeter, 2
lighting, 16–17 magnifying lens, 96 mutual repulsion, 33
low-powered, 150 mail-order sources, xi
pulsing (see Experiment 14: A
Pulsing Glow)
Make: Electronic kits, xiii
Maker Shed, xiii
N
relay-driven (see Experiment 7: Making Things Talk, 234 NAND gates (see Experiments 19-24)
Relay-Driven LEDs) manufacturer’s data sheet, 26 nanofarads, 61
schematics, 53, 54 Marconi, Guglielmo, 266 negative charge, 35
size of resistor required, 28 neodymium magnet, 240
too much heat (see Experiment 13: Newark, xii, 320
Broil an LED)
330 Index
Index 331
332 Index
T basics, 77
beta value, 80
voltage regulators, 151, 182
LM7805 (see Experiment 19:
tactile switches, 151 break-to-make transistor circuit, Learning Logic)
tamper-proof screws, 203 129–130 volts, 36
tantalum capacitor, 63 getting a better understanding, basics, 11
Texas Instruments, 321 80–81 Vox wow-fuzz pedal, 257
4026 Decade Counter, 150 NPN and PNP, 76–77
logic chips, 150 origins, 78
relays and, 79
W
Theory
Alternating current concepts, 248 switching (see Experiment 10: Wal-Mart, 229, 321
Basic measurements, 36 Transistor Switching) Warnings
Binary arithmetic, 217 unijunction, 82–84 Avoid Burns While Bending, 272
Calculating voltage drop, 283–284 Transistor-Transistor Logic (TTL), Beware of Pin-Shuffling!, 161
Doing the math on your tongue, 30 190–192 Blood Blisters and Dead Media, 240
How radio works, 266–267 tremolo box, 261 Capacitor Polarity, 63
Inductance, 237 Trem-Trol, 261 Cut with Care, 270
Inside a stepper motor, 288–289 trigger voltage, 156 Flying Wire Segments, 121
Inside the 555 timer: astable mode, TTL Cookbook, 234 Getting Zapped by Capacitors, 62
164–165 tweeter, 253 Grounding Yourself, 172
Inside the 555 timer: monostable Twin Industries, 321 Heat Guns Get Hot, Too!, 110, 111
mode, 158–159 perforated board, 101 High Voltage!, 263
Power assessments, 31 Tyco, 321 Hot Resistors, 247
See the current, 80–81 relays, 42 Never Use Two Hands, 74
Soldering theory, 109 No Floating Pins!, 175
Sound, electricity, and sound, U No More Than 9 Volts, 5
Pin 2 Pull-Down, 299
244–245
The nature of electricity, 33 unijunction transistors, 82–84 Short Circuits, 9
The time constant, 71–72 Soldering Irons Get Hot!, 104
Waveforms, 255–256 V The Warranty Issue, 197
water-powered turbine, 236
third hand, 96
Thomson, J. J., 35 Vaughan, 321 wattage, history, 28
time constant, 71–72 Vectorboard, 101 Watt, James, 28
toggle switches, 42, 229 Velleman keyboards, 321 watts, 36
options for toggle switches and Ventures, 260 basics, 31
pushbuttons, 47 VIH min, 192 waveforms, 255–256
Tools VIL max, 192 clipping, 257
Desoldering, 109 vise, miniature, 99 wavelength of the sound, 244
Eight most common soldering Vishay, 321 Weller, 321
errors, 107 VOH min, 192 Weller Therma-Boost, 96
Four most common perfboarding VOL max, 192 windmill, 236
errors, 138 Volta, Alessandro, 12 wire cutters, 2
torque, 281 voltage, 10 warning, 121
Tower Hobbies, 321 blocking bad voltage, 132–134 wire gauges, 282
miniature hand saw, 99 calculating drop, 283–284 wires, 100
tracing a fault, 139 high, 263 point-to-point wiring connections,
transistors, 42 how much wire consumes, 27 106
2N2222 (see Experiments 11 and 15) measuring, 6 schematics, 52
2N6027 programmable unijunction soldering (see also Experiment 12:
transistor (see Experiment 14: Joining Two Wires Together)
A Pulsing Glow) voltage consumed by, 27
Index 333
wire strippers, 40
wire wrap, 106
X Z
woofer, 253 X-Acto, 321 Zener diode, 134
work area, customizing, 228–232 miniature hand saw, 99 zinc electrode, 33
bench, 231 Xcelite, 321
computer, 232 pliers, 1
labeling, 231 Xytronic, 321
oscilloscope, 231 soldering iron, 96
334 Index
Colophon
The heading and cover font are BentonSans, the text font is Myriad Pro, and
the code font is TheSansMonoCondensed.