Sunday, January 27, 2008

Electronics shopping list, part II: Components

In part I I discussed the tools that one starting to play around with electronics should pick up - well, mostly I pointed out already existing lists of equipment, but who's counting. In this article I want to talk about the fun stuff: components.

One thing I wanted to get right off the bat was a big pile of parts, both so that I'd have a variety of things to play around with, and so that I wouldn't be missing any common parts when I needed to build something. I knew what various components did - resistors, capacitors, diodes, transistors - I just had no idea what values and types I would need and what I wouldn't. I was surprised at how little information I found on the subject, and that there didn't seem to be any good "starter packs" available (more on that later). I put together a list from this thread on the Arduino forums, along with Tom Igoe's books (Physical Computing and Making Things Talk, and a few other sources. Read on to see what I found.



A few preliminaries: I'm not going to go into too much explanation of how to use these components. That's best left for other articles, and besides, there's plenty of information out there (I highly recommend Lessons in Electric Circuits, a six volume set available free online in HTML or PDF format). I will, however, try to give enough information to understand what you're getting and why, and to link to relevant background information.

The values here assume you're working with microcontroller-level voltages (3.3V, 5V, and maybe occasionally 12V) and currents (less than 1A).

The list
This post ended up being much longer than I had anticipated, so here is a summary list of parts I recommend to start out with. For details, read on.

Generally I'm pointing out the cheapest options. Suggested quantities are in brackets. A few items are in italics, because they're less important. If anyone has any comments - good places to buy these things, alternatives, additions - please leave a comment at the bottom.

Resistors:
  • 1/4 W ceramic (get hundreds) - 22 Ohms, 47 Ohms, 100 Ohms, 220 Ohms, 470 Ohms, 1kOhms, 4.7kOhms, 10kOhms, 22kOhms, 100kOhms, and 1MOhms. (Other values if needed for specific projects)

Capacitors:
  • 50V ceramic (get dozens) - 22pF, 47pF, 100pF (0.1nF), and 100nF (0.1uF)
  • 50V radial electrolytic (get dozens) - 1uF, 10uF, and 100uF

Diodes:
  • General purpose (get dozens) - 1N4001, 1N4004 (1N400x will all probably be fine)
  • Switching (get dozens) - 1N4148 or 1N914
  • Zener (get 10-20) - 3.3V (I got 1N5226, but plenty of others will do), other voltages if you know you'll be dealing with them
  • LEDs (get at least two dozen) - cheap red ones (and any others you might like)

Transistors:
  • General Purpose (get dozens) - 2N2222 (or PN2222, which is cheaper), 2N2907 (or PN2907)
  • Power (a dozen, unless you plan on controlling high-voltage devices like motors; then use more) - TIP120

Integrated circuits:
Be sure to get a DIP package (or anything ending in DIP, like PDIP) unless you want to do surface-mount soldering (if you're reading this, you probably don't). There are so many ICs, with so many functions, that it's impossible to make a good list. Any 74HC or 74LS are good to start, as are CD4xxx series, so find some that sound like fun. I recommend counters, multiplexers, BCD-to-seven segment decoders, and (slightly more advanced) shift registers as a good way to start to learn (get a couple each of several different types to play around with).

Power supply (quantities depend on how many power-supply circuits you'll build):
Again, be sure not to get surface mount packages; TO-220, TO-92, and TO-3 should all be safe
  • Fixed - LM7805 5V 1A positive regulator (other voltages are LM78xx where xx is the voltage, if you know you need them); LM1084 3.3V 5A positive regulator
  • Adjustable - LM317
  • Breadboard power supply kit - not a necessity, but very convenient, plus a good way to practice your soldering
General advice on picking parts
Datasheets are scary at first; at least, they were to me. The best way to get over that is to read them, over and over again, and lots of them. There's a lot of information in them that you don't really need to worry about, so learn to pick out what's important. The main things you want to check are that the component you're looking at can handle the voltage, current, and power that you're going to be subjecting it to, so look for those numbers. If you don't know how to figure those out, then stop here and go read up on and power. You might want to check out Lessons in Electric Circuits, which is a fantastic free textbook to make sure you understand a little bit of the theory before you starting putting down cash.

Package deals
I looked around for package deals that included a wide variety of parts. Almost all that I encountered had two distinct problems: they included a lot of things that aren't really necessary (and not enough of things that are), and they are grossly overpriced. For example, Digi-key offers a kit with 365 resistors - 5 each of 73 different values - for $14.95. First of all, 5 of a given value really isn't enough; what if you have 8 LEDs that you want the same brightness? That aside, for $14.95, you should be able to buy at least 1495 resistors. You'd be much better off buying 100 each of 10 different values for $10 than getting that kit for $15.

While writing this entry I discovered Futurlec, an online store that seems to have very competitive prices. They offer several different value packs of different components, generally 100 pieces of various values, which appear to be a very good deal price-wise. The trade-off is that the values you get are unknown, and for that reason I wouldn't recommend making them the basis of your kit to begin with. I recommend stocking up on some key values, and then perhaps using these "mystery" packages to randomly fill in some gaps. In fact, I just placed an order for several of them in order to do just that.

Resistors
Resistors are essential for controlling how much current is flowing through a circuit, and as such you'll use them all the time. Fortunately, they are dirt cheap. The type you'll probably want as a beginner hobbyist are 1/4 Watt ceramic film (not ceramic composition, those are much more expensive). I was in Toronto over the holidays, where there are several good electronics stores, all of which sell resistors for a penny each, even in small quantities (I picked up about 1,500 of various values, 100-200 of each, so I won't have to worry about resistors for a long time). This is a rare occasion when brick-and-mortar stores seem to do better than online, unless you're buying in the thousands. The only online store I've seen with comparable prices for small quantities is Futurelec, whose resistor page is here. If you're buying in larger quantities, look around and see how well you can do.

All of the sources I found recommended resistor values of different orders of magnitude starting with 1.0, 2.2, and 4.7; I went with it and haven't had a problem yet. I got 100-200 each of 22, 47, 100, 220, 470, 1k, 4.7k, 10k, 22k, 100k, and 1M. The lowest order of magnitude is for limiting current in low-voltage situations (ie LEDs with high voltage drops), the mid range for most current limiting situations (normal LED series resistors, pin protection), and the high end for pull-up and pull-down resistors. The high end I've used the least, by far. Of course, other values come in handy, but these should do pretty well; remember that you can put resistors in series or parallel to get other values, too.

Capacitors
Capacitors are like tiny temporary batteries: they store energy up and then release it. The unit of capacitance is the farad (F), but one farad is pretty huge, so what you'll normally encounter are micro-, nano-, and picofarad ratings.

The most common use when dealing with microcontrollers seems to be to "de-noise" power lines; the idea is that the capacitor stores a little bit of charge, so if there are fluctuations from the power source, it can release or store charge to compensate for them. These are called bypass or decoupling capacitors, and some sources recommend using them constantly. I don't, and haven't encountered any problems yet, but it's something to think about when building your circuits.

There are many types of capacitors, but the only I've used so far are the cheapest and most common: ceramic (usually smaller values) and electrolytic (larger values). Generally speaking ceramic are non-polar (doesn't matter which way you put them in the circuit), while electrolytic are polar (there are positive and negative ends, so you need to be careful which way you put them in the circuit). Make sure the capacitors are rated for a voltage significantly higher than what you plan on using them in, just to be safe.

I picked up a wide range of values, but I've hardly had to use them at all. They're cheap (4 to 20 cents each), though, and a lot of circuits suggest them, so I'm glad to have them around. I have 22pF, 47pF, 100pF (0.1nF) and 100nF (0.1uF) ceramic capacitors, and 1uF, 10uF, and 100uF electrolytic capacitors. As in resistors, values starting with 2.2 and 4.7 seem to be popular; 22pF in particular crops up a lot, but I couldn't tell you what's special about that particular value.

Diodes (rectifiers)
Here's where things started getting a little trickier for me. Resistors and capacitors I had played with a lot in high school shop and physics class; I had played with them, knew equations that used them, and at least vaguely understood what the ratings and numbers meant. Diodes (also sometimes called rectifiers) were more of a mystery. I knew that they forced current to travel in only one direction, but I didn't have a good sense of when you need to use them, and what the various ratings in the datasheet meant. For that, I highly recommend Volume 3, Chapter 3 of the aforementioned Lessons in Electronic Circuits, particularly the section on diode ratings.

Many of the uses for diodes involve AC current, which I haven't dealt with at all and won't talk about. Briefly, some of the DC-related uses for diodes you might encounter are: as a snubber (also called a flyback diode), to protect circuits from stray current flow; for switching matrices, to prevent ghosting and masking (scroll down to section 8 on the linked page); and, using a Zener diode, to regulate a voltage drop.

There are a whole range of different types of diodes ideally suited to various applications. Fortunately, there are cheap general purpose diodes available which will work well enough for many applications you'll encounter. The most prevalent seem to be the 1N400x series, usually 1N4001 and 1N4004. These are all the same save for the amount of voltage they can handle in the reverse direction, which goes up the higher the last digit of the part number is: the 1N4001 is rated at 50V and the 1N4004 at 400V (check out the datasheet for full details, it's the first line of the table). Other than using a very high voltage source, I don't really know why you'd need anything other than a 1N4001; they're all very cheap, so I picked up a few each of 1N4001 and 1N4004. If anyone can explain why you wouldn't want to just use a 1N4007 in everything, please post it in the comments!

You might also want some high-speed or switching diodes, part numbers 1N4148 or 1N914. These are able to switch between passing current and blocking current very quickly (on the order of nanoseconds), so are useful in high-frequency applications. That said, you'll probably rarely need that sort of speed, at least at first. Still, in any sort of time-sensitive application (like the matrix switching above), it can't hurt!

Zener diodes are still a little mysterious to me, but the general idea (gleaned from the relevant section in Lessons in Electric Circuits) is that they can take a higher voltage and only allow a certain amount through, giving a regulated voltage source. I have some 3.3V Zener diodes (part 1N5226), but you can get them in a wide range of voltages. You might want to pick up other values, depending on what voltages and power supplies you're dealing with.

Of course, the most fun diodes are LEDs, a staple of so many electronics hobbyist projects. LEDs don't seem to have standardize part numbers, and come in myriad shapes, sizes, and colours. The standard size is 5mm cylindrical or T1-3/4. Slightly smaller are 3mm or T1. The cheapest is almost always red, and the most expensive are blue and white. Other colours fall in between. Multi-colour LEDs, which are really just several LEDs in one package, are also available; tri-colour or RGB LEDs are a lot of fun, because you can mix colours to get essentially anything you want. You can get LEDs as cheap as 3 or 4 cents, all the way up to multiple dollars on the high side of things. The expensive ones are much, much brighter, with much nicer colours. Stock up on some of the cheapest ones you can find, because they're good for testing, and buy more expensive ones if you want, because they're much nicer looking. SuperBrightLEDs.com is expensive, but their products are high quality. Seven-segment displays are fun to play with, too, especially in conjunction with certain integrated circuits, but I was surprised at the price (usually around a dollar or two, which is relative expensive compared to most parts on this list).

Transistors
Transistors are the essential building block of microchips, they are the subject of Moore's Law, and so, as a lifelong geek, it was pretty thrilling for me to play with transistors for the first time. A transistor is basically an electrically controlled switch: in it's simplest form it has three pins. When you apply current to one of these pins, it allows current to flow across the other two pins. This allows your microcontroller to control all sorts of other electronic devices. A transistor can also be thought of as an amplifier, because by applying a very small current to one pin, it allows a much higher current (typically 100x higher or more) to flow across the others. The amount of amplification of a transistor is called its DC current gain, and is given by the symbol hFE. It is also sometimes called the transistor's beta value.

There are far too many types of transistors for me to explain them here (even if I knew enough to do so, which I don't). Suffice it to say that you're going to want to get a whole bunch of 2N2222 transistors (or their cheaper equivalents, PN2222, which come in a plastic case), which is a great general-purpose part. There's also 2N2222A, which is very similar but a little more expensive; as far as I can tell, it's simply because all the characteristics are slightly better, but there might be more to it (if you know, please let me know in the comments!). These are NPN bipolar junction transistors, which basically means that they turn on when given a little bit of current. They have a complementary PNP transistor, part number 2N3904, which turns off when given a little bit of current. These are less commonly used.

The other type of transistor I recommend is a Darlington transistor (also called a Darlington pair). All this is is one NPN transistor driving a second one, such that the hFE value multiply and end up much higher. They are used to switch very high currents, and the most common used part is the TIP120.

Intergrated circuits
Integrated circuits are basically an entire circuit reduced to a tiny chip. You can get ICs to do just about anything, and, if you want to do projects of any complexity, you're going to want to use them sooner or later (well, technically, if you're using any sort of microcontroller, you already are using one). To even scratch the surface would require a dedicated article (which I will perhaps write one day, but not today).

The idea of figuring out how to use an IC intimidated me more than anything else when I was getting started. I had made a project with a 555 timer in a high school class, but that had just been following a schematic; it had never really been explained. Datasheets are awfully daunting at first. Still, I bought a few that sounded interesting, read the datasheets over and over again until they started making sense, found some tutorials online using those chips, and built up my confidence. It didn't take much experimentation before I felt comfortable with ICs, and I think that's probably the best way to do it: look at the list of 74 series chips or the one for the 4000 series, find some that sound interesting, and then pick a couple up and see what you can do. I really liked the 74HC595 because there's a nice tutorial for it on the Arduino site. I also liked the 4511, which takes a binary number and outputs it to give the corresponding number on a seven-segment display. Other things that can be fun are counters and multiplexers; look around and see what you find interesting! They're cheap, so get a bunch! (Incidentally, even though the 555 timer chip I mentioned above is everywhere, it's much less useful when you've got a microcontroller keeping time for you; still, it's good to play with and understand if you want to learn to make circuits without a microcontroller.)

Be careful when buying chips that you get them in a through-hole package, which will generally be labelled as DIP or PDIP (dual inline package and plastic dual inline package, respectively), usually followed by a number indicating how many pins it has. Other packages, like SOIC or anything ending in SOP (like TSOP) are surface-mount parts, which, if you're reading this, you probably don't want. Here's an article on many of the different packages available, but the general rule of thumb is, if it doesn't end in DIP, then it's probably going to be surface mount.

Power Supply
This is going to end the article on a bit of an anticlimactic note (especially since these are technically ICs, too). Voltage regulators are, surprisingly enough, devices which regulate voltage. That is to say, they generally take a voltage as input, and output a lower voltage at a constant rate. The DC converters you plug in to a wall don't give very reliable voltage levels, and batteries change their output voltage over their lifetime, so you stick a regulator in between your power source and your circuit so you know what you're getting. If you're using the Arduino, or most other startup packages, it's already got one built in.

The simplest type, and the one that's on the Arduino, is a linear regulator. Another type that is a bit more versatile and efficient but has somewhat noisier output is a switching regulator. I bought a few 5V regulators, LM7805, and some adjustable regulators, LM317, in case I wanted to build any standalone projects with their own power supplies. I haven't used them yet, so I can't say much more, but I'm glad they around in case I do. You can find them for all sorts of voltages for whatever level your project might need.

One thing I got that I highly recommend is Sparkfun's breadboard power supply. This uses the adjustable LM317 linear regulator to provide a 3.3V or 5V supply to a breadboard. It's very useful - before I had it, I was using my Arduino to provide power even for projects that didn't use the microcontroller; it's good soldering practice; and studying the circuit will help you understand how power supplies work. You could build one yourself, but you wouldn't get the nice compact PCB. I think it's worth the $10.

Where to buy
Not too much to say here that hasn't been said elsewhere. There are the big distributors, like Digi-Key, Jameco, Newark, and my favourite of the group, Mouser. They have just about everything, but often have a minimum order ($25, usually). Some things are only available in large quantities, or else aren't priced well for small quantities. There are some stores which seem more oriented towards hobbyists rather than manufacturers, like Electronix Express and Futurlec. Futurlec in particular seems to have the best prices for small quantities, but becomes less competitive with the big stores if you're buying large quantities. Shipping from them also appears to be slower than from the other places. There's also always the dreaded option of Radio Shack. They are admittedly terrible, but their stores have a surprising supply of common components. By no means get everything there, but if you realize you're missing something, and you either don't want to wait for shipping, or don't want to pay $5-$7 shipping for $0.50 of parts, you might be able to get it there for, say $2 instead. They also seem to have some of the best prices around on prototyping boards (basically a circuit board with a layout similar to a breadboard, for making permanent circuits without etching a PCB).

In conclusion
Wow! That ended up being a lot longer than I expected! I hope that this is valuable to someone out there faced with the same issues I had when I was starting: wanting to get some parts, but having no idea what I should get and why. It is by no means exhaustive - I didn't even touch on things like switches (no pun intended) or potentiometers, mainly because, for playing around, more or less anything will do. No motors or servos, either, because I haven't done anything with them yet. Perhaps in a later blog post.

If you have any additions, comments, questions, please feel free to post them below!

3 comments:

Anonymous said...

Hi,

This is a really nice overview for getting started, well done.

I'm trying to document electronics things as I learn them myself, you might want to check out my list of electronics links.

Another option for gaining components and learning how things work is by scavenging them from old electronics, or the wonderful world of component sampling.

(Oddly enough, old thermal fax machines are ideal for scavenging: no-one wants them and they often have LCDs, stepper motors in addition to other interesting parts.)

All in all, it's really great to see another beginner document things as they learn, as I think it will prove valuable in helping others to learn. Thanks. :-)

--Phil.

JMG said...

Thanks for the kind words, Phil. I'm particularly happy, because I've been reading your site quite a bit - particularly the parts on trying to get Kicad to work on OS X. (Incidentally, I compiled it with the latest release of it an wxMac, and it runs, but with enough annoying visual bugs that it's essentially unusable. If your efforts produce a usable binary, I'd love to get my hands on it!)

Josh Kopel said...

Wow!
Great post, and a really nice guide.

I second the idea of scavenging components. I really like the idea of coming up with a way to re-use the stuff that I find on the curb during trash day. It pains me to see it just end up polluting some landfill somewhere. Ink jet printers have great parts for building small kinetic projects, and they usually have a few very useful switches and sensors.

I also very much enjoy shopping for parts surplus. It makes a much better sport then clicking to the right page on digikey and hitting "add to cart". Besides I always discover something I never knew about when surfing around on the surplus sites. I am in the midst of putting all my surplus bookmarks online here http://thehacktory.org/electronics_resources.

jak