Category Archives: 兴趣小组

(中文) PIR传感器相关知识

How PIRs Work

PIR sensors are more complicated than many of the other sensors explained in these tutorials (like photocells, FSRs and tilt switches) because there are multiple variables that affect the sensors input and output. To begin explaining how a basic sensor works, we’ll use this rather nice diagram

The PIR sensor itself has two slots in it, each slot is made of a special material that is sensitive to IR. The lens used here is not really doing much and so we see that the two slots can ‘see’ out past some distance (basically the sensitivity of the sensor). When the sensor is idle, both slots detect the same amount of IR, the ambient amount radiated from the room or walls or outdoors. When a warm body like a human or animal passes by, it first intercepts one half of the PIR sensor, which causes a positive differential change between the two halves. When the warm body leaves the sensing area, the reverse happens, whereby the sensor generates a negative differential change. These change pulses are what is detected.

The PIR Sensor

The IR sensor itself is housed in a hermetically sealed metal can to improve noise/temperature/humidity immunity. There is a window made of IR-transmissive material (typically coated silicon since that is very easy to come by) that protects the sensing element. Behind the window are the two balanced sensors.

Image from RE200B datasheet

You can see above the diagram showing the element window, the two pieces of sensing material

Image from RE200B datasheet

This image shows the internal schematic. There is actually a JFET inside (a type of transistor) which is very low-noise and buffers the extremely high impedence of the sensors into something a low-cost chip (like the BIS0001) can sense.

Lenses

PIR sensors are rather generic and for the most part vary only in price and sensitivity. Most of the real magic happens with the optics. This is a pretty good idea for manufacturing: the PIR sensor and circuitry is fixed and costs a few dollars. The lens costs only a few cents and can change the breadth, range, sensing pattern, very easily.In the diagram up top, the lens is just a piece of plastic, but that means that the detection area is just two rectangles. Usually we’d like to have a detection area that is much larger. To do that, we use a simple lens such as those found in a camera: they condenses a large area (such as a landscape) into a small one (on film or a CCD sensor). For reasons that will be apparent soon, we would like to make the PIR lenses small and thin and moldable from cheap plastic, even though it may add distortion. For this reason the sensors are actually Fresnel lenses:

Image from Sensors Magazine

The Fresnel lens condenses light, providing a larger range of IR to the sensor.

Image from Cypress appnote 2105

OK, so now we have a much larger range. However, remember that we actually have two sensors, and more importantly we dont want two really big sensing-area rectangles, but rather a scattering of multiple small areas. So what we do is split up the lens into multiple section, each section of which is a fresnel lens.

Here you can see the multiple facet-sections

This macro shot shows the different Frenel lenses in each facet!

The different faceting and sub-lenses create a range of detection areas, interleaved with each other. Thats why the lens centers in the facets above are ‘inconsistant’ – every other one points to a different half of the PIR sensing element

Connecting to a PIR

Most PIR modules have a 3-pin connection at the side or bottom. The pinout may vary between modules so triple-check the pinout! It’s often silkscreened on right next to the connection (at least, ours is!) One pin will be ground, another will be signal and the final one will be power. Power is usually 3-5VDC input but may be as high as 12V. Sometimes larger modules don’t have direct output and instead just operate a relay in which case there is ground, power and the two switch connections.

The output of some relays may be ‘open collector’ – that means it requires a pullup resistor. If you’re not getting a variable output be sure to try attaching a 10K pullup between the signal and power pins.

An easy way of prototyping with PIR sensors is to connect it to a breadboard since the connection port is 0.1″ spacing. Some PIRs come with header on them already, the one’s from adafruit have a straight 3-pin header on them for connecting a cable

For our PIR’s the red cable is + voltage power, black cable is – ground power and yellow is the signal out. Just make sure you plug the cable in as shown above! If you get it backwards you won’t damage the PIR but it won’t work.

Testing a PIR

Now when the PIR detects motion, the output pin will go “high” to 3.3V and light up the LED!

Once you have the breadboard wired up, insert batteries and wait 30-60 seconds for the PIR to ‘stabilize’. During that time the LED may blink a little. Wait until the LED is off and then move around in front of it, waving a hand, etc, to see the LED light up!

Retriggering

There’s a couple options you may have with your PIR. First up we’ll explore the ‘Retriggering’ option.

Once you have the LED blinking, look on the back of the PIR sensor and make sure that the jumper is placed in the L position as shown below.

Now set up the testing board again. You may notice that when connecting up the PIR sensor as above, the LED does not stay on when moving in front of it but actually turns on and off every second or so. That is called “non-retriggering”.
Now change the jumper so that it is in the H position. If you set up the test, you will notice that now the LED does stay on the entire time that something is moving. That is called “retriggering”.

(The graphs above are from the BISS0001 datasheet, they kinda suck)

For most applications, “retriggering” (jumper in H position as shown below) mode is a little nicer.

If you need to connect the sensor to something edge-triggered, you’ll want to set it to “non-retriggering” (jumper in L position).

Changing sensitivity

The Adafruit PIR has a trimpot on the back for adjusting sensitivity. You can adjust this if your PIR is too sensitive or not sensitive enough – clockwise makes it more sensitive.

Changing Pulse Time and Timeout Length

There are two ‘timeouts’ associated with the PIR sensor. One is the “Tx” timeout: how long the LED is lit after it detects movement – this is easy to adjust on Adafruit PIR’s because there’s a potentiometer.

The second is the “Ti” timeout which is how long the LED is guaranteed to be off when there is no movement. This one is not easily changed but if you’re handy with a soldering iron it is within reason.First, lets take a look at the BISS datasheet again

On Adafruit PIR sensors, there’s a little trim potentiometer labeled TIME. This is a 1 Megaohm adjustable resistor which is added to a 10K series resistor. And C6 is 0.01uF so

Tx = 24576 x (10K + Rtime) x 0.01uF

If the Rtime potentiometer is turned all the way down counter-clockwise (to 0 ohms) then

Tx = 24576 x (10K) x 0.01uF = 2.5 seconds (approx)

If the Rtime potentiometer is turned all the way up clockwise to 1 Megaohm then

Tx = 24576 x (1010K) x 0.01uF = 250 seconds (approx)

If RTime is in the middle, that’d be about 120 seconds (two minutes) so you can tweak it as necessary. For example if you want motion from someone to turn on a fan for a minimum of 1 minute, set the Rtime potentiometer to about 1/4 the way around.

For older/other PIR sensors

If you have a PIR sensor from somewhere else that does not have a potentiometer adjust, you can trace out the adjustment resistors this way:

Determining R10 and R9 isnt too tough. Unfortunately this PIR sensor is mislabeled (it looks like they swapped R9 R17). You can trace the pins by looking at the BISS001 datasheet and figuring out what pins they are – R10 connects to pin 3 and R9 connects to pin 7. the capacitors are a little tougher to determine, but you can ‘reverse engineer’ them from timing the sensor and solving!

For example:

Tx is = 24576 * R10 * C6 = ~1.2 seconds
R10 = 4.7K and C6 = 10nF

Likewise,

Ti = 24 * R9 * C7 = ~1.2 seconds
R9 = 470K and C7 = 0.1uF

Using a PIR

Reading PIR Sensors

Connecting PIR sensors to a microcontroller is really simple. The PIR acts as a digital output so all you need to do is listen for the pin to flip high (detected) or low (not detected).Its likely that you’ll want reriggering, so be sure to put the jumper in the H position!

Power the PIR with 5V and connect ground to ground. Then connect the output to a digital pin. In this example we’ll use pin 2.

The code is very simple, and is basically just keeps track of whether the input to pin 2 is high or low. It also tracks the state of the pin, so that it prints out a message when motion has started and stopped.
  1. /*
  2. * PIR sensor tester
  3. */
  4. int ledPin = 13; // choose the pin for the LED
  5. int inputPin = 2; // choose the input pin (for PIR sensor)
  6. int pirState = LOW; // we start, assuming no motion detected
  7. int val = 0; // variable for reading the pin status
  8. void setup() {
  9. pinMode(ledPin, OUTPUT); // declare LED as output
  10. pinMode(inputPin, INPUT); // declare sensor as input
  11. Serial.begin(9600);
  12. }
  13. void loop(){
  14. val = digitalRead(inputPin); // read input value
  15. if (val == HIGH) { // check if the input is HIGH
  16. digitalWrite(ledPin, HIGH); // turn LED ON
  17. if (pirState == LOW) {
  18. // we have just turned on
  19. Serial.println(“Motion detected!”);
  20. // We only want to print on the output change, not state
  21. pirState = HIGH;
  22. }
  23. } else {
  24. digitalWrite(ledPin, LOW); // turn LED OFF
  25. if (pirState == HIGH){
  26. // we have just turned of
  27. Serial.println(“Motion ended!”);
  28. // We only want to print on the output change, not state
  29. pirState = LOW;
  30. }
  31. }
  32. }
Don’t forget that there are some times when you don’t need a microcontroller. A PIR sensor can be connected to a relay (perhaps with a transistor buffer) without a micro!

Make Your Own Fritzing Parts 

What is Fritzing?

Fritzing Logo

Fritzing is a great open source tool for anyone to teach, share, and prototype their electronic projects! It allows you to design a schematic, and thus a part, which can then be added to very professional-looking wiring diagrams. You can even design your own PCBs and have them fabricated from the files you design. Here at SparkFun, we use Fritzing in the classrooms, our hook-up guides, and any other place we need to show how to hook-up our boards to other hardware.

Fritzing Hookup Example

Fritzing example of the INA169 connected to an Arduino

The awesome thing about Fritzing is that you can make your own Fritzing parts for your project and share with the community! This tutorial is going to go over how to make a custom Fritzing part in the Fritzing (New) Parts Editor, starting from the beginning.

Do You Need to Make a Custom Fritzing Part?

Fritzing comes with tons of electronic parts already installed with the software. SparkFun also has a Fritzing Github repofor housing parts we’ve created not already in Fritzing. Before creating your own part, double check to see if it exists in those two locations or if another Fritzing user already made the part you need on the Fritzing forum. It will save you a lot of time if the part is already made! However, if you’re certain that the part you need doesn’t live in Fritzing land already, read on!

Suggested Reading

This tutorial assumes that you are already familiar with Adobe Illustrator, Inscape, or both. Using these programs is beyond the scope of this tutorial. If you need more info on how to use eithwer of these programs, their respective websites should have lots of tutorials and guides on how to get started with vector graphics. If that fails, there’s always Google.

Here are other related tutorials you may want to check out before reading this one:

Download and Install

You will need to download and install the following software in order to follow along and make your own custom Fritzing part.

Please Note: If you only need to make a basic IC, Fritzing (New) Parts Editor allows you to make custom ICs easily, and you won’t need to download a vector graphic editor. You can still follow along, since this tutorial will be building off a custom IC in the Fritzing (New) Parts Editor.

Fritzing

Go to the download page on the Fritzing site to download the latest Fritzing version for your OS. Find where you want to put the Fritzing application on your hard drive, and unzip the Fritzing folder in that location.

Vector Graphics Editor

There is a lot of different types of vector graphics editors out there. The vector graphics editors we use here at SparkFun are Adobe Illustrator and Inkscape. Choose the one you are the most familiar and comfortable with. If you don’t have a vector graphics editor, Inkscape is a great open source choice, and it is free.

Inkscape

Inkscape Logo

Go to the Inkscape download page and download the appropriate Official Release Package for your computer.

Windows Users: Double click on the executable. Follow along the Inkscape Setup Wizard.

Mac OS X Users: Follow along the newest instructions on the Inkscape site.

Adobe Illustrator

Adobe Illustrator Logo

Adobe Illustrator is not free, but if you already have the Adobe Creative Cloud you can download it. You can also purchase an Illustrator monthly membership.

Please Note: We have no affiliation with Adobe and are only promoting Illustrator because it is a great piece of software that works well for what we need in this tutorial.

Other Downloads

Fritzing Fonts and Templates

Fritzing uses the OCR-A font for ICs. For all the other parts you can use OCR-A and Droid Sans fonts. Fritzing has fonts and templates available for download on their site. You will need to download Fritzing’s Graphic Standards to follow this tutorial. Go to their template download page, and download the Fritzing’s Graphic Standards folder. After you download their zip file, you will need to make sure to unzip the folder, and place anywhere on your computer. You will want to install the fonts on your computer.

SparkFun Fritzing Example Templates

This tutorial will reference the SparkFun Fritzing Example Templates a lot. If you are making a Fritzing part for a SparkFun board or want a starting point, download this set of example templates from the SparkFun Fritzing Parts Github repo. The SparkFun Fritzing templates will have this tutorial’s example, SparkFun T5403 Barometer Breakout SVG, files to compare and work with.

Breadboard View

When the Fritzing starts up, you should be in the Welcome view. You will want to go to Breadboard view.

breadboard view

There is two main steps you will need to do in Breadboard view. First, create your breadboard SVG, and upload it. Fritzing prefers using SVG format, so your images look great when you are zoomed in and out! Second, you’ll need to change the connector pins.

Please note: If you are only making a basic IC you can skip to Editing Breadboard View section of this tutorial.

Fritzing Graphic Standards

On the Fritzing website, there are a lot of graphic standards to follow. It is a great idea to follow the graphic standards that way your parts match other Fritzing parts.

Templates

When making you part, it is recommended to start from a template. Have an image of the part to refer to, so, when making your SVG files, the process will go faster.

Tip: If you are making a custom Fritzing part for a board you made in EAGLE, you can download an ULP that converts boards to SVG. This way you can have an accurate SVG of your EAGLE board for a reference. You can find EAGLE ULPs on the Cadsoft site.

It is time to make your graphic for the Breadboard view!

Create a New Part

For this tutorial, we are going to create a Fritzing part for the SparkFun T5403 Barometer Breakout.

T5403 Breakout Image

EAGLE image of the SparkFun T5403 Barometer Breakout

Open the Fritzing application. You should see tabs for Welcome, Breadboard, Schematic, and PCB towards the top of the program. Click on Breadboard button to make sure you are in the Breadboard view.

Breadboard Button

Check for Pre-made Parts

If you are just updating a board in Fritzing, first check to see if there is a part that is closely related to the Fritzing part you are trying to create. You can type the part’s name into the search bar.

Search for Part

The search bar can be found at the top of the Parts window

You can also look in the different sections of the Fritzing’s Parts window for a similar part.

Parts Window

Look for the SparkFun flame to see a huge section of SparkFun Fritzing parts

Using an IC as a Starting Point

If there is not a part like the one you are trying to make, using an IC as a base is a great place to start. Click on the CORE tab in the Part Window. Scroll down until you see the ICs. Under the ICs section, click and drag the IC icon onto the Breadboard window.

Core Tab

Custom ICs are simple, since Fritzing lets you change the number of pins and the IC package

Dragging IC on breadboard window

Changing the Name of the IC

Look for the IC properties in the Inspector window on the right. Change the name of the IC to your part’s name. Then, change the number of pins needed for the board or part in the pins section. For the SparkFun T5403 Barometer Breakout, we need 8 pins. You will see the IC, in the Breadboard view, change to your part’s name.

Changing name

Fritzing (New) Parts Editor

Right-click the IC in the Breadboard window, and select Edit (new parts editor). The Fritzing (New) Parts Editor should pop up.

Go to Parts Editor

There are 6 main sections of the Fritzing (New) Parts Editor in which you will need to make changes. Those are:

  • Breadboard
  • Schematic
  • PCB
  • Icon
  • Metadata
  • Connectors

There really isn’t an order you need to follow. After making a couple different custom parts you will probably end up starting in one view before the others. In this tutorial, we’re just going to go down the list.

Author note: I found, for boards with a large number of pins, that starting off in the Connectors view saves a little bit more time, since you can go down the list to name the connector pins faster.

Before you continue on, it is a good idea to save as a new part first. If you need to stop anytime when making the custom part, you can come back to it in the future. Go to File. Then, select Save as new part.

Save as new Part

You can choose to name the prefix if you want.


Let’s continue on to Breadboard view!

Custom Breadboard SVG

Create a File

Open up your vector graphics editor and create a new file. The image size of the file should be the same size of your board. The SparkFun T5403 Barometer Breakout size is 1″ x 0.650″. You are going to want to save the file with a good naming convention, since you are going to end up needing 3 different svg files when creating your Fritzing part.

Illustrator Users: You can save by going to File->Save As, saving as a SVG, and hitting Save.

For this example the Breadboard SVG is named: SFE_T5403_Barometer_Breakout_breadboard.svg

Use Templates as References

To compare the different layers and groups, you can open up the Fritzing BreadboardViewGraphic_Template.svg file found in the Fritzing Fonts and Template folder you downloaded earlier. You can also open the example SparkFun T5403 Barometer Breakout breadboard SVG template file from the SparkFun Fritzing Parts Github repo.

You can see with the example templates how you can kept the layers organized. For the SparkFun T5403 Barometer Breakout, there is a “breadboard” group. Inside that breadboard group it will have the group of parts, copper layers, silkscreen group, and the board path.

Tips for Making Your Custom Breadboard Graphic

You are now able to create your custom part’s breadboard graphic. Here are some helpful tips!

Follow the Fritzing Graphic Standards

Here are some main color standards for Breadboard images:

To keep with the Fritzing graphics standards, you are going to want to make the copper contacts the copper/tinned color.

Copper Green

HEX: 9A916C, RGB: 154 145 108

If you have legs on any of your parts on your board, the color to use is grey.

Leg Grey

HEX: 8C8C8C, RGB: 140 140 140

SparkFun Red is: HEX: E62C2E, RGB: 230 44 46

Keep It Simple

The great thing with Fritzing is you can make your board as simple or as complex as you want. Since SparkFun is always trying to make our products better with revisions and have a lot of boards, it is easier and faster for us to not included certain details, like traces or every component, on our boards. That way if there is a new change with the board, like a resistor value change, we don’t have to go in and change that resistor in the Fritzing part. Focusing more on the important components, like ICs, might be a better way to spend your tine. It will still look nice, but less work!

Use Components That Already Exist

If you need an SMD LED on your board that is already in Fritzing, go ahead and use it! This will save you time and keep the all the Fritzing parts having the same look and feel. If you create a custom board with components that others can use, you can share them on the Fritzing site, so others can use too! Make sure to organize the component graphics nicely in the vector graphics editor you are using, so the parts are easy to find when using on future boards.

Name Connector Pins in Copper Groups

Naming your connectors will be a huge time saver. For the SparkFun T5403 Barometer Breakout example, under the copper group, each connector is named connector#pad.

Copper Layers

Example in Illustrator. If you are using Inkscape, you will still want to make sure the connectors are appropriately named.

Use the ORC-A or Droid Sans Fonts.

Stick with the Fritzing fonts to kept all Fritzing parts looking alike. It is suggested that the standard font size is 5pt. However, there will be times you won’t have space for smaller boards. You won’t want to go lower then 3pt, because it starts to become harder to see without zooming in. On the Fritzing site they mention using black as the font color. Whatever your silkscreen color is tends to look better. For this example we are using white, since that is the breakout board’s silkscreen color and it is easier to read against a red background.

Create a Compound Path to Make Board Openings See-through

Illustrator Users: Create a path in the size of your PCB. For the SparkFun T5403 Barometer Breakout, you can use the rectangle tool to make a 1″ x 0.650″ rectangle. Then, make paths where you have openings in your board. For example, you can use the ellipse tool, under the rectangle tool, to make perfect circles where there are openings for stand-offs and connector pins. Select all the hole opening layers and the bottom PCB layer.

Select All

Make sure the bottom PCB layer is selected

Next go to Object->Compound Path->Make. You should now have a compound path, and you will be able to see through the openings in Fritzing.

Final Breadboard Image

Final breadboard graphic

Save

Make sure to Save as SVG again once you are done creating your custom board! Now, you can continue on to Editing Breadboard View.

Breadboard View – Parts Editor

Load Image

After you created your custom breadboard image, you will want to load the breadboard SVG in the Fritzing (New) Parts Editor. First, go back to the Fritzing (New) Parts Editor and click the Breadboard button to get into the Breadboard view. Go to File->Load image for view.

Load graphic

Next, you will select the breadboard SVG you just created and hit Open. The graphic should be now in the Fritzing (New) Parts Editor.

Connectors

When working in the main Fritzing application, you connect different Fritzing parts with colored wires to show how the parts connect to one and another. In order for Fritzing to know where connector pins are on a board or part, you will need to tell Fritzing where those connectors are.

Name and Description for Connector Pins

For the Breadboard view, the Connectors window will be on the right side of the Fritzing (New) Parts Editor. Select a pin to change the name of the pin and to add a description.

Select Pin

Choose any of the connector pins to edit

Change Connector Pin Name

Select the Connector Pin’s Graphic

Click on the Select graphic button on the right of your connector pin’s name. Then, click on the connector pin’s graphic. This will set the Anchor point. The Anchor point is the location where the wire connects to that connector. By default the Terminal point will show up in the middle of the selected graphic. If you want to move the Terminal point, you are able to click on the Terminal point and hold to move. You can also change the Terminal point by clicking on either “Center”, “W”, “N”, “S”, or “E” in the Connectors window.

Example Terminal Placement

You can see the difference in the placement of the wire when you change the Terminal point

Change Connector Type

Change the type of connector in the Connectors window. You can choose from male, female, or pad. For the SparkFun T5403 Barometer Breakout, all the connector pins are female.

Set Connector Type

In the image below, you can see the differences between setting the connector type as male vs female.

Different Connector Type

Top board has the connector type set at male. Bottom board has the connector type correctly set at female.

Repeat for All Connector Pins

Name, select the appropriate graphic, and change the connector type for all your connector pins. You can also set Internal Connections in the Connectors window.

Schematic View

Custom Schematic SVG

Go back to either Illustrator, Inkscape, or the vector graphic editor you are using. Open up the Fritzing’s SchematicViewGraphic_Template.svg in the downloaded Fonts and Templates folder. You can also open the example SparkFun T5403 Barometer Breakout schematic SVG template file from the SparkFun Fritzing Parts Github repo.

When editing the schematic to match your board, you will want to make sure each connector pin is shown. You will want to change the pin labels to match the connector pin names. Depending on your part, you might have to resize the template schematic. Make sure there is 0.1” space between the main part symbol square and the edge of the outer pins.

Schematic Example

Make sure to delete the 0.1″ dimension helper box, so it doesn’t show up in the final Fritzing schematic graphic

Save SVG

You will want make sure to save as a new SVG. Remember to have a naming convention that will be easy to tell the difference between the other SVG files you are creating for your Fritzing part.

Editing Schematic View in Parts Editor

Load SVG

Go back to the Parts Editor, and click on the Schematic button to go to the Schematic view. Go to File->Load image for view. Next, you will select the schematic SVG you just created, and click Open. The part should be now in the Fritzing (New) Parts Editor.

Set Connector Pins

If you look at the Connectors window on the right side, you will notice that your pin names are already there. When you make a change to the connector pin’s name and description in either Breadboard, Schematic, PCB, or Connectors view, the Parts Editor will automatically change the connector pin’s name and description for the other views. Also, the connector type (male, female, or pad) will still be the same.

Just like you did in Breadboard view, you will still need to select a graphic for each pin. Click on the ‘Select graphic’ button, and choose the appropriate graphic for that pin. For the Schematic view, you are going to want to change the Terminal point, so the connecting wires are connecting at the furthest point.

The easiest way to do this is make sure the connector pin’s graphic is still selected, and change the Terminal point in the Connectors window. For the GND graphic, the Terminal point is moved to the south end by clicking on “S”.

Terminal Point

Repeat for All Connectors

After you update all your connector pins you can move on to Editing in PCB view.

PCB View

Making custom PCB SVG

Go back to either Illustrator, Inkscape, or the vector graphic editor you are using. When making a custom PCB SVG, the main image groups you will need are copper (which will have all your connector pads) and silkscreen.

Create the PCB Graphic

You can either start fresh when creating a PCB SVG, modify your custom breadboard SVG, or edit the Fritzing’s PCBViewGraphic_Template.svg in the downloaded Fonts and Templates folder. For this example, the custom breadboard SVG was modified, and the file was saved as a new SVG called SFE_T5403_Barometer_Breakout_PCB.svg.

Make Sure to have Two Copper Groups

When setting up your layers, make sure to have two copper groups. All of your connector layers should be in the copper groups. When you do this, Fritzing will know that the component has the copper connectors on both sides of the PCB.

Example of PCB Layers

Illustrator example of having two copper groups

Make Sure the Connector Pins’ Spacing is Accurate

It is important to have the PCB connector pins match accurately with your board and to have the appropriate spacing between pins. Fritzing offers a PCB Fab services. If you or other Fritzing users want to use that service with your custom part, you will want to make sure your PCB view is accurate.

Graphic Standards

Instead of the connector pins being a copper/tinned green color, the PCB view connector pins are the “copper” color:

Copper Color

Hex: F7BD13 RGB: 247 189 19

The main changes made from the custom breadboard SVG is that the main groups are copper and silkscreen. The silkscreen will still be white.

Final PCB Graphic

Final PCB Graphic

Editing PCB View in Parts Editor

Go back to the Parts Editor, and click on the PCB button to get to PCB view. Go to File->Load image for view. Next, you will select the PCB SVG you just created, and click Open. The part should be now in the Fritzing (New) Parts Editor.

Update Connector Pins

Select the appropriate graphics for each connector pin, just like you did in Breadboard and Schematic view.

Icon View

Reuse a Past Graphic

Go to the Fritzing (New) Parts Editor, and click on the Icon button to get to Icon view. The great thing about Icon view is that you can reuse your breadboard, schematic, or PCB SVG for the icon image, so there is no need to make a new image! All you need to do is go to File and select what image you want to reuse. For the SparkFun T5403 Barometer Breakout, the Icon view reuses the breadboard image. The breadboard image should show up.

Reuse Past Graphic

Great Scott! You are now done with Icon view!

Metadata

Go to Metadata View

Go to the Parts Editor, and click the Metadata button to go into Metadata view. The Metadata is where you will add all the important information about your part!

Different Sections in the Metadata View

Title: Pretty self-explanatory. This is going to be the name of your part.

Date: The date entry is locked in Fritzing. The date should show the date you are creating the part. If you update the part later down the road, the date will be changed to the current date of the last update.

Author: You will want to put your name in here, so, if you share your part with the Fritzing community, they know who made the part.

Description: Description should included anything that is important about the board, such as operating voltage.

Label: The Label is shown in Schematic view and makes it easier to tell which part you have selected. For the SparkFun T5403 Barometer Breakout, the Label is changed to Part. The reason for that is, because Part is fairly small and the SparkFun T5403 Barometer Breakout name is already on the schematic graphic itself. It is up to you what you want to label your part!

URL: Consider posting the url of the part, so anyone can get more information about your part.

Family: If you have a part that comes in different colors, chip packages, etc, you will want them to be in the same Family. For example if you have a through-hole LED that comes in different colors, all the different colors of the same LED will be in the same family.

Variant: When creating a brand new part, you want to make sure the Variant is 1. When you do revisions in the future, it will change the next revision to Variant 2 if it is in the same family.

Properties: A place to put important details like part numbers, pin spacing, and etc.

Tags: Use tags that can be found easier and best describe your part in as few words as possible.

Metadata

Feel that the info is a little lacking? You can update this content again later when you have more to write.

Connectors View

Go to Connectors view

Go to the Parts Editor, and click the Connectors button to go into Connectors view. In the Connectors view you are able to do the following:

  • Change the number of connectors
  • Set connector type
  • Set the connector pins as Through-hole or SMD
  • Name connector pins
  • Add connector pin descriptions

Connectors view

You shouldn’t need to change anything in the Connectors view, since you already filled out all the information in the other views. If you need to make any last minute changes, now you can. Keep in mind, if you change the number of connectors here, you will need to go back and update Breadboard, Schematic, and PCB views.

Save

Now you can save your part! Go to File>Save

Continue on to exporting part!

Exporting New Part

Quality Check in Fritzing Application

It is time to check out your new Fritzing part in the main Fritzing application. When you Saved As new part in the Fritzing (New) Parts Editor earlier, the part automatically shows under the My Parts label in the MINE tab in the main Fritzing application.

Before exporting your new custom part, you will want to check if each view looks good. Make sure you are in the main Fritzing application and not the Fritzing (New) Parts Editor. Go to Breadboard view by clicking on the Breadboard button at the top. In the Parts window, on the right side, make sure you are in the MINE tab. You should see your new part. Click and drag the board on the Breadboard view.

MINE Tab

Double check if the pins are named correctly and are working properly. Do the same in the Schematic and PCB view. Once you have done a quality check, you can export the part.

Export part

Right click on the new part’s icon in the My Parts window and select Export Part. Save out your Fritzing part.

Export Part

Congratulations, you made your own Fritzing Part!

Resources and Going Further

Contribute to Fritzing

Now that you have your part done, you are able to connect with other Fritzing parts. You can share your part or a project tutorial on the Fritzing site. There are many more ways to contribute to the Fritzing community! Check out the Fritzing Support Us page for even more ways to support Fritzing.

Large Batches of Fritzing Parts?

If you are a developer that uses EAGLE or someone who is investing a lot of time in making Fritzing parts, the Fritzing team has open sourced a toolkit to make the SVG files from EAGLE .brd files. It is highly recommended that you check out if you are creating batches of SVG board files ready for Fritzing. They have the source code on the Fritzing Google code page.

Further Reading

At SparkFun, we use Fritzing at a lot in our Learn tutorials. Check out how we use Fritzing in different tutorials to show how to connect different parts together.

Here are some tutorials that uses Fritzing in the Hook-up section:

If you want to learn more about designing your own PCBs with other software, visit these tutorials:

Serial Peripheral Interface (SPI)

Introduction

Serial Peripheral Interface (SPI) is an interface bus commonly used to send data between microcontrollers and small peripherals such as shift registers, sensors, and SD cards. It uses separate clock and data lines, along with a select line to choose the device you wish to talk to.

Suggested Reading

Stuff that would be helpful to know before reading this tutorial:

What’s Wrong with Serial Ports?

A common serial port, the kind with TX and RX lines, is called “asynchronous” (not synchronous) because there is no control over when data is sent or any guarantee that both sides are running at precisely the same rate. Since computers normally rely on everything being synchronized to a single “clock” (the main crystal attached to a computer that drives everything), this can be a problem when two systems with slightly different clocks try to communicate with each other.

To work around this problem, asynchronous serial connections add extra start and stop bits to each byte help the receiver sync up to data as it arrives. Both sides must also agree on the transmission speed (such as 9600 bits per second) in advance. Slight differences in the transmission rate aren’t a problem because the receiver re-syncs at the start of each byte.

Asynchronous serial waveform

(By the way, if you noticed that “11001010” does not equal 0x53 in the above diagram, kudos to your attention to detail. Serial protocols will often send the least significant bits first, so the smallest bit is on the far left. The lower nybble is actually 0011 = 0x3, and the upper nybble is 0101 = 0x5.)

Asynchronous serial works just fine, but has a lot of overhead in both the extra start and stop bits sent with every byte, and the complex hardware required to send and receive data. And as you’ve probably noticed in your own projects, if both sides aren’t set to the same speed, the received data will be garbage. This is because the receiver is sampling the bits at very specific times (the arrows in the above diagram). If the receiver is looking at the wrong times, it will see the wrong bits.

A Synchronous Solution

SPI works in a slightly different manner. It’s a “synchronous” data bus, which means that it uses separate lines for data and a “clock” that keeps both sides in perfect sync. The clock is an oscillating signal that tells the receiver exactly when to sample the bits on the data line. This could be the rising (low to high) or falling (high to low) edge of the clock signal; the datasheet will specify which one to use. When the receiver detects that edge, it will immediately look at the data line to read the next bit (see the arrows in the below diagram). Because the clock is sent along with the data, specifying the speed isn’t important, although devices will have a top speed at which they can operate (We’ll discuss choosing the proper clock edge and speed in a bit).

alt text

One reason that SPI is so popular is that the receiving hardware can be a simple shift register. This is a much simpler (and cheaper!) piece of hardware than the full-up UART (Universal Asynchronous Receiver / Transmitter) that asynchronous serial requires.

Receiving Data

You might be thinking to yourself, self, that sounds great for one-way communications, but how do you send data back in the opposite direction? Here’s where things get slightly more complicated.

In SPI, only one side generates the clock signal (usually called CLK or SCK for Serial ClocK). The side that generates the clock is called the “master”, and the other side is called the “slave”. There is always only one master (which is almost always your microcontroller), but there can be multiple slaves (more on this in a bit).

When data is sent from the master to a slave, it’s sent on a data line called MOSI, for “Master Out / Slave In”. If the slave needs to send a response back to the master, the master will continue to generate a prearranged number of clock cycles, and the slave will put the data onto a third data line called MISO, for “Master In / Slave Out”.

alt text

Notice we said “prearranged” in the above description. Because the master always generates the clock signal, it must know in advance when a slave needs to return data and how much data will be returned. This is very different than asynchronous serial, where random amounts of data can be sent in either direction at any time. In practice this isn’t a problem, as SPI is generally used to talk to sensors that have a very specific command structure. For example, if you send the command for “read data” to a device, you know that the device will always send you, for example, two bytes in return. (In cases where you might want to return a variable amount of data, you could always return one or two bytes specifying the length of the data and then have the master retrieve the full amount.)

Note that SPI is “full duplex” (has separate send and receive lines), and, thus, in certain situations, you can transmit and receive data at the same time (for example, requesting a new sensor reading while retrieving the data from the previous one). Your device’s datasheet will tell you if this is possible.

Slave Select (SS)

There’s one last line you should be aware of, called SS for Slave Select. This tells the slave that it should wake up and receive / send data and is also used when multiple slaves are present to select the one you’d like to talk to.

alt text

The SS line is normally held high, which disconnects the slave from the SPI bus. (This type of logic is known as “active low,” and you’ll often see used it for enable and reset lines.) Just before data is sent to the slave, the line is brought low, which activates the slave. When you’re done using the slave, the line is made high again. In a shift register, this corresponds to the “latch” input, which transfers the received data to the output lines.

Multiple slaves

There are two ways of connecting multiple slaves to an SPI bus:

  1. In general, each slave will need a separate SS line. To talk to a particular slave, you’ll make that slave’s SS line low and keep the rest of them high (you don’t want two slaves activated at the same time, or they may both try to talk on the same MISO line resulting in garbled data). Lots of slaves will require lots of SS lines; if you’re running low on outputs, there are binary decoder chips that can multiply your SS outputs.

alt text

  1. On the other hand, some parts prefer to be daisy-chained together, with the MISO (output) of one going to the MOSI (input) of the next. In this case, a single SS line goes to all the slaves. Once all the data is sent, the SS line is raised, which causes all the chips to be activated simultaneously. This is often used for daisy-chained shift registers and addressable LED drivers.

alt text

Note that, for this layout, data overflows from one slave to the next, so to send data to any one slave, you’ll need to transmit enough data to reach all of them. Also, keep in mind that the first piece of data you transmit will end up in the last slave.

This type of layout is typically used in output-only situations, such as driving LEDs where you don’t need to receive any data back. In these cases you can leave the master’s MISO line disconnected. However, if data does need to be returned to the master, you can do this by closing the daisy-chain loop (blue wire in the above diagram). Note that if you do this, the return data from slave 1 will need to pass through all the slaves before getting back to the master, so be sure to send enough receive commands to get the data you need.

Programming for SPI

Many microcontrollers have built-in SPI peripherals that handle all the details of sending and receiving data, and can do so at very high speeds. The SPI protocol is also simple enough that you (yes, you!) can write your own routines to manipulate the I/O lines in the proper sequence to transfer data. (A good example is on the Wikipedia SPI page.)

If you’re using an Arduino, there are two ways you can communicate with SPI devices:

  1. You can use the shiftIn() and shiftOut() commands. These are software-based commands that will work on any group of pins, but will be somewhat slow.
  2. Or you can use the SPI Library, which takes advantage of the SPI hardware built into the microcontroller. This is vastly faster than the above commands, but it will only work on certain pins.

You will need to select some options when setting up your interface. These options must match those of the device you’re talking to; check the device’s datasheet to see what it requires.

  • The interface can send data with the most-significant bit (MSB) first, or least-significant bit (LSB) first. In the Arduino SPI library, this is controlled by the setBitOrder() function.
  • The slave will read the data on either the rising edge or the falling edge of the clock pulse. Additionally, the clock can be considered “idle” when it is high or low. In the Arduino SPI library, both of these options are controlled by the setDataMode() function.
  • SPI can operate at extremely high speeds (millions of bytes per second), which may be too fast for some devices. To accommodate such devices, you can adjust the data rate. In the Arduino SPI library, the speed is set by the setClockDivider() function, which divides the master clock (16MHz on most Arduinos) down to a frequency between 8MHz (/2) and 125kHz (/128).
  • If you’re using the SPI Library, you must use the provided SCK, MOSI and MISO pins, as the hardware is hardwired to those pins. There is also a dedicated SS pin that you can use (which must, at least, be set to an output in order for the SPI hardware to function), but note that you can use any other available output pin(s) for SS to your slave device(s) as well.
  • On older Arduinos, you’ll need to control the SS pin(s) yourself, making one of them low before your data transfer and high afterward. Newer Arduinos such as the Due can control each SS pin automatically as part of the data transfer; see the Due SPI documentation page for more information.

Resources and Going Further

Tips and Tricks

  • Because of the high speed signals, SPI should only be used to send data over short distances (up to a few feet). If you need to send data further than that, lower the clock speed, and consider using specialized driver chips.
  • If things aren’t working the way you think they should, a logic analyzer is a very helpful tool. Smart analyzers like the Saleae USB Logic Analyzer can even decode the data bytes for a display or logging.

alt text

Advantages of SPI:

  • It’s faster than asynchronous serial
  • The receive hardware can be a simple shift register
  • It supports multiple slaves

Disadvantages of SPI:

  • It requires more signal lines (wires) than other communications methods
  • The communications must be well-defined in advance (you can’t send random amounts of data whenever you want)
  • The master must control all communications (slaves can’t talk directly to each other)
  • It usually requires separate SS lines to each slave, which can be problematic if numerous slaves are needed.

Further Reading

Check out the Wikipedia page on SPI, which includes lots of good information on SPI and other synchronous interfaces.

This blog post presents a more correct way to set up an SPI network amongst your embedded devices, particularly for use with an Arduino microcontroller.

A number of SparkFun products have SPI interfaces. For example, the Bar Graph Breakout kit has an easy-to-use SPI interface that you can use to turn any of 30 LEDs on or off.

Other communication options:

Now that you’re a pro on SPI, here are some other tutorials to practice your new skills:

WS2812 Breakout Hookup Guide

Preface

The WS2812 is an unassuming RGB LED with an integrated control circuit hidden underneath. We love the simplicity of this little IC/LED combo. It’s at the heart of a number of products including the the simple WS2812 Breakout Board.

WS2812B breakout

The LilyPad Pixel shares the same circuit as the breakout board, but it comes on a circular, purple LilyPad board. These are perfect for sewing onto clothing or other fabric, and embedding into an e-textiles project.

LilyPad Pixel ISO

Finally, the WS2812 serves as the heart and soul of a variety of LED strips. These strips come in four flavors: 5 meter sealed, 1m sealed, 5m bare, and 1m bare.

Addressable RGB Strip

What makes the WS2812 really special is the way its controlled. The IC embedded into the LED communicates via a very unique one-wire interface. With the help of some libraries, they’re really very easy to control. Plus they’re chain-able – the output of one LED can be connected to the input of another to create strips of hundreds of LEDs. The more boards you have linked together, the fancier your animations can be!

In this tutorial we’re going to get you familiar with the workings of the WS2812. We’ll go over some of the ways you might want to hook up to the breakout board, LilyPad, or strips. And we’ll close the tutorial out with some example Arduino code.

Required Materials

Stating the obvious: you’ll need a WS2812-based board or strip. The more the merrier! In the example hookup we’ll be linking together five breakout boards, but the example should be adaptable to the other products. Grab however many you think you’ll need for your project, regardless of how many you have, it’s not enough.

Aside from the star of the show, you’ll also need a microcontroller. Something that can send the series of 1’s and 0’s used to control the LEDs. Our go-to is the classic Arduino Uno, but any Arduino board should do. Or you can try to adapt the example code to your favorite microcontroller.

You’ll also need some way to connect between the board and an Arduino. You could use a combination of male headers and breadboard. Or you could just go with a few pieces of wire.

Tools

In order to get a good, solid, electrically-sound connection to the breakout boards, you’ll need to solder to the pins. That means you’ll need at least a basic soldering iron as well as solder. Check out our how to solder tutorial for help, if this is you first time soldering.

Suggested Reading

These boards aren’t too hard to use. If you’ve done anything with Arduino before, you’ll be prepared to work with the WS2812. If you’re not exactly sure what this “Arduino” thing is, or if you’re not familiar with the topics below, consider reading their tutorials:

WS2812 Overview

The WS2812 is much more than meets the eye. It may look like a common 5050-sized (5x5mm) LED, but there’s actually an integrated circuit embedded inside there too. If you look really hard, you can see the tiny black chip hidden in there, along with minuscule gold wires connecting the chip to the LED.

Zoom in on the IC

Pretty nifty view at the guts of the WS2812.

The LED itself is like any RGB (Red/Green/Blue) LED. The brightness of each color can be adjusted using pulse-width modulation to one of 256 different levels. That means there are 16,777,216 (2563) possible combinations of colors. You can produce any color from white to black (off), or salmon to sienna.

Breakout Board Pinout

The Breakout board mounts that multi-taltented LED onto a PCB, and breaks out the few pins required to control the LED.

Annotated WS2812 Breakout pinout

Four unique pins are broken out:

  • 5V – This should be a regulated supply voltage between 5V and about 7V. More than that could harm the LED, less than 5V will either reduce brightness, or it just won’t turn on.
  • GND – The common, ground, 0V reference supply voltage.
  • DI – Data from a microcontroller (or another WS2812 pixel) comes into this pin.
  • DO – Data is shifted out of this pin, to be connected to the input of another pixel or left floating if it is the last link in the chain.

Data Transmission Interface

Note: this stuff is ugly, and not critical to understand if you just want to use the breakout board. (That’s what libraries are for, right?!) It’s interesting to talk about, because the interface is so unique.

The communication interface between a microcontroller and the WS2812 is weird. It’s one wire, but it’s not like a standard, UART serial interface. This interface is very time-specific. Both a logic 0 and a logic 1 require a square pulse, and it’s the length of the pulse that defines which it is.

Data code chart

Timing diagram for a single bit of value 0 or 1.

The data is sent in a sequence containing 24 of those bits – 8 bits for each color – followed by a low “reset” pulse of at least 50µs.

Data bit order

A sequence of 24 timed-bits sets the color for each channel. 8-bits per channel. Green first, then red, then blue.

The larger the value of a specific color is, the brighter it will be. If every color is set to 0, the LED will be off. If every color is set to max – 255 – the LED will be as bright and white as can be.

This is all to say that the interface is very time-specific. To run the LEDs you’ll need a real-time processor, like an Arduino; microprocessors like those on the Raspberry Pi or pcDuino can’t give you a reliably-timed pulse. Even if one bit is less than a microsecond off, that could mean the difference between purple and maroon.

LilyPad Pixel

Want to embed the WS2812 LEDs into your clothing? We have a thing for that! The LilyPad Pixel Board is the e-textile version of the WS2812 Breakout. The functionality and pinouts are exactly the same, though the pins are in slightly different location to make threaded traces easier.

LilyPad Pixel

Rather than solder these boards, you can use conductive thread to connect them to other LilyPad boards. You can control individual LEDs, or chain them together to create a multitude of colors on your clothing. The examples in this tutorial use the WS2812 Breakout, but you can substitute the LilyPad Pixel for any of the breakout boards.

Addressable LED Strips

If you need an abundance of WS2812 LEDs in a slick, pre-assembled form factor these addressable LED strips might be for you.

LED strip overview

The LED strips come on a reel as shown above.

The WS2812 Addressable LED strips come in four product options, which vary by size and sealant. You can get them in either 1m or 5m lengths, and for each length the strip can be either covered by a waterproof sealant or left bare.

The waterproofed strips are rated IP65 – dust tight and protected from water jets.

Zoom in on LED strip

Each strip has 60 LEDs per meter, which are spaced about 1.65cm away from each other.

Connecting to the Strips

Each end of the LED strip is terminated with a set of three colored wires: red, yellow, and green. Two wires are for power, and the third transmits data either into our out of the strip:

Wire Color Function Notes
Red Vcc WS2812 power supply. Should be a regulated supply between 5V and 7V.
Yellow GND Ground. 0V.
Green Data In/Out Serial data in or out. Look at arrows and labels on strip to check which it is.

LED strip connectors

Each of the wire pigtails are terminated by a three-pin JST SM connector, which you can use to connect string strips together. For the first strip in a string, you can either connect to a mating connector, or cut and strip the wires, and connect them to your controlling device.

Hardware Hookup

The great thing about these LEDs is they’re super easy to chain together. Plus just one, single pin from your microcontroller is required to control an entire strip of LEDs. In this example we’ll link together five LEDs, but you should be safe to increase that ten-fold or even more.

Solder/Sew/Wire Something

The first assembly step for each of these products is creating a reliable, electrical connection from the LED to your control board. You’ll need to solder either headers or wires to your breakout boards. Or sew your LilyPad Pixel withconductive thread. Or strip and splice some wire to connect up the LED strips.

If you’re going to stick the boards into a breadboard or other prototyping board, straight male headers might be the best choice.

Breakouts breadboarded

WS2812 breakouts linked together on a breadboard. Hidden under each is a white wire that connects DO of one to DI of the next.

If you’re going to make a big strip of boards, you may need to opt for the stranded wire route.

Breakouts wired together

Link WS2812 boards together in a chain, by connecting DIs to DOs (don’t forget power too). Sorry, the fancy green boards aren’t available :(.

Select a Power Source

The WS2812 requires about 5V to work. It should operate at anywhere between about 4V to 7V, but 5V is readily-available on most boards. The 5V header on an Arduino board, for example, is a perfect voltage supply for the LEDs.

Also consider how much current your LED strip is going to pull. With every single LED on at full brightness, each breakout board can pull about 60mA (20mA per channel). Even with just ten breakout boards strung together, you’re looking at upwards of a possible 600mA. Yikes! If you’re stringing together a lot of these things, make sure your power supply can provide the necessary current-umph. If you end up using an external power supply, make sure you connect the power supply ground to your Arduino ground as well.

Connecting an Arduino

This hookup is fairly straightforward. You can power the breakout board(s) using the Arduino’s 5V and GND pins. Then all you need is to pick a free I/O pin to send data to the LED. Let’s go with pin 4. To link more breakouts together, simply connect the output pin of one to the input of the next. Make sure each breakout also gets some power delivered to it.

Five boards hooked up to an Arduino

Protect your WS2812’s!

In addition to the hookup above we recommend the following additions to help you get the most out of your WS2812-based devices:

Add a Big Smoothing Capacitor

Before connecting the WS2812 to a power source, connect a big capacitor from power to ground. A cap between100µF and 1000µF should be good.

1000uF cap

This cap will help to smooth out your power supply. The current draw of a WS2812 can vary wildly, and as current draw grows and shrinks it’ll be up to your power source to compensate. The cap will act as a “power reservoir” to store energy in case the supply dips.

Try to place this cap as close to your WS2812 as possible.

Add an In-Line Resistor On the Data Signal

Placing a small-ish resistor between your Arduino’s data output and the WS2812’s data input will help protect the data pin. A resistor between 220 and 470 Ω should do nicely.

330 Ohm resistor

Try to place the resistor as close to the WS2812 as possible.

Keep Wires Short!

Wires don’t conduct perfectly. They’ll inevitably induce some voltage loss, especially when they’re really long. Try to keep wires between your power supply, Arduino, and WS2812 as short as possible to minimize this loss.

Adding Firmware

For our example code, we’ll be making use of Adafruit’s fantastic NeoPixel library.

Click here to download a copy of both the example code, as well as the NeoPixel library. The library is located in the “Adafruit_NeoPixel” folder, and the example code is found in the “WS2812_Breakout_Example” folder.

You’ll need to install the library. For help there, check out our installing Arduino libraries tutorial.

With the library installed, open up WS2812_Breakout_Example.ino within Arduino. Before you upload the code, make sure you adjust the PIN and LED_COUNT definitions near the top of the sketch. These define which pin the first pixel is connected to, and how many total LEDs are linked up. Then upload away and enjoy the show!

Redboard controlling five breadboarded breakout boards

Using the NeoPixel Library

Setup

There are a few lines of code required to set up your sketch to use the library. First, call the constructor near the top of your code (before setup(), you’ll probably want it to be a global variable).

#define PIN 4
#define LED_COUNT 8

// Create an instance of the Adafruit_NeoPixel class called "leds".
// That'll be what we refer to from here on...
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);

The PIN and LED_COUNT parameters in that function call should be set, respectively, to the Arduino pin you’ve connected to the first breakout’s “DIN” pin and the total number of breakout boards you have linked up.

The rest of the setup is calling the leds.begin() function somewhere near the beginning of the setup() function.

Setting An LED

Setting an LED with the Adafruit NeoPixel library is a two step process. First, you have to set a pixel color using theleds.setPixelColor(position, color) command. The color parameter in that function can either be a 24-bit RGB color-code, or three separate bytes for each color. For example:

leds.setPixelColor(4, 0xFF00FF);    // Set fourth LED to full red, no green, full blue
leds.setPixelColor(4, 0xFF, 0x00, 0xFF)  // Also set fourth LED to full red, no green, full blue

Setting a pixel’s color does not equate to that pixel actually turning on though. For that, you need to callleds.show(). Note that when this function is called any LED that was previously set will turn on.

The Rest of the Code

After you’ve gotten the hang of using the NeoPixel library, the remaining parts of the sketch are finding ways to maniuplate the pixel colors. There are some fun functions in this example code, which create the classic “cylon” larson scanner, or draw a rainbow. We hope you can adapt them to make even more creative animations.

The included “WS2812_Definitions.h” file defines a huge list of standard colors. In there you’ll find anything from navyto saddle brown to ghost white.

Have fun!

Going Further and Resources

Resources

For more information on the LilPad Pixel Board, check out this other tutorial.

LilyPad Pixel Board Hookup Guide

SEPTEMBER 16, 2015

Add changing colors to your wearable projects using LilyPad Pixel Boards.

Going Further

Now that you’ve got the gist of the WS2812 Breakout board, how are you going to use it in a project? Need some inspiration? Check out these tutorials:

  • Using OpenSegment – The OpenSegment is a very large, 4-digit 7-segment display. If you’re on a blinky-high after playing with the WS2812 LEDs, this is another fun component to play with.
  • Getting Started with the LilyPad MP3 Player – If you’re into e-textiles (or even if you’re not, this thing is awesome), check out the LilyPad MP3 Player. Combine the LilyPad MP3 player with the WS2812 to make a nifty LED-music show.
  • Designing PCBs: Advanced SMD – If you’d like to lay out your own, custom PCB for the WS2812 LED/chip, check out this tutorial. It’ll walk you through every step required to design your very own circuit board using free software. You can use the WS2812 footprint from our parts library to get started.

Series and Parallel Circuits

Series and Parallel Circuits

Simple circuits (ones with only a few components) are usually fairly straightforward for beginners to understand. But, things can get sticky when other components come to the party. Where’s the current going? What’s the voltage doing? Can this be simplified for easier understanding? Fear not, intrepid reader. Valuable information follows.

In this tutorial, we’ll first discuss the difference between series circuits and parallel circuits, using circuits containing the most basic of components – resistors and batteries – to show the difference between the two configurations. We’ll then explore what happens in series and parallel circuits when you combine different types of components, such as capacitors and inductors.

Covered in this Tutorial

  • What series and parallel circuit configurations look like
  • How passive components act in these configurations
  • How a voltage source will act upon passive components in these configurations

Suggested Reading

You may want to visit these tutorials on the basic components before diving into building the circuits in this tutorial.

Series Circuits

Nodes and Current Flow

Before we get too deep into this, we need to mention what a node is. It’s nothing fancy, just the electrical junction between two or more components. When a circuit is modeled on a schematic, the nodes are the wires between components.

Node example schematic

Example schematic with four uniquely colored nodes.

That’s half the battle towards understanding the difference between series and parallel. We also need to understand how current flows through a circuit. Current flows from a high voltage to a lower voltage in a circuit. Some amount of current will flow through every path it can take to get to the point of lowest voltage (usually called ground). Using the above circuit as an example, here’s how current would flow as it runs from the battery’s positive terminal to the negative:

Example of current flow through circuit

Current (indicated by the blue, orange, and pink lines) flowing through the same example circuit as above. Different currents are indicated by different colors.

Notice that in some nodes (like between R1 and R2) the current is the same going in as at is coming out. At other nodes (specifically the three-way junction between R2, R3, and R4) the main (blue) current splits into two different ones. That’s the key difference between series and parallel!

Series Circuits Defined

Two components are in series if they share a common node and if the same current flows through them. Here’s an example circuit with three series resistors:

Schematic: Three resistors in series

There’s only one way for the current to flow in the above circuit. Starting from the positive terminal of the battery, current flow will first encounter R1. From there the current will flow straight to R2, then to R3, and finally back to the negative terminal of the battery. Note that there is only one path for current to follow. These components are in series.

Parallel Circuits

Parallel Circuits Defined

If components share two common nodes, they are in parallel. Here’s an example schematic of three resistors in parallel with a battery:

Schematic: Three resistors in parallel

From the positive battery terminal, current flows to R1… and R2, and R3. The node that connects the battery to R1 is also connected to the other resistors. The other ends of these resistors are similarly tied together, and then tied back to the negative terminal of the battery. There are three distinct paths that current can take before returning to the battery, and the associated resistors are said to be in parallel.

Where series components all have equal currents running through them, parallel components all have the same voltage drop across them – series:current::parallel:voltage.

Series and Parallel Circuits Working Together

From there we can mix and match. In the next picture, we again see three resistors and a battery. From the positive battery terminal, current first encounters R1. But, at the other side of R1 the node splits, and current can go to both R2and R3. The current paths through R2 and R3 are then tied together again, and current goes back to the negative terminal of the battery.

Schematic: Series and Parallel Resistors

In this example, R2 and R3 are in parallel with each other, and R1 is in series with the parallel combination of R2 and R3.

Calculating Equivalent Resistances in Series Circuits

Here’s some information that may be of some more practical use to you. When we put resistors together like this, in series and parallel, we change the way current flows through them. For example, if we have a 10V supply across a 10kΩ resistor, Ohm’s law says we’ve got 1mA of current flowing.

Schematic: Single Resistor in series with battery

If we then put another 10kΩ resistor in series with the first and leave the supply unchanged, we’ve cut the current in half because the resistance is doubled.

Schematic: Two series resistors in series with a battery

In other words, there’s still only one path for current to take and we just made it even harder for current to flow. How much harder? 10kΩ + 10kΩ = 20kΩ. And, that’s how we calculate resistors in series – just add their values.

To put this equation more generally: the total resistance of N – some arbitrary number of – resistors is their total sum.

Schematic snippet: N resistors in series

Equation: Rtot = R1+R2+...+R(N-1)+RN

Calculating Equivalent Resistances in Parallel Circuits

What about parallel resistors? That’s a bit more complicated, but not by much. Consider the last example where we started with a 10V supply and a 10kΩ resistor, but this time we add another 10kΩ in parallel instead of series. Now there are two paths for current to take. Since the supply voltage didn’t change, Ohm’s Law says the first resistor is still going to draw 1mA. But, so is the second resistor, and we now have a total of 2mA coming from the supply, doubling the original 1mA. This implies that we’ve cut the total resistance in half.

Schematic: Two parallel resistors in parallel with a battery

While we can say that 10kΩ || 10kΩ = 5kΩ (“||” roughly translates to “in parallel with”), we’re not always going to have 2 identical resistors. What then?

The equation for adding an arbitrary number of resistors in parallel is:

1/Rtot = 1/R1 + 1/R2 + ... + 1/R(N-1) + 1/RN

If reciprocals aren’t your thing, we can also use a method called “product over sum” when we have two resistors in parallel:

R1||R2 = R1*R2/(R1+R2)

However, this method is only good for two resistors in one calculation. We can combine more than 2 resistors with this method by taking the result of R1 || R2 and calculating that value in parallel with a third resistor (again as product over sum), but the reciprocal method may be less work.

Experiment Time – Part 1

What you’ll need:

Let’s try a simple experiment just to prove that these things work the way we’re saying they do.

First, we’re going to hook up some 10kΩ resistors in series and watch them add in a most un-mysterious way. Using a breadboard, place one 10kΩ resistor as indicated in the figure and measure with a multimeter. Yes, we already know it’s going to say it’s 10kΩ, but this is what we in the biz call a “sanity check”. Once we’ve convinced ourselves that the world hasn’t changed significantly since we last looked at it, place another one in similar fashion but with a lead from each resistor connecting electrically through the breadboard and measure again. The meter should now say something close to 20kΩ.

You may notice that the resistance you measure might not be exactly what the resistor says it should be. Resistors have a certain amount of tolerance, which means they can be off by a certain percentage in either direction. Thus, you may read 9.99kΩ or 10.01kΩ. As long as it’s close to the correct value, everything should work fine.

Multimeter Fritzing Diagram

The reader should continue this exercise until convincing themselves that they know what the outcome will be before doing it again, or they run out of resistors to stick in the breadboard, whichever comes first.

Experiment Time – Part 2

Now let’s try it with resistors in a parallel configuration. Place one 10kΩ resistor in the breadboard as before (we’ll trust that the reader already believes that a single 10kΩ resistor is going to measure something close to 10kΩ on the multimeter). Now place a second 10kΩ resistor next to the first, taking care that the leads of each resistor are in electrically connected rows. But before measuring the combination, calculate by either product-over-sum or reciprocal methods what the new value should be (hint: it’s going to be 5kΩ). Then measure. Is it something close to 5kΩ? If it’s not, double check the holes into which the resistors are plugged.

Experiment: Measure parallel resistors with a multimeter

Repeat the exercise now with 3, 4 and 5 resistors. The calculated/measured values should be 3.33kΩ, 2.5kΩ and 2kΩ, respectively. Did everything come out as planned? If not, go back and check your connections. If it did, EXCELSIOR! Go have a milkshake before we continue. You’ve earned it.

Rules of Thumb for Series and Parallel Resistors

There are a few situations that may call for some creative resistor combinations. For example, if we’re trying to set up a very specific reference voltage you’ll almost always need a very specific ratio of resistors whose values are unlikely to be “standard” values. And while we can get a very high degree of precision in resistor values, we may not want to wait the X number of days it takes to ship something, or pay the price for non-stocked, non-standard values. So in a pinch, we can always build our own resistor values.

Tip #1: Equal Resistors in Parallel

Adding N like-valued resistors R in parallel gives us R/N ohms. Let’s say we need a 2.5kΩ resistor, but all we’ve got is a drawer full of 10kΩ’s. Combining four of them in parallel gives us 10kΩ/4 = 2.5kΩ.

Four 10kΩ Resistors in parallel can be used to create a 2.5kΩ one!

Tip #2: Tolerance

Know what kind of tolerance you can tolerate. For example, if you needed a 3.2kΩ resistor, you could put 3 10kΩ resistors in parallel. That would give you 3.3kΩ, which is about a 4% tolerance from the value you need. But, if the circuit you’re building needs to be closer than 4% tolerance, we can measure our stash of 10kΩ’s to see which are lowest values because they have a tolerance, too. In theory, if the stash of 10kΩ resistors are all 1% tolerance, we can only get to 3.3kΩ. But part manufacturers are known to make just these sorts of mistakes, so it pays to poke around a bit.

Tip #3: Power Ratings in Series/Parallel

This sort of series and parallel combination of resistors works for power ratings, too. Let’s say that we need a 100Ω resistor rated for 2 watts (W), but all we’ve got is a bunch of 1kΩ quarter-watt (¼W) resistors (and it’s 3am, all the Mountain Dew is gone, and the coffee’s cold). You can combine 10 of the 1kΩ’s to get 100Ω (1kΩ/10 = 100Ω), and the power rating will be 10×0.25W, or 2.5W. Not pretty, but it will get us through a final project, and might even get us extra points for being able to think on our feet.

We need to be a little more careful when we combine resistors of dissimilar values in parallel where total equivalent resistance and power ratings are concerned. It should be completely obvious to the reader, but…

Tip #4: Different Resistors in Parallel

The combined resistance of two resistors of different values is always less than the smallest value resistor. The reader would be amazed at how many times someone combines values in their head and arrives at a value that’s halfway between the two resistors (1kΩ || 10kΩ does NOT equal anything around 5kΩ!). The total parallel resistance will always be dragged closer to the lowest value resistor. Do yourself a favor and read tip #4 10 times over.

Tip #5: Power Dissipation in Parallel

The power dissipated in a parallel combination of dissimilar resistor values is not split evenly between the resistors because the currents are not equal. Using the previous example of (1kΩ || 10kΩ), we can see that the 1kΩ will be drawing 10X the current of the 10kΩ. Since Ohm’s Law says power = voltage x current, it follows that the 1kΩ resistor will dissipate 10X the power of the 10kΩ.

Ultimately, the lessons of tips 4 and 5 are that we have to pay closer attention to what we’re doing when combining resistors of dissimilar values in parallel. But tips 1 and 3 offer some handy shortcuts when the values are the same.

Series and Parallel Capacitors

Combining capacitors is just like combining resistors…only the opposite. As odd as that sounds, it’s absolutely true. Why would this be?

A capacitor is just two plates spaced very close together, and it’s basic function is to hold a whole bunch of electrons. The greater the value of capacitance, the more electrons it can hold. If the size of the plates is increased, the capacitance goes up because there’s physically more space for electrons to hang out. And if the plates are moved farther apart, the capacitance goes down, because the electric field strength between them goes down as the distance goes up.

Now let’s say we’ve got two 10µF capacitors wired together in series, and let’s say they’re both charged up and ready discharge into the friend sitting next to you.

Capacitors in series

Remember that in a series circuit there’s only one path for current to flow. It follows that the number of electrons that are discharging from the cap on the bottom is going to be the same number of electrons coming out of the cap on the top. So the capacitance hasn’t increased, has it?

In fact, it’s even worse than that. By placing the capacitors in series, we’ve effectively spaced the plates farther apart because the spacing between the plates of the two capacitors adds together. So we don’t have 20µF, or even 10µF. We’ve got 5µF. The upshot of this is that we add series capacitor values the same way we add parallel resistor values. Both the product-over-sum and reciprocal methods are valid for adding capacitors in series.

Capacitors in series schematic/equation

It may seem that there’s no point to adding capacitors in series. But it should be pointed out that one thing we did get is twice as much voltage (or voltage ratings). Just like batteries, when we put capacitors together in series the voltages add up.

Adding capacitors in parallel is like adding resistors in series: the values just add up, no tricks. Why is this? Putting them in parallel effectively increases the size of the plates without increasing the distance between them. More area equals more capacitance. Simple.

Capacitors in parallel schematic/equation

Experiment Time – Part 3

What you’ll need:

Let’s see some series and parallel connected capacitors in action. This will be a little trickier than the resistor examples, because it’s harder to measure capacitance directly with a multimeter.

Let’s first talk about what happens when a capacitor charges up from zero volts. When current starts to go in one of the leads, an equal amount of current comes out the other. And if there’s no resistance in series with the capacitor, it can be quite a lot of current. In any case, the current flows until the capacitor starts to charge up to the value of the applied voltage, more slowly trickling off until the voltages are equal, when the current flow stops entirely.

As stated above, the current draw can be quite large if there’s no resistance in series with the capacitor, and the time to charge can be very short (like milliseconds or less). For this experiment, we want to be able to watch a capacitor charge up, so we’re going to use a 10kΩ resistor in series to slow the action down to a point where we can see it easily. But first we need to talk about what an RC time constant is.

Tau = R*C

What the above equation says is that one time constant in seconds (called tau) is equal to the resistance in ohms times the capacitance in farads. Simple? No? We shall demonstrate on the next page.

Experiment Time – Part 3, Continued…

For the first part of this experiment, we’re going to use one 10K resistor and one 100µF (which equals 0.0001 farads). These two parts create a time constant of 1 second:

Tau = 10kOhm * 100uF = 1 second

When charging our 100µF capacitor through a 10kΩ resistor, we can expect the voltage on the cap to rise to about 63% of the supply voltage in 1 time constant, which is 1 second. After 5 time constants (5 seconds in this case) the cap is about 99% charged up to the supply voltage, and it will follow a charge curve something like the plot below.

Capacitor charge time graph

Now that we know that stuff, we’re going to connect the circuit in the diagram (make sure to get the polarity right on that capacitor!).

Fritzing diagram, power off, cap in series with resistor, battery

With our multimeter set to measure volts, check the output voltage of the pack with the switch turned on. That’s our supply voltage, and it should be something around 4.5V (it’ll be a bit more if the batteries are new). Now connect the circuit, taking care that the switch on the battery pack is in the “OFF” position before plugging it into the breadboard. Also, take care that the red and black leads are going to the right places. If it’s more convenient, you can use alligator clips to attach the meter probes to the legs of the capacitor for measurement (you can also spread those legs out a bit to make it easier).

Once we’re satisfied that the circuit looks right and our meter’s on and set to read volts, flip the switch on the battery pack to “ON”. After about 5 seconds, the meter should read pretty close to the battery pack voltage, which demonstrates that the equation is right and we know what we’re doing. Now turn the switch off. It’s still holding that voltage pretty well, isn’t it? That’s because there’s no path for current to discharge the capacitor; we’ve got an open circuit. To discharge the cap, you can use another 10K resistor in parallel. After about 5 seconds, it will be back to pretty close to zero.

Experiment Time – Part 3, Even More…

Now we’re on to the interesting parts, starting with connecting two capacitors in series. Remember that we said the result of which would be similar to connecting two resistors in parallel. If this is true, we can expect (using product-over-sum)

C = 100uF*100uF/(100uF+100uF) = 50uF

What’s that going to do to our time constant?

Tau = 0.5 seconds

Experiment 3.2 fritzing diagram

With that in mind, plug in another capacitor in series with the first, make sure the meter is reading zero volts (or there-abouts) and flip the switch to “ON”. Did it take about half as much time to charge up to the battery pack voltage? That’s because there’s half as much capacitance. The electron gas tank got smaller, so it takes less time to charge it up. A third capacitor is suggested for this experiment just to prove the point, but we’re betting the reader can see the writing on the wall.

Now we’ll try capacitors in parallel, remembering that we said earlier that this would be like adding resistors in series. If that’s true, then we can expect 200µF, right? Then our time constant becomes

Tau = 2 seconds

This means that it will now take about 10 seconds to see the parallel capacitors charge up to the supply voltage of 4.5V.

Frizing diagram: caps in parallel

For the proof, start with our original circuit of one 10kΩ resistor and one 100µF capacitor in series, as hooked up in the first diagram for this experiment. We already know that the capacitor is going to charge up in about 5 seconds. Now add a second capacitor in parallel. Make sure the meter is reading close to zero volts (discharge through a resistor if it isn’t reading zero), and flip the switch on the battery pack to “ON”. Takes a long time, doesn’t it? Sure enough, we made the electron gas tank bigger and now it takes longer to fill it up. To prove it to yourself, try adding the third 100µF capacitor, and watch it charge for a good, long time.

Series and Parallel Inductors

Series and Parallel Inductors

Cases where inductors need to be added either in series or in parallel are rather rare, but not unheard of. In any case, let’s address them just to be complete.

In a nutshell they add just like resistors do, which is to say they add with a plus sign when in series, and with product-over-sum when in parallel. The tricky part comes when they are placed close together so as to have interacting magnetic fields, whether intentionally or not. For this reason, it is preferable to have a single component rather than two or more, though most inductors are shielded to prevent interacting magnetic fields.

In any case, suffice it to say that they add like resistors do. More information than that regarding inductors is well beyond the scope of this tutorial.

Resources and Going Further

Now that you’re familiar with the basics of serial and parallel circuits, why not check out some of these tutorials?

  • Voltage Dividers – One of the most basic, and recurring circuits is the voltage divider. This is a circuit which really builds upon the concepts explored in this tutorial.
  • What is an Arduino? – Now that you’ve got the basics of circuits under your belt, you could head directly to learning about microcontrollers with one of the most popular platforms out there: Arduino.
  • Switch Basics – We’ve talked about some of the more basic circuit elements in this tutorial, but this wasn’t one of them. Switches are a critical component in just about every electronics project out there. Learn all about switches in this tutorial
  • Sewing with Conductive Thread – Circuits don’t have to be all breadboards and wire. E-textiles uses conductive thread to sew lights and other electronics into clothing or other fabric.

Resistors

Take a Stance, The Resist Stance

Resistors – the most ubiquitous of electronic components. They are a critical piece in just about every circuit. And they play a major role in our favorite equation, Ohm’s Law.

resistors

In this, our pièce de résistance, we’ll cover:

  • What is a resistor?!
  • Resistor units
  • Resistor circuit symbol(s)
  • Resistors in series and parallel
  • Different variations of resistors
  • Color coding decoding
  • Surface mount resistor decoding
  • Example resistor applications

Consider reading…

Some of the concepts in this tutorial build on previous electronics knowledge. Before jumping into this tutorial, consider reading (at least skimming) these first:


Resistor Basics

Resistors are electronic components which have a specific, never-changing electrical resistance. The resistor’s resistance limits the flow of electrons through a circuit.

They are passive components, meaning they only consume power (and can’t generate it). Resistors are usually added to circuits where they complement active components like op-amps, microcontrollers, and other integrated circuits. Commonly resistors are used to limit current, divide voltages, and pull-up I/O lines.

Resistor units

The electrical resistance of a resistor is measured in ohms. The symbol for an ohm is the greek capital-omega: Ω. The (somewhat roundabout) definition of 1Ω is the resistance between two points where 1 volt (1V) of applied potential energy will push 1 ampere (1A) of current.

As SI units go, larger or smaller values of ohms can be matched with a prefix like kilo-, mega-, or giga-, to make large values easier to read. It’s very common to see resistors in the kilohm (kΩ) and megaohm (MΩ) range (much less common to see miliohm (mΩ) resistors). For example, a 4,700Ω resistor is equivalent to a 4.7kΩ resistor, and a 5,600,000Ω resistor can be written as 5,600kΩ or (more commonly as) 5.6MΩ.

Schematic symbol

All resistors have two terminals, one connection on each end of the resistor. When modeled on a schematic, a resistor will show up as one of these two symbols:

Resistor schematic symbols

Two common resistor schematic symbols. R1 is an American-style 1kΩ resistor, and R2 is an international-style 47kΩ resistor.

The terminals of the resistor are each of the lines extending from the squiggle (or rectangle). Those are what connect to the rest of the circuit.

The resistor circuit symbols are usually enhanced with both a resistance value and a name. The value, displayed in ohms, is obviously critical for both evaluating and actually constructing the circuit. The name of the resistor is usually an R preceding a number. Each resistor in a circuit should have a unique name/number. For example, here’s a few resistors in action on a 555 timer circuit:

Example schematic with resistors - a 555 timer

In this circuit, resistors play a key role in setting the frequency of the 555 timer’s output. Another resistor (R3) limits the current through an LED.


Types of Resistors

Resistors come in a variety of shapes and sizes. They might be through-hole or surface-mount. They might be a standard, static resistor, a pack of resistors, or a special variable resistor.

Termination and mounting

Resistors will come in one of two termination-types: through-hole or surface-mount. These types of resistors are usually abbreviated as either PTH (plated through-hole) or SMD/SMT (surface-mount technology or device).

Through-hole resistors come with long, pliable leads which can be stuck into a breadboard or hand-soldered into a prototyping board or printed circuit board (PCB). These resistors are usually more useful in breadboarding, prototyping, or in any case where you’d rather not solder tiny, little 0.6mm-long SMD resistors. The long leads usually require trimming, and these resistors are bound to take up much more space than their surface-mount counterparts.

The most common through-hole resistors come in an axial package. The size of an axial resistor is relative to its power rating. A common ½W resistor measures about 9.2mm across, while a smaller ¼W resistor is about 6.3mm long.

1/4 and 1/2 watt resistors

A half-watt (½W) resistor (above) sized up to a quarter-watt (¼W).

Surface-mount resistors are usually tiny black rectangles, terminated on either side with even smaller, shiny, silver, conductive edges. These resistors are intended to sit on top of PCBs, where they’re soldered onto mating landing pads. Because these resistors are so small, they’re usually set into place by a robot, and sent through an oven where solder melts and holds them in place.

SMD resistor on a quarter

A tiny 0603 330Ω resistor hovering over shiny George Washington’s nose on top of a U.S. quarter.

SMD resistors come in standardized sizes; usually either 0805 (0.8mm long by 0.5mm wide), 0603, or 0402. They’re great for mass circuit-board-production, or in designs where space is a precious commodity. They take a steady, precise hand to manually solder, though!

Resistor composition

Resistors can be constructed out of a variety of materials. Most common, modern resistors are made out of either a carbon, metal, or metal-oxide film. In these resistors, a thin film of conductive (though still resistive) material is wrapped in a helix around and covered by an insulating material. Most of the standard, no-frills, through-hole resistors will come in a carbon-film or metal-film composition.

Peeled away view of carbon-film resistors

Peek inside the guts of a few carbon-film resistors. Resistance values from top to bottom: 27Ω, 330Ω and a 3.3MΩ. Inside the resistor, a carbon film is wrapped around an insulator. More wraps means a higher resistance. Pretty neat!

Other through-hole resistors might be wirewound or made of super-thin metallic foil. These resistors are usually more expensive, higher-end components specifically chosen for their unique characteristics like a higher power-rating, or maximum temperature range.

Surface-mount resistors are usually either thick or thin-film variety. Thick-film is usually cheaper but less precise than thin. In both resistor types, a small film of resistive metal alloy is sandwiched between a ceramic base and glass/epoxy coating, and then connected to the terminating conductive edges.

Special resistor packages

There are a variety of other, special-purpose resistors out there. Resistors may come in pre-wired packs of five-or-so resistor arrays. Resistors in these arrays may share a common pin, or be set up as voltage dividers.

Resistor Network

An array of five 330Ω resistors, all tied together at one end.

Resistors don’t have to be static either. Variable resistors, known as rheostats, are resistors which can be adjusted between a specific range of values. Similar to the rheostat is the potentiometer. Pots connect two resistors internally, in series, and adjust a center tap between them creating an adjustable voltage divider. These variable resistors are often used for inputs, like volume knobs, which need to be adjustable.

A smattering of potentiometers

A smattering of potentiometers. From top-left, clockwise: a standard 10k trimpot, 2-axis joystick, softpot, slide pot, classic right-angle, and a breadboard friendly 10k trimpot.


Decoding Resistor Markings

Though they may not display their value outright, most resistors are marked to show what their resistance is. PTH resistors use a color-coding system (which really adds some flair to circuits), and SMD resistors have their own value-marking system.

Decoding the color bands

Through-hole, axial resistors usually use the color-band system to display their value. Most of these resistors will have four bands of color circling the resistor.

Resistors showing their stripes

The first two bands indicate the two most-significant digits of the resistor’s value. The third band is a weight value, which multiplies the two significant digits by a power of ten.

The final band indicates the tolerance of the resistor. The tolerance explains how much more or less the actual resistance of the resistor can be compared to what its nominal value is. No resistor is made to perfection, and different manufacturing processes will result in better or worse tolerances. For example, a 1kΩ resistor with 5% tolerance could actually be anywhere between 0.95kΩ and 1.05kΩ.

How do you tell which band is first and last? The last, tolerance band is often clearly separated from the value bands, and usually it’ll either be silver or gold.

Here’s a table of each of the colors and which value, multiplier or tolerance they represent:

Color Digit value Multiplier Multiplied Out Tolerance
Black 0 100 1
Brown 1 101 10
Red 2 102 100
Orange 3 103 1,000
Yellow 4 104 10000
Green 5 105 100,000
Blue 6 106 1,000,000
Violet 7 107 10,000,000
Gray 8 108 100,000,000
White 9 109 1,000,000,000
Gold ±5%
Silver ±10%

Here’s an example of a 4.7kΩ resistor with four color bands:

Close-up of a 4.7kOhm resistor

When decoding the resistor color bands, consult a resistor color code table like the one above. For the first two bands, find that color’s corresponding digit value. The 4.7kΩ resistor has color bands of yellow and violet to begin – which have digit values of 4 and 7 (47). The third band of the 4.7kΩ is red, which indicates that the 47 should be multiplied by 102 (or 100). 47 times 100 is 4,700!

If you’re trying to commit the color band code to memory, a mnemonic device might help. There are a handful of (sometimes unsavory) mnemonics out there, to help remember the resistor color code. A good one, which spells out the difference between black and brown is:

Big brown rabbits often yield great big vocal groans when gingerly snapped.”

Or, if you remember “ROY G. BIV”, subtract the indigo (poor indigo, no one remembers indigo), and add black and brown to the front and gray and white to the back of the classic rainbow color-order.

Color Code Calculator

If you’d rather skip the math (we won’t judge :), and just use a handy calculator, give this a try!

 

Band 1 Band 2 Band 3 Band 4
Value 1 (MSV) Value 2 Weight Tolerance

Resistance:

1,000 Ω ±5%

Decoding surface-mount markings

SMD resistors, like those in 0603 or 0805 packages, have their own way of displaying their value. There are a few common marking methods you’ll see on these resistors. They’ll usually have three to four characters – numbers or letters – printed on top of the case.

If the three characters you’re seeing are all numbers, you’re probably looking at an E24 marked resistor. These markings actually share some similarity with the color-band system used on the PTH resistors. The first two numbers represent the first two most-significant digits of the value, the last number represents a magnitude.

Examples of E-24 marked SMD resistors

In the above example picture, resistors are marked 104, 105, 205, 751, and 754. The resistor marked with 104 should be 100kΩ (10×104), 105 would be 1MΩ (10×105), and 205 is 2MΩ (20×105). 751 is 750Ω (75×101), and 754 is 750kΩ (75×104).

Another common coding system is E96, and it’s the most cryptic of the bunch. E96 resistors will be marked with three characters – two numbers at the beginning and a letter at the end. The two numbers tell you the first three digits of the value, by corresponding to one of the not-so-obvious values on this lookup table.

Code Value Code Value Code Value Code Value Code Value Code Value
01 100 17 147 33 215 49 316 65 464 81 681
02 102 18 150 34 221 50 324 66 475 82 698
03 105 19 154 35 226 51 332 67 487 83 715
04 107 20 158 36 232 52 340 68 499 84 732
05 110 21 162 37 237 53 348 69 511 85 750
06 113 22 165 38 243 54 357 70 523 86 768
07 115 23 169 39 249 55 365 71 536 87 787
08 118 24 174 40 255 56 374 72 549 88 806
09 121 25 178 41 261 57 383 73 562 89 825
10 124 26 182 42 267 58 392 74 576 90 845
11 127 27 187 43 274 59 402 75 590 91 866
12 130 28 191 44 280 60 412 76 604 92 887
13 133 29 196 45 287 61 422 77 619 93 909
14 137 30 200 46 294 62 432 78 634 94 931
15 140 31 205 47 301 63 442 79 649 95 953
16 143 32 210 48 309 64 453 80 665 96 976

The letter at the end represents a multiplier, matching up to something on this table:

Letter Multiplier Letter Multiplier Letter Multiplier
Z 0.001 A 1 D 1000
Y or R 0.01 B or H 10 E 10000
X or S 0.1 C 100 F 100000

Resistors marked with E-96 codes

So a 01C resistor is our good friend, 10kΩ (100×100), 01B is 1kΩ (100×10), and 01D is 100kΩ. Those are easy, other codes may not be. 85A from the picture above is 750Ω (750×1) and 30C is actually 20kΩ.


Power Rating

The power rating of a resistor is one of the more hidden values. Nevertheless it can be important, and it’s a topic that’ll come up when selecting a resistor type.

Power is the rate at which energy is transformed into something else. It’s calculated by multiplying the voltage difference across two points by the current running between them, and is measured in units of a watt (W). Light bulbs, for example, power electricity into light. But a resistor can only turn electrical energy running through it into heat. Heat isn’t usually a nice playmate with electronics; too much heat leads to smoke, sparks, and fire!

Every resistor has a specific maximum power rating. In order to keep the resistor from heating up too much, it’s important to make sure the power across a resistor is kept under it’s maximum rating. The power rating of a resistor is measured in watts, and it’s usually somewhere between ⅛W (0.125W) and 1W. Resistors with power ratings of more than 1W are usually referred to as power resistors, and are used specifically for their power dissipating abilities.

Finding a resistor’s power rating

A resistor’s power rating can usually be deduced by observing its package size. Standard through-hole resistors usually come with ¼W or ½W ratings. More special purpose, power resistors might actually list their power rating on the resistor.

Some examples of power resistors

These power resistors can handle a lot more power before they blow. From top-right to bottom-left there are examples of 25W, 5W and 3W resistors, with values of 2Ω, 3Ω 0.1Ω and 22kΩ. Smaller power-resistors are often used to sense current.

The power ratings of surface mount resistors can usually be judged by their size as well. Both 0402 and 0603-size resistors are usually rated for 1/16W, and 0805’s can take 1/10W.

Measuring power across a resistor

Power is usually calculated by multiplying voltage and current (P = IV). But, by applying Ohm’s law, we can also use the resistance value in calculating power. If we know the current running through a resistor, we can calculate the power as:

P=I^2*R

Or, if we know the voltage across a resistor, the power can be calculated as:

P=V^2/R


Series and Parallel Resistors

Resistors are paired together all the time in electronics, usually in either a series or parallel circuit. When resistors are combined in series or parallel, they create a total resistance, which can be calculated using one of two equations. Knowing how resistor values combine comes in handy if you need to create a specific resistor value.

Series resistors

When connected in series resistor values simply add up.

Schematic of resistors in series

Equation for adding resistors in series

N resistors in series. The total resistance is the sum of all series resistors.

So, for example, if you just have to have a 12.33kΩ resistor, seek out some of the more common resistor values of 12kΩ and 330Ω, and butt them up together in series.

Parallel resistors

Finding the resistance of resistors in parallel isn’t quite so easy. The total resistance of N resistors in parallel is the inverse of the sum of all inverse resistances. This equation might make more sense than that last sentence:

Schematic of resistors in parallel

Equation for adding resistors in parallel

N resistors in parallel. To find the total resistance, invert each resistance value, add them up, and then invert that.

(The inverse of resistance is actually called conductance, so put more succinctly: the conductance of parallel resistors is the sum of each of their conductances).

As a special case of this equation: if you have just two resistors in parallel, their total resistance can be calculated with this slightly-less-inverted equation:

Equation for calculating two resistors in parallel

As an even more special case of that equation, if you have two parallel resistors of equal value the total resistance is half of their value. For example, if two 10kΩ resistors are in parallel, their total resistance is 5kΩ.

A shorthand way of saying two resistors are in parallel is by using the parallel operator: ||. For example, if R1 is in parallel with R2, the conceptual equation could be written as R1||R2. Much cleaner, and hides all those nasty fractions!

Resistor networks

As a special introduction to calculating total resistances, electronics teachers just love to subject their students to finding that of crazy, convoluted resistor networks.

A tame resistor network question might be something like: “what’s the resistance from terminals A to B in this circuit?”

An example of a resistor network

To solve such a problem, start at the back-end of the circuit and simplify towards the two terminals. In this case R7, R8and R9 are all in series and can be added together. Those three resistors are in parallel with R6, so those four resistors could be turned into one with a resistance of R6||(R7+R8+R9). Making our circuit:

Resistor network simplified

Now the four right-most resistors can be simplified even further. R4, R5 and our conglomeration of R6 – R9 are all in series and can be added. Then those series resistors are all in parallel with R3.

Resistor network further simplified

And that’s just three series resistors between the A and B terminals. Add ‘em on up! So the total resistance of that circuit is: R1+R2+R3||(R4+R5+R6||(R7+R8+R9)).


Example Applications

Resistors exist in just about every electronic circuit ever. Here are a few examples of circuits, which heavily depend on our resistor friends.

LED Current Limiting

Resistors are key in making sure LEDs don’t blow up when power is applied. By connecting a resistor in series with an LED, current flowing through the two components can be limited to a safe value.

Current limiting resistor schematic

When sizing out a current-limiting resistor, look for two characteristic values of the LED: the typical forward voltage, and the maximum forward current. The typical forward voltage is the voltage which is required to make an LED light up, and it varies (usually somewhere between 1.7V and 3.4V) depending upon the color of the LED. The maximum forward current is usually around 20mA for basic LEDs; continuous current through the LED should always be equal to or less than that current rating.

Once you’ve gotten ahold of those two values, you can size up a current-limiting resistor with this equation:

Current limiting resistor = (Vs-Vf)/If

VS is the source voltage – usually a battery or power supply voltage. VF and IF are the LED’s forward voltage and the desired current that runs through it.

For example, assume you have a 9V battery to power an LED. If your LED is red, it might have a forward voltage around 1.8V. If you want to limit the current to 10mA, use a series resistor of about 720Ω.

Current limiting example equation R=(9-1.8)/.010

Voltage Dividers

A voltage divider is a resistor circuit which turns a large voltage into a smaller one. Using just two resistors in series, an output voltage can be created that’s a fraction of the input voltage.

Here’s the voltage divider circuit:

Voltage divider circuit

Two resistors, R1 and R2, are connected in series and a voltage source (Vin) is connected across them. The voltage from Vout to GND can be calculated as:

Voltage divider equation

For example, if R1 was 1.7kΩ and R2 was 3.3kΩ, a 5V input voltage could be turned into 3.3V at the Vout terminal.

Voltage dividers are very handy for reading resistive sensors, like photocells, flex sensors, and force-sensitive resistors. One half of the voltage divider is the sensor, and the part is a static resistor. The output voltage between the two components is connected to an analog-to-digital converter on a microcontroller (MCU) to read the sensor’s value.

A photocell and resistor make a light sensor

Here a resistor R1 and a photocell create a voltage divider to create a variable voltage output.

Pull-up Resistors

A pull-up resistor is used when you need to bias a microcontroller’s input pin to a known state. One end of the resistor is connected to the MCU’s pin, and the other end is connected to a high voltage (usually 5V or 3.3V).

Without a pull-up resistor, inputs on the MCU could be left floating. There’s no guarantee that a floating pin is either high (5V) or low (0V).

Pull-up resistors are often used when interfacing with a button or switch input. The pull-up resistor can bias the input-pin when the switch is open. And it will protect the circuit from a short when the switch is closed.

A resistor pulling up a button input

In the circuit above, when the switch is open the MCU’s input pin is connected through the resistor to 5V. When the switch closes, the input pin is connected directly to GND.

The value of a pull-up resistor doesn’t usually need to be anything specific. But it should be high enough that not too much power is lost if 5V or so is applied across it. Usually values around 10kΩ work well.


Resources and Going Further

Now that you’re a budding expert on all things resistor, how ‘bout exploring some more fundamental electronics concepts! Resistors certainly aren’t the only basic component we use in electronics, there’s also:

Or maybe you’d like to further explore resistor applications?

Capacitors

Introduction

A capacitor is a two-terminal, electrical component. Along with resistors and inductors, they are one of the most fundamental passive components we use. You would have to look very hard to find a circuit which didn’t have a capacitor in it.

Capacitor variety hour

What makes capacitors special is their ability to store energy; they’re like a fully charged electric battery. Caps, as we usually refer to them, have all sorts of critical applications in circuits. Common applications include local energy storage, voltage spike suppression, and complex signal filtering.

Covered in this Tutorial

In this tutorial, we’ll be examining all sorts of capacitor-related topics, including:

  • How a capacitor is made
  • How a capacitor works
  • Units of capacitance
  • Types of capacitors
  • How to recognize capacitors
  • How capacitance combines in series and parallel
  • Common capacitor applications

Suggested Reading

Some of the concepts in this tutorial build on previous electronics knowledge. Before jumping into this tutorial, consider reading (at least skimming) these first:


Symbols and Units

Circuit Symbols

There are two common ways to draw a capacitor in a schematic. They always have two terminals, which go on to connect to the rest of the circuit. The capacitors symbol consists of two parallel lines, which are either flat or curved; both lines should be parallel to each other, close, but not touching (this is actually representative of how the capacitor is made. Hard to describe, easier to just show:

Capacitor circuit symbols

(1) and (2) are standard capacitor circuit symbols. (3) is an example of capacitors symbols in action in a voltage regulator circuit.

The symbol with the curved line (#2 in the photo above) indicates that the capacitor is polarized, meaning it’s probably an electrolytic capacitor. More on that in the types of capacitors section of this tutorial.

Each capacitor should be accompanied by a name – C1, C2, etc.. – and a value. The value should indicate the capacitance of the capacitor; how many farads it has. Speaking of farads…

Capacitance Units

Not all capacitors are created equal. Each capacitor is built to have a specific amount of capacitance. The capacitance of a capacitor tells you how much charge it can store, more capacitance means more capacity to store charge. The standard unit of capacitance is called the farad, which is abbreviated F.

It turns out that a farad is a lot of capacitance, even 0.001F (1 milifarad – 1mF) is a big capacitor. Usually you’ll see capacitors rated in the pico- (10-12) to microfarad (10-6) range.

 

Prefix Name Abbreviation Weight Equivalent Farads
Picofarad pF 10-12 0.000000000001 F
Nanofarad nF 10-9 0.000000001 F
Microfarad µF 10-6 0.000001 F
Milifarad mF 10-3 0.001 F
Kilofarad kF 103 1000 F

When you get into the farad to kilofarad range of capacitance, you start talking about special caps called super or ultra-capacitors.


Capacitor Theory

Note: The stuff on this page isn’t completely critical for electronics beginners to understand…and it gets a little complicated towards the end. We recommend reading the How a Capacitor is Made section, the others could probably be skipped if they give you a headache.

How a Capacitor Is Made

The schematic symbol for a capacitor actually closely resembles how it’s made. A capacitor is created out of two metal plates and an insulating material called a dielectric. The metal plates are placed very close to each other, in parallel, but the dielectric sits between them to make sure they don’t touch.

Internal capacitor view

Your standard capacitor sandwich: two metal plates separated by an insulating dielectric.

The dielectric can be made out of all sorts of insulating materials: paper, glass, rubber, ceramic, plastic, or anything that will impede the flow of current.

The plates are made of a conductive material: aluminum, tantalum, silver, or other metals. They’re each connected to a terminal wire, which is what eventually connects to the rest of the circuit.

The capacitance of a capacitor – how many farads it has – depends on how it’s constructed. More capacitance requires a larger capacitor. Plates with more overlapping surface area provide more capacitance, while more distance between the plates means less capacitance. The material of the dielectric even has an effect on how many farads a cap has. The total capacitance of a capacitor can be calculated with the equation:

C=er*A/(4*pi*d)

Where εr is the dielectric’s relative permittivity (a constant value determined by the dielectric material), A is the amount of area the plates overlap each other, and d is the distance between the plates.

How a Capacitor Works

Electric current is the flow of electric charge, which is what electrical components harness to light up, or spin, or do whatever they do. When current flows into a capacitor, the charges get “stuck” on the plates because they can’t get past the insulating dielectric. Electrons – negatively charged particles – are sucked into one of the plates, and it becomes overall negatively charged. The large mass of negative charges on one plate pushes away like charges on the other plate, making it positively charged.

Charged Cap Drawing

The positive and negative charges on each of these plates attract each other, because that’s what opposite charges do. But, with the dielectric sitting between them, as much as they want to come together, the charges will forever be stuck on the plate (until they have somewhere else to go). The stationary charges on these plates create an electric field, which influence electric potential energy and voltage. When charges group together on a capacitor like this, the cap is storing electric energy just as a battery might store chemical energy.

Charging and Discharging

When positive and negative charges coalesce on the capacitor plates, the capacitor becomes charged. A capacitor can retain its electric field – hold its charge – because the positive and negative charges on each of the plates attract each other but never reach each other.

At some point the capacitor plates will be so full of charges that they just can’t accept any more. There are enough negative charges on one plate that they can repel any others that try to join. This is where the capacitance (farads) of a capacitor comes into play, which tells you the maximum amount of charge the cap can store.

If a path in the circuit is created, which allows the charges to find another path to each other, they’ll leave the capacitor, and it will discharge.

For example, in the circuit below, a battery can be used to induce an electric potential across the capacitor. This will cause equal but opposite charges to build up on each of the plates, until they’re so full they repel any more current from flowing. An LED placed in series with the cap could provide a path for the current, and the energy stored in the capacitor could be used to briefly illuminate the LED.

capacitor charge/discharge example

Calculating Charge, Voltage, and Current

A capacitor’s capacitance – how many farads it has – tells you how much charge it can store. How much charge a capacitor is currently storing depends on the potential difference (voltage) between its plates. This relationship between charge, capacitance, and voltage can be modeled with this equation:

Q=CV

Charge (Q) stored in a capacitor is the product of its capacitance (C) and the voltage (V) applied to it.

The capacitance of a capacitor should always be a constant, known value. So we can adjust voltage to increase or decrease the cap’s charge. More voltage means more charge, less voltage…less charge.

That equation also gives us a good way to define the value of one farad. One farad (F) is the capacity to store one unit of energy (coulombs) per every one volt.

Calculating Current

We can take the charge/voltage/capacitance equation a step further to find out how capacitance and voltage affect current, because current is the rate of flow of charge. The gist of a capacitor’s relationship to voltage and current is this: the amount of current through a capacitor depends on both the capacitance and how quickly the voltage is rising or falling. If the voltage across a capacitor swiftly rises, a large positive current will be induced through the capacitor. A slower rise in voltage across a capacitor equates to a smaller current through it. If the voltage across a capacitor is steady and unchanging, no current will go through it.

(This is ugly, and gets into calculus. It’s not all that necessary until you get into time-domain analysis, filter-design, and other gnarly stuff, so skip ahead to the next page if you’re not comfortable with this equation.) The equation for calculating current through a capacitor is:

i=Cdv/dt

The dV/dt part of that equation is a derivative (a fancy way of saying instantaneous rate) of voltage over time, it’s equivalent to saying “how fast is voltage going up or down at this very moment”. The big takeaway from this equation is that if voltage is steady, the derivative is zero, which means current is also zero. This is why current cannot flow through a capacitor holding a steady, DC voltage.


Types of Capacitors

There are all sorts of capacitor types out there, each with certain features and drawbacks which make it better for some applications than others.

When deciding on capacitor types there are a handful of factors to consider:

  • Size – Size both in terms of physical volume and capacitance. It’s not uncommon for a capacitor to be the largest component in a circuit. They can also be very tiny. More capacitance typically requires a larger capacitor.
  • Maximum voltage – Each capacitor is rated for a maximum voltage that can be dropped across it. Some capacitors might be rated for 1.5V, others might be rated for 100V. Exceeding the maximum voltage will usually result in destroying the capacitor.
  • Leakage current – Capacitors aren’t perfect. Every cap is prone to leaking some tiny amount of current through the dielectric, from one terminal to the other. This tiny current loss (usually nanoamps or less) is called leakage. Leakage causes energy stored in the capacitor to slowly, but surely drain away.
  • Equivalent series resistance (ESR) – The terminals of a capacitor aren’t 100% conductive, they’ll always have a tiny amount of resistance (usually less than 0.01Ω) to them. This resistance becomes a problem when a lot of current runs through the cap, producing heat and power loss.
  • Tolerance – Capacitors also can’t be made to have an exact, precise capacitance. Each cap will be rated for their nominal capacitance, but, depending on the type, the exact value might vary anywhere from ±1% to ±20% of the desired value.

Ceramic Capacitors

The most commonly used and produced capacitor out there is the ceramic capacitor. The name comes from the material from which their dielectric is made.

Ceramic capacitors are usually both physically and capacitance-wise small. It’s hard to find a ceramic capacitor much larger than 10µF. A surface-mount ceramic cap is commonly found in a tiny 0402 (0.4mm x 0.2mm), 0603 (0.6mm x 0.3mm) or 0805 package. Through-hole ceramic caps usually look like small (commonly yellow or red) bulbs, with two protruding terminals.

Ceramic Capacitors

Two caps in a through-hole, radial package; a 22pF cap on the left, and a 0.1µF on the right. In the middle, a tiny 0.1µF 0603 surface-mount cap.

Compared to the equally popular electrolytic caps, ceramics are a more near-ideal capacitor (much lower ESR and leakage currents), but their small capacitance can be limiting. They are usually the least expensive option too. These caps are well-suited for high-frequency coupling and decoupling applications.

Aluminum and Tantalum Electrolytic

Electrolytics are great because they can pack a lot of capacitance into a relatively small volume. If you need a capacitor in the range of 1µF-1mF, you’re most likely to find it in an electrolytic form. They’re especially well suited to high-voltage applications because of their relatively high maximum voltage ratings.

Aluminum electrolytic capacitors, the most popular of the electrolytic family, usually look like little tin cans, with both leads extending from the bottom.

Electrolytic caps

An assortment of through-hole and surface-mount electrolytic capacitors. Notice each has some method for marking the cathode (negative lead).

Unfortunately, electrolytic caps are usually polarized. They have a positive pin – the anode – and a negative pin called the cathode. When voltage is applied to an electrolytic cap, the anode must be at a higher voltage than the cathode. The cathode of an electrolytic capacitor is usually identified with a ‘-’ marking, and a colored strip on the case. The leg of the anode might also be slightly longer as another indication. If voltage is applied in reverse on an electrolytic cap, they’ll fail spectacularly (making a pop and bursting open), and permanently. After popping an electrolytic will behave like a short circuit.

These caps also notorious for leakage – allowing small amounts of current (on the order of nA) to run through the dielectric from one terminal to the other. This makes electrolytic caps less-than-ideal for energy storage, which is unfortunate given their high capacity and voltage rating.

Supercapacitors

If you’re looking for a capacitor made to store energy, look no further than supercapacitors. These caps are uniquely designed to have very high capacitances, in the range of farads.

Supercapacitor

A 1F (!) supercapacitor. High capacitance, but only rated for 2.5V. Notice these are also polarized.

While they can store a huge amount of charge, supercaps can’t deal with very high voltages. This 10F supercap is only rated for 2.5V max. Any more than that will destroy it. Super caps are commonly placed in series to achieve a higher voltage rating (while reducing total capacitance).

The main application for supercapacitors is in storing and releasing energy, like batteries, which are their main competition. While supercaps can’t hold as much energy as an equally sized battery, they can release it much faster, and they usually have a much longer lifespan.

Others

Electrolytic and ceramic caps cover about 80% of the capacitor types out there (and supercaps only about 2%, but they’re super!). Another common capacitor type is the film capacitor, which features very low parasitic losses (ESR), making them great for dealing with very high currents.

There’s plenty of other less common capacitors. Variable capacitors can produce a range of capacitances, which makes them a good alternative to variable resistors in tuning circuits. Twisted wires or PCBs can create capacitance (sometimes undesired) because each consists of two conductors separated by an insulator. Leyden Jars – a glass jar filled with and surrounded by conductors – are the O.G. of the capacitor family. Finally, of course, flux capacitors (a strange combination of inductor and capacitor) are critical if you ever plan on traveling back to the glory days.


Capacitors in Series/Parallel

Much like resistors, multiple capacitors can be combined in series or parallel to create a combined equivalent capacitance. Capacitors, however, add together in a way that’s completely the opposite of resistors.

Capacitors in Parallel

When capacitors are placed in parallel with one another the total capacitance is simply the sum of all capacitances. This is analogous to the way resistors add when in series.

Capacitors in parallel add

So, for example, if you had three capacitors of values 10µF, 1µF, and 0.1µF in parallel, the total capacitance would be 11.1µF (10+1+0.1).

Capacitors in Series

Much like resistors are a pain to add in parallel, capacitors get funky when placed in series. The total capacitance of N capacitors in series is the inverse of the sum of all inverse capacitances.

Capacitors in series are the inverse of the sum of their inverses

If you only have two capacitors in series, you can use the “product-over-sum” method to calculate the total capacitance:

Equation for 2 capacitors in series Ctot=C1*C2/(C1+C2)

Taking that equation even further, if you have two equal-valued capacitors in series, the total capacitance is half of their value. For example two 10F supercapacitors in series will produce a total capacitance of 5F (it’ll also have the benefit of doubling the voltage rating of the total capacitor, from 2.5V to 5V).


Application Examples

There are tons of applications for this nifty little (actually they’re usually pretty large) passive component. To give you an idea of their wide range of uses, here are a few examples:

Decoupling (Bypass) Capacitors

A lot of the capacitors you see in circuits, especially those featuring an integrated circuit, are decoupling. A decoupling capacitor’s job is to supress high-frequency noise in power supply signals. They take tiny voltage ripples, which could otherwise be harmful to delicate ICs, out of the voltage supply.

In a way, decoupling capacitors act as a very small, local power supply for ICs (almost like an uninterupptable power supply is to computers). If the power supply very temporarily drops its voltage (which is actually pretty common, especially when the circuit it’s powering is constantly switching its load requirements), a decoupling capacitor can briefly supply power at the correct voltage. This is why these capacitors are also called bypass caps; they can temporarily act as a power source, bypassing the power supply.

Decoupling capacitors connect between the power source (5V, 3.3V, etc.) and ground. It’s not uncommon to use two or more different-valued, even different types of capacitors to bypass the power supply, because some capacitor values will be better than others at filtering out certain frequencies of noise.

Decoupling capacitor schematic

In this schematic, three decoupling capacitors are used to help reduce the noise in an accelerometer’s voltage supply. Two ceramic 0.1µF and one tantalum electrolytic 10µF split decoupling duties.

While it seems like this might create a short from power to ground, only high-frequency signals can run through the capacitor to ground. The DC signal will go to the IC, just as desired. Another reason these are called bypass capacitors is because the high frequencies (in the kHz-MHz range) bypass the IC, instead running through the capacitor to get to ground.

When physically placing decoupling capacitors, they should always be located as close as possible to an IC. The further away they are, they less effective they’ll be.

ADXL345 breakout decoupling caps

Here’s the physical circuit layout from the schematic above. The tiny, black IC is surrounded by two 0.1µF capacitors (the brown caps) and one 10µF electrolytic tantalum capacitor (the tall, black/grey rectangular cap).

To follow good engineering practice, always add at least one decoupling capacitor to every IC. Usually 0.1µF is a good choice, or even add some 1µF or 10µF caps. They’re a cheap addition, and they help make sure the chip isn’t subjected to big dips or spikes in voltage.

Power Supply Filtering

Diode rectifiers can be used to turn the AC voltage coming out of your wall into the DC voltage required by most electronics. But diodes alone can’t turn an AC signal into a clean DC signal, they need the help of capacitors! By adding a parallel capacitor to a bridge rectifier, a rectified signal like this:

Rectification pre-Cap

Can be turned into a near-level DC signal like this:

Rectification post-cap

Capacitors are stubborn components, they’ll always try to resist sudden changes in voltage. The filter capacitor will charge up as the rectified voltage increases. When the rectified voltage coming into the cap starts its rapid decline, the capacitor will access its bank of stored energy, and it’ll discharge very slowly, supplying energy to the load. The capacitor shouldn’t fully discharge before the input rectified signal starts to increase again, recharging the cap. This dance plays out many times a second, over-and-over as long as the power supply is in use.

Power supply circuit

An AC-to-DC power supply circuit. The filter cap (C1) is critical in smoothing out the DC signal sent to the load circuit.

If you tear apart any AC-to-DC power supply, you’re bound to find at least one rather large capacitor. Below are the guts of a 9V DC wall adapter. Notice any capacitors in there?

alt text

There might be more capacitors than you think! There are four electrolytic, tin-can-looking caps ranging from 47µF to 1000µF. The big, yellow rectangle in the foreground is a high-voltage 0.1µF polypropylene film cap. The blue disc-shaped cap and the little green one in the middle are both ceramics.

Energy Storage and Supply

It seems obvious that if a capacitor stores energy, one of it’s many applications would be supplying that energy to a circuit, just like a battery. The problem is capacitors have a much lower energy density than batteries; they just can’t pack as much energy as an equally sized chemical battery (but that gap is narrowing!).

The upside of capacitors is they usually lead longer lives than batteries, which makes them a better choice environmentally. They’re also capable of delivering energy much faster than a battery, which makes them good for applications which need a short, but high burst of power. A camera flash might get its power from a capacitor (which, in turn, was probably charged by a battery).

Battery or Capacitor?

Battery Capacitor
Capacity
Energy Density
Charge/Discharge Rate
Life Span

 

Signal Filtering

Capacitors have a unique response to signals of varying frequencies. They can block out low-frequency or DC signal-components while allowing higher frequencies to pass right through. They’re like a bouncer at a very exclusive club for high frequencies only.

Filtering signals can be useful in all sorts of signal processing applications. Radio receivers might use a capacitor (among other components) to tune out undesired frequencies.

Another example of capacitor signal filtering is passive crossover circuits inside speakers, which separate a single audio signal into many. A series capacitor will block out low frequencies, so the remaining high-frequency parts of the signal can go to the speaker’s tweeter. In the low-frequency passing, subwoofer circuit, high-frequencies can mostly be shunted to ground through the parallel capacitor.

Crossover schematic

A very simple example of an audio crossover circuit. The capacitor will block out low frequencies, while the inductor blocks out high frequencies. Each can be used to deliver the proper signal to tuned audio drivers.

De-rating

When working with capacitors, it’s important to design your circuits with capacitors that have a much higher tolerance than the potentially highest voltage spike in your system.

Here’s an excellent video from SparkFun Engineer Shawn about what happens to different types of capacitors when you fail to de-rate your capacitors and exceed their maximum voltage specs. You can read more about his experiments here.


Purchasing Capacitors

Store up on these little energy storage components or put them to work a beginning power supply kit.

Our recommendations:


Resources and Going Further

Whew. Feel like a capacitor expert?! Want to keep learning more about the fundamentals of electronics? If you haven’t already, consider reading about some of the other common electronics components:

Or maybe some of these tutorials will catch your attention?

How to Use a Breadboard

Introduction

Breadboards are one of the most fundamental pieces when learning how to build circuits. In this tutorial, you will learn a little bit about what breadboards are, why they are called breadboards, and how to use one. Once you are done you should have a basic understanding of how breadboards work and be able to build a basic circuit on a breadboard.

A Breadboard

Suggested Reading

Here are some tutorials and concepts you may want to explore before learning about breadboards:


History

If you wanted to build a circuit prior to the 1960s, chances are you would have used a technique called wire-wrap. Wire wrap is a process that involves wrapping wires around conductive posts attached to a perfboard (a.k.a. a protoboard). As you can see, the process can get rather complex very quickly.Although this method is still used today, there is something that makes prototyping much easier, breadboards!

wire-wrap circuit

A wire-wrap circuit (image courtesy of Wikipedia user Wikinaut)

What’s in a Name?

When you picture a breadboard in your head, you may envision a big piece of wood and a large loaf of freshly baked bread. You wouldn’t be too far off either.

A literal breadboard

Bread on a breadboard

So why do we call this electronic “circuit builder” a breadboard? Many years ago, when electronics were big and bulky, people would grab their mom’s breadboard, a few nails or thumbtacks, and start connecting wires onto the board to give themselves a platform on which to build their circuits.

Circuit built on literal breadboard

Circuit on an “original” breadboard (image courtesy of mischka and their awesome literal breadboard tutorial)

Since then, electronic components have gotten a lot smaller, and we’ve come up with better ways to connect circuits, making moms all over the world happy to have their breadboards back. However, we are stuck with the confusing name. Technically, these are still breadboards, but this discussion is going to be on modern, “solderless” breadboards.


Why Use Breadboards?

An electronics breadboard (as opposed to the type on which sandwiches are made) is actually referring to a solderless breadboard. These are great units for making temporary circuits and prototyping, and they require absolutely no soldering.

Prototyping is the process of testing out an idea by creating a preliminary model from which other forms are developed or copied, and it is one of the most common uses for breadboards. If you aren’t sure how a circuit will react under a given set of parameters, it’s best to build a prototype and test it out.

For those new to electronics and circuits, breadboards are often the best place to start. That is the real beauty of breadboards–they can house both the simplest circuit as well as very complex circuits. As you’ll see later in this tutorial, if your circuit outgrows its current breadboard, others can be be attached to accommodate circuits of all sizes and complexities.

Another common use of breadboards is testing out new parts, such as Integrated circuits (ICs). When you are trying to figure out how a part works and constantly rewiring things, you don’t want to have to solder your connections each time.

As mentioned, you don’t always want the circuit you build to be permanent. When trying to duplicate a customer’s problem, SparkFun’s Technical Support team will often use breadboards to build, test, and analyze the circuit. They can connect the parts the customer has, and once they’ve gotten the circuit setup and figured out the problem, they can take everything apart and put it aside for the next time they need to do some troubleshooting.

A circuit built on a solderless breadboard

A circuit built on a solderless breadboard


Anatomy of a Breadboard

The major features of a Breadboard

The major features of a Breadboard

The best way to explain how a breadboard works is to take it apart and see what’s inside. Using a smaller breadboard it’s easier to see just how they function.

Terminal Strips

Here we have a breadboard where the adhesive backing has been removed. You can see lots of horizontal rows of metal strips on the bottom of the breadboard.

SparkFun Mini Breadboard

A SparkFun Mini Breadboard from the top (left) and the same breadboard flipped over with the adhesive back removed (right).

The tops of the metal rows have little clips that hide under the plastic holes. These clips allow you to stick a wire or the leg of a component into the exposed holes on a breadboard, which then hold it in place.

Clip

A single strip of conductive metal removed from the above breadboard.

Once inserted that component will be electrically connected to anything else placed in that row. This is because the metal rows are conductive and allow current to flow from any point in that strip.

Notice that there are only five clips on this strip. This is typical on almost all breadboards. Thus, you can only have up to five components connected in one particular section of the breadboard. The row has ten holes, so why can you only connect five components? You’ll also notice that each horizontal row is separated by a ravine, or crevasse, in the middle of the breadboard. This ravine isolates both sides of a given row from one another, and they are not electrically connected. We’ll discuss the purpose of this in just a bit, but, for now, just know that each side of a given row is disconnected from the other, leaving you with five spots for components on either side.

LED in Breadboard

An LED inserted into a breadboard. Notice how each leg of the LED is placed on either side of the ravine. This prevents the connections to the LED from being shorted.

Power Rails

Now that we’ve seen how the connections in a breadboard are made, let’s look at a larger, more typical breadboard. Aside from horizontal rows, breadboards usually have what are called power rails that run vertically along the sides.

Front and back, medium breadboard with power rails exposed

A medium-size breadboard with the adhesive back removed to expose the power rails.

These power rails are metal strips that are identical to the ones that run horizontally, except they are, typically*, all connected. When building a circuit, you tend to need power in lots of different places. The power rails give you lots of easy access to power wherever you need it in your circuit. Usually they will be labeled with a ‘+’ and a ‘-’ and have a red and blue or black stripe, to indicate the positive and negative side.

It is important to be aware that the power rails on either side are not connected, so if you want the same power source on both sides, you will need to connect the two sides with some jumper wires. Keep in mind that the markings are there just as a reference. There is no rule that says you have to plug power into the ‘+’ rail and ground into the ‘-‘rail, though it’s good practice to keep everything in order.

Jumper wires connecting both sides of the power rails

Two jumper wires used to connect the power rails on both sides. Always attach the ‘+’ to ‘+’ and the ‘-’ to ‘-’.

DIP Support

Earlier we mentioned the ravine that isolates the two sides of a breadboard. This ravine serves a very important purpose. Many integrated circuits, often referred to as ICs or, simply, chips, are manufactured specifically to fit onto breadboards. In order to minimize the amount of space they take up on the breadboard, they come in what is known as a Dual in-line Package, or DIP.

These DIP chips (salsa anyone?) have legs that come out of both sides and fit perfectly over that ravine. Since each leg on the IC is unique, we don’t want both sides to be connected to each other. That is where the separation in the middle of the board comes in handy. Thus, we can connect components to each side of the IC without interfering with the functionality of the leg on the opposite side.

alt text

Two DIP ICs, the LM358 (top), a very common op-amp, and the ever-popular ATmega328 microcontroller (bottom).

Rows and Columns

You may have noticed that many breadboards have numbers and letters marked on various rows and columns. These don’t serve any purpose other than to help guide you when building your circuit. Circuits can get complicated quickly, and all it takes is one misplaced leg of a component to make the entire circuit malfunction or not work at all. If you know the row number of the connection you are trying to make, it makes it much simpler to plug a wire into that number rather than eyeballing it.

These are also helpful when using instruction booklets, such as the one found in the SparkFun Inventor’s Kit. Many books and guides have circuit diagrams for you to follow along while building your circuit. Just remember that the circuit you’re building doesn’t have to be in the exact same location on the breadboard as the one in the book. In fact, it doesn’t even have to look similar. As long as all the electrical connections are being made, you can build your circuit any way you’d like!

Binding Posts

Some breadboards come on a platform that has binding posts attached to it. These posts allow you to connect all kinds of different power sources to your breadboard. We’ll cover these more in the next section.

Other Features

When building your circuit, you are not confined to stay on just one breadboard. Some circuits will require a lot more space. Many breadboards have little nubbins and slots on the sides, and some even have them on the tops and bottoms. These allow you to connect multiple breadboards together to form the ultimate prototyping surface.

Four SparkFun mini breadboards connected togethe

Four SparkFun mini breadboards connected together.

Some breadboards also have an adhesive backing that allow you to stick them to many different surfaces. These can come in handy if you want to attach your breadboard to the inside on an enclosure or other project case.

*Some larger breadboards will often isolate one half of the breadboard’s power rails form the other half (think top and bottom half, not the sides). This is convenient if you have two different voltages with which you need to power your circuit, such as 3.3V and 5V. However, if you’re unaware whether the power rials are or aren’t isolated, it can often lead to issues while building your circuit. It’s always a good idea to use a multimeter to check for the absence or presence of continuity in your breadboard’s power rails.

Providing Power to a Breadboard

When it comes to providing power to you breadboard, there are numerous options.

Borrowing from Other Power Sources

If you are working with a development board such as an Arduino, then you can simply pull power from the Arduino’s female headers. The Arduino has multiple power and ground pins that you can connect to the power rails or other rows on a breadboard.

Sharing power with an Arduino

Connecting the Ground (GND) pin from an Arduino to a row on a mini breadboard. Now any leg or wire connected to that row will also be connected to Ground.

The Arduino usually gets its power from the USB port on a computer or an external power supply such as a battery pack or a wall wart.

Binding Posts

As mentioned in the previous section, some breadboards have binding posts that allow you to connect external power sources.

The first step to using the binding posts is to connect them to the breadboard using some jumper wires. Although it would seem that the posts are connected to the breadboard, they are not. If they were, you would be limited to where you could and couldn’t provide power. As we’ve seen, breadboards are meant to be totally customizable, so it would make sense that the binding posts are no different.

With that, we have to connect wires to the posts in order to connect them to the breadboard. To do that, unscrew the post until the hole going through it is exposed. Slide the stripped end of your jumper wire through the hole, and screw the post back down until the wire is firmly connected.

Conneting wire to the binding posts

Typically, you only need to connect a power and ground wire from the posts to the breadboard. If you need an alternate power source, you can use the third post.

Now your posts are connected to the the breadboard, but there is still no power. You can use many different methods to connect power to the posts, and, thus, to the breadboard.

Benchtop Power Supplies

Many electronics labs have benchtop power supplies that allow you to provide a wide range of voltage and current to your circuit. Using a banana connector you can provide power from the supply to the binding posts.

A breadboard being powered through the binding posts from banana cables

A breadboard being powered through the binding posts from banana cables.

Alternatively, you could use alligator clips, IC hooks, or any other cables with a banana connection to hook your breadboard up to a number of different supplies.

Another method of using the binding posts is to solder a barrel jack to some wires, and then connect them to the binding posts. This is a more advanced technique, and it requires some intermediate soldering skills.

A breadboard being powered through the binding posts with a barrel jack

The barrel jack is soldered to two wires that share the same holes on the binding posts as the wires going to the breadboard. If your breadboard doesn’t have binding posts, you could just plug the wires from the barrel jack directly into the power rails.

Breadboard Power Supplies

Yet another method for powering your breadboard is to use one of the many breadboard power supplies available. SparkFun carries a number of kits and boards that you can use to plug power directly into your breadboard. Some allow you to plug a wall wart directly into the breadboard. Others allow you to pull power directly from your computer via the USB connections. And, almost all of them have the capability to adjust the voltage, giving you a full range of the common voltages needed when building circuits.

A SparkFun USB Breadboard Power Supply

A SparkFun USB Breadboard Power Supply that pulls power from your computer’s USB and has the option to choose between 3.3V and 5V.


Building Your First Breadboard Circuit

Now that we’re familiar with the internals of a breadboard and how to provide power to them, what do we do with them? We are going to start with a simple circuit.

What You’ll Need

Here is a parts list to follow along with this circuit. If you have other electronic bits and pieces, feel free to use them and change the circuit up. Remember, there is often more ways than one to build any given circuit. Some even have dozens of different ways that you can build them.

This wish list assumes you don’t have any parts/tools and is generous with quantities etc. For example, you only need one LED for this project, but the pack listed has 20 LEDs in it. The same is true with the hook-up wire. You don’t need that much (or all those colors), but if you keep playing with circuits, it could come in handy. If you don’t want the higher quantities check the bottom of the product pages in the section called “Related Products” and you should be able to find smaller quantities. Also, the breadboard power supply doesn’t have headers, if you know how to solder and have the tools, solder the headers on yourself. If not, solderless headers have been included in the wishlist as well.

Build the Circuit

Here is a small circuit on a breadboard.

Picture of Circuit

A simple circuit, involving a button, an LED, and a resistor, built two different ways.

The red board you see a Breadboard Power Supply, which supplies 5V to the power rails when it is connected to a 9V wall wart.

The circuit goes as follows:

  • There is a wire connecting the 5V power rail to the positive, anode leg of an LED.
  • The negative, cathode leg of the LED is connected to a 330Ω resistor.
  • The resistor is then connected to a button.
  • When the button is pushed, it connects the circuit to ground completing the circuit and turning on the LED.

Circuit Schematics

We cover how to read a schematic in another tutorial. However, it is a very important part of building circuits, so it will be covered here in short.

Schematics are universal pictograms that allow people all over the world to understand and build electronics. Every electronic component has a very unique schematic symbol. These symbols are then assembled into circuits using a variety of programs. You could also draw them out by hand. If you want to dive deeper in the world of electronics and circuit building, learning to read schematics is a very important step in doing so.

Here we have a schematic for the above circuit. Power (5V) is represented by the arrow at the top. It then goes to the LED (the triangle and line with arrows emitting out of it). The LED is then connected to the resistor (the squiggly line). That is connected to the button (the latch-looking symbol). Last the button is connect to ground (the horizontal line at the bottom).

Schematic

This may seem like a funny way to draw a circuit, but it is a fundamental process that has been around for decades. Schematics allow people from different nationalities and languages to build and collaborate on circuits designed by anyone. As mentioned, you can build a circuit in many different ways, but, as this schematic shows, there are certain connections that must be made. Diverging from this schematic will give you an entirely different circuit.

Practice Makes Perfect

The last bit of knowledge to leave you with is that there are tons of resources and programs you can use to build circuits without having to actually use your breadboard. One very common program used by SparkFun is Fritzing. Fritzing is a free program that allows you to build your own circuits on a virtual breadboard. It also provides schematic views for all the circuits you build. Here we can see the same circuits as above built using Fritzing.

Fritzing Diagram

Notice that the green lines indicate to which rows and columns each component is connected.

There are many other programs like Fritzing. Some are free, and some are paid. Some will even allow you to build a circuit and test its functionality through simulations. Go explore the internet, and find the tools that work best for you.


Purchasing a Breadboard

A great way to start using breadboards is to purchase one as part of a kit. The Sparkfun Inventor’s Kit includes everything you need to complete 16 different circuits. We’ve also listed a few basic stand-alone breadboards in different sizes for your projects.

Our recommendations:


Resources and Going Further

Hopefully you now have a better understanding of what a breadboard is and how it works. Now the real fun begins. We’ve barely scratched the surface of building circuits on breadboards. Here are some other tutorials you can check out to learn more about components and how to integrate them into your breadboard circuits.

Educators may be interested in these links.

Or, if you have mastered your circuit building skills and want to move to the next level, check out these tutorials.

Integrated Circuits

Introduction

Integrated circuits (ICs) are a keystone of modern electronics. They are the heart and brains of most circuits. They are the ubiquitous little black “chips” you find on just about every circuit board. Unless you’re some kind of crazy, analog electronics wizard, you’re likely to have at least one IC in every electronics project you build, so it’s important to understand them, inside and out.

Example of ICs on a PCB

Integrated circuits are the little black “chips”, found all over embedded electronics.

An IC is a collection of electronic components – resistors, transistors, capacitors, etc. – all stuffed into a tiny chip, and connected together to achieve a common goal. They come in all sorts of flavors: single-circuit logic gates, op amps, 555 timers, voltage regulators, motor controllers, microcontrollers, microprocessors, FPGAs…the list just goes on-and-on.

Covered in this Tutorial

  • The make-up of an IC
  • Common IC packages
  • Identifying ICs
  • Commonly used ICs

Suggested Reading

Integrated circuits are one of the more fundamental concepts of electronics. They do build on some previous knowledge, though, so if you aren’t familiar with these topics, consider reading their tutorials first…

Inside the IC

When we think integrated circuits, little black chips are what come to mind. But what’s inside that black box?

Internal view of an IC

The guts of an integrated circuit, visible after removing the top.

The real “meat” to an IC is a complex layering of semiconductor wafers, copper, and other materials, which interconnect to form transistors, resistors or other components in a circuit. The cut and formed combination of these wafers is called a die.

Overview of internal IC

An overview of an IC die.

While the IC itself is tiny, the wafers of semiconductor and layers of copper it consists of are incredibly thin. The connections between the layers are very intricate. Here’s a zoomed in section of the die above:

Microscopic view of an IC

An IC die is the circuit in its smallest possible form, too small to solder or connect to. To make our job of connecting to the IC easier, we package the die. The IC package turns the delicate, tiny die, into the black chip we’re all familiar with.

IC Packages

The package is what encapsulates the integrated circuit die and splays it out into a device we can more easily connect to. Each outer connection on the die is connected via a tiny piece of gold wire to a pad or pin on the package. Pins are the silver, extruding terminals on an IC, which go on to connect to other parts of a circuit. These are of utmost importance to us, because they’re what will go on to connect to the rest of the components and wires in a circuit.

There are many different types of packages, each of which has unique dimensions, mounting-types, and/or pin-counts.

Package variety chart

Polarity Marking and Pin Numbering

All ICs are polarized, and every pin is unique in terms of both location and function. This means the package has to have some way to convey which pin is which. Most ICs will use either a notch or a dot to indicate which pin is the first pin. (Sometimes both, sometimes one or the other.)

Package with notch/dot labeled

Once you know where the first pin is, the remaining pin numbers increase sequentially as you move counter-clockwise around the chip.

DIP pin numbering

Mounting Style

One of the main distinguishing package type characteristics is the way they mount to a circuit board. All packages fall into one of two mounting types: through-hole (PTH) or surface-mount (SMD or SMT). Through-hole packages are generally bigger, and much easier to work with. They’re designed to be stuck through one side of a board and soldered to the other side.

Surface-mount packages range in size from small to minuscule. They are all designed to sit on one side of a circuit board and be soldered to the surface. The pins of a SMD package either extrude out the side, perpendicular to the chip, or are sometimes arranged in a matrix on the bottom of the chip. ICs in this form factor are not very “hand-assembly-friendly.” They usually require special tools to aid in the process.

DIP (Dual in-line packages)

DIP, short for dual in-line package, is the most common through-hole IC package you’ll encounter. These little chips have two parallel rows of pins extending perpendicularly out of a rectangular, black, plastic housing.

DIP package example

The 28-pin ATmega328 is one of the more popular DIP-packaged microcontrollers (thanks, Arduino!).

Each of the pins on a DIP IC are spaced by 0.1″ (2.54mm), which is a standard spacing and perfect for fitting intobreadboards and other prototyping boards. The overall dimensions of a DIP package depend on its pin count, which may be anywhere from four to 64.

The area between each row of pins is perfectly spaced to allow DIP ICs to straddle the center area of a breadboard. This provides each of the pins its own row in the board, and it makes sure they don’t short to each other.

DIP chips on a breadboard

Aside from being used in breadboards, DIP ICs can also be soldered into PCBs. They’re inserted into one side of the board and soldered into place on the other side. Sometimes, instead of soldering directly to the IC, it’s a good idea tosocket the chip. Using sockets allows for a DIP IC to be removed and swapped out, if it happens to “let its blue smoke out.”

alt text

A regular DIP socket (top) and a ZIF socket with and without an IC.

Surface-Mount (SMD/SMT) Packages

There is a huge variety of surface-mount package types these days. In order to work with surface-mount packaged ICs, you usually need a custom printed circuit board (PCB) made for them, which has a matching pattern of copper on which they’re soldered.

Here are a few of the more common SMD package types out there, ranging in hand-solderability from “doable” to “doable, but only with special tools” to “doable only with very special, usually automated tools”.

Small-Outline (SOP)

Small-outline IC (SOIC) packages are the surface-mount cousin of the DIP. It’s what you’d get if you bent all the pins on a DIP outward, and shrunk it down to size. With a steady hand, and a close eye, these packages are among the easiest SMD parts to hand solder. On SOIC packages, each pin is usually spaced by about 0.05″ (1.27mm) from the next.

The SSOP (shrink small-outline package) is an even smaller version of SOIC packages. Other, similar IC packages include TSOP (thin small-outline package) and TSSOP (thin-shrink small-outline package).

Example of SSOP mounted, quarter added for size-comparison

A 16-Channel Multiplexer (CD74HC4067) in a 24-pin SSOP package. Mounted on a board in the middle (quarter added for size-comparison).

A lot of the more simple, single-task-oriented ICs like the MAX232 or multiplexers come in SOIC or SSOP forms.

Quad Flat Packages

Splaying IC pins out in all four directions gets you something that might look like a quad flat package (QFP). QFP ICs might have anywhere from eight pins per side (32 total) to upwards of seventy (300+ total). The pins on a QFP IC are usually spaced by anywhere from 0.4mm to 1mm. Smaller variants of the standard QFP package include thin (TQFP), very thin (VQFP), and low-profile (LQFP) packages.

TQFP example package

The ATmega32U4 in a 44-pin (11 on each side) TQFP package.

If you sanded the legs off a QFP IC, you get something that might look like a quad-flat no-leads (QFN) package. The connections on QFN packages are tiny, exposed pads on the bottom corner edges of the IC. Sometimes they wrap around, and are exposed on both the side and bottom, other packages only expose the pad on the bottom of the chip.

Example of QFN package

The multitalented MPU-6050 IMU sensor comes in a relatively tiny QFN package, with 24 total pins hiding on the bottom edge of the IC.

Thin (TQFN), very thin (VQFN), and micro-lead (MLF) packages are smaller variations of the standard QFN package. There are even dual no-lead (DFN) and thin-dual no-lead (TDFN) packages, which have pins on just two of the sides.

Many microprocessors, sensors, and other modern ICs come in QFP or QFN packages. The popular ATmega328microcontroller is offered in both a TQFP package and a QFN-type (MLF) form, while a tiny accelerometer/gyroscopelike the MPU-6050 comes in a miniscule QFN form.

Ball Grid Arrays

Finally, for really advanced ICs, there are ball grid array (BGA) packages. These are amazingly intricate little packages where little balls of solder are arranged in a 2-D grid on the bottom of the IC. Sometimes the solder balls are attached directly to the die!

Example of BGA package

BGA packages are usually reserved for advanced microprocessors, like those on the pcDuino or Raspberry Pi.

If you can hand solder a BGA-packaged IC, consider yourself a master solderer. Usually, to put these packages onto a PCB requires an automated procedure involving pick-and-place machines and reflow ovens.

Common ICs

Integrated circuits are prevalent in so many forms across electronics, it’s hard to cover everything. Here are a few of the more common ICs you might encounter in educational electronics.

Logic Gates, Timers, Shift Registers, Etc.

Logic gates, the building blocks of much more ICs themselves, can be packaged into their own integrated circuit. Some logic gate ICs might contain a handful of gates in one package, like this quad-input AND gate:

Logic gate pinout

Logic gates can be connected inside an IC to create timers, counters, latches, shift registers, and other basic logic circuitry. Most of these simple circuits can be found in DIP packages, as well as SOIC and SSOP.

Microcontrollers, Microprocessors, FPGAs, Etc.

Microcontrollers, microprocessors, and FPGAs, all packing thousands, millions, even billions of transistors into a tiny chip, are all integrated circuits. These components exist in a wide range in functionality, complexity, and size; from an 8-bit microcontroller like the ATmega328 in an Arduino, to a complex 64-bit, multi-core microprocessor organizing activity in your computer.

These components are usually the largest IC in a circuit. Simple microcontrollers can be found in packages ranging from DIP to QFN/QFP, with pin counts lying somewhere between eight and a hundred. As these components grow in complexity, the package gets equally complex. FPGAs and complex microprocessors can have upwards of a thousand pins and are only available in advanced packages like QFN, LGA, or BGA.

Sensors

Modern digital sensors, like temperature sensors, accelerometers, and gyroscopes all come packed into an integrated circuit.

These ICs are usually smaller than the microcontrollers, or other ICs on a circuit board, with pin counts in the three to twenty range. DIP sensor ICs are becoming a rarity, as modern components are usually found in QFP, QFN, even BGA packages.

Resources and Going Further

Integrated circuits are present in just about every circuit out there. Now that you’re familiar with ICs, why not check out some of these related concept tutorials:

  • PCB Basics – ICs have to be connected to a circuit somehow. Usually we’ll solder an IC to a printed circuit board (PCB). Check out this tutorial to learn more about those little green boards.
  • Serial Communication, Serial Peripheral Interface (SPI), and I2C – All three of these are communication protocols ICs use to communicate between each other.

Or, check out some of these skill tutorials. These are handy skills every budding electronics hacker should learn!

  • How to Solder – Unless you’re using a breadboard with your ICs, you’ll probably need to solder them.
  • Designing PCBs – Or, if you’re already familiar with PCBs, why not try making one! This tutorial explains how to use a freely available software (Eagle) to design PCBs.
  • Designing PCB Footprints – This tutorial walks you through the steps required to design a PCB footprint for an IC, using Eagle CAD.

Electric Power

With Great Power…

Why do we care about power? Power is the measurement of energy transfer over time, and energy costs money. Batteries aren’t free, and neither is that stuff coming out of your electrical outlet. So, power measures how fast the pennies are draining out of your wallet!

Also, energy is…energy. It comes in many, potentially harmful, forms – heat, radiation, sound, nuclear, etc. – ,and more power means more energy. So, it’s important to have an idea of what kind of power you’re working with when playing with electronics. Fortunately, in playing with Arduinos, lighting up LEDs, and spinning small motors, losing track of how much power you’re using only means smoking a resistor or melting an IC. Nevertheless, Uncle Ben’s advice doesn’t just apply to superheros.

Covered in this Tutorial

  • The definition of power
  • Examples of electric energy transfers
  • Watts, the SI unit of power
  • Calculating power using voltage, current, and resistance
  • Maximum power ratings

Suggested Reading

Power is one of the more fundamental concepts in electronics. But before learning about power, there might be some other tutorials you should read first. If you’re not familiar with some these topics, consider checking out those tutorials first:

What is Electric Power?

There are many types of power – physical, social, super, odor blocking, love – but in this tutorial, we’ll be focusing on electric power. So what is electric power?

In general physics terms, power is defined as the rate at which energy is transferred (or transformed).

So, first, what is energy and how is it transferred? It’s hard to state simply, but energy is basically the ability ofsomething to move something else. There are many forms of energy: mechanical, electrical, chemical, electromagnetic, thermal, and many others.

Energy can never be created or destroyed, only transferred to another form. A lot of what we’re doing in electronics is converting different forms of energy to and from electric energy. Lighting LEDs turns electric energy into electromagnetic energy. Spinning motors turns electric energy into mechanical energy. Buzzing buzzers makes sound energy. Powering a circuit off a 9V alkaline battery turn chemical energy into electrical energy. All of these are forms ofenergy transfers.

ENERGY TYPE CONVERTED CONVERTED BY
Mechanical Electric Motor
Electromagnetic LED
Heat Resistor
Chemical Battery
Wind Windmill

Example electric components, which transfer electric energy to another form.

Electric energy in particular, begins as electric potential energy – what we lovingly refer to as voltage. When electrons flow through that potential energy, it turns into electric energy. In most useful circuits, that electric energy transforms into some other form of energy. Electric power is measured by combining both how much electric energy is transferred, and how fast that transfer happens.

Producers and Consumers

Each component in a circuit either consumes or produces electric energy. A consumer transforms electric energy into another form. For example, when an LED lights up, electric energy is transformed into electromagnetic. In this case, the lightbulb consumes power. Electric power is produced when energy is transferred to electric from some other form. A battery supplying power to a circuit is an example of a power producer.

Wattage

Energy is measured in terms of joules (J). Since power is a measure of energy over a set amount of time, we can measure it in joules per second. The SI unit for joules per second is the watt abbreviated as W.

watt = w = joule/second = j/s

It’s very common to see “watts” preceded by one of the standard SI prefixes: microwatts (µW), miliwatt (mW), kilowatt (kW), megawatt (MW), and gigawatts (GW), are all common depending on the situation.

PREFIX NAME PREFIX ABBREVIATION WEIGHT
Nanowatt nW 10-9
Microwatt µW 10-6
Milliwatt mW 10-3
Watt W 100
Kilowatt kW 103
Megawatt MW 106
Gigawatt GW 109

Microcontrollers, like the Arduino will usually operate in the the µW or mW range. Laptop and desktop computers operate in the standard watt power range. Energy consumption of a house is usually in the kilowatt range. Large stadiums might operate at the megawatt scale. And gigawatts come into play for large-scale power stations and time machines.

Calculating Power

Electric power is the rate at which energy is transferred. It’s measured in terms of joules per second (J/s) – a watt (W). Given the few basic electricity terms we know, how could we calculate power in a circuit? Well, we’ve got a very standard measurement involving potential energy – volts (V) – which are defined in terms of joules per unit of charge (coulomb) (J/C). Current, another of our favorite electricity terms, measures charge flow over time in terms of the ampere (A) – coulombs per second (C/s). Put the two together and what do we get?! Power!

Deriving watts from volts and amps

To calculate the power of any particular component in a circuit, multiply the voltage drop across it by the current running through it.

P = VI

For Example

Below is a simple (though not all that functional) circuit: a 9V battery connected across a 10Ω resistor.

Simple circuit: 9V battery connected to 10Ω resistor

How do we calculate the power across the resistor? First we have to find the current running through it. Easy enough…Ohm’s law!

I = V/R = 9/10 = 900mA

Alright, 900mA (0.9A) running through the resistor, and 9V across it. What kind of power is being applied to the resistor then?

P=IV=9*.9=8.1W

A resistor transforms electric energy into heat. So this circuit transforms 8.1 joules of electric energy to heat every second.

Calculating Power in Resistive Circuits

When it comes to calculating power in a purely resistive circuit, knowing two of three values (voltage, current, and/or resistance) is all you really need.

Power across a resistor example circuit

By plugging Ohm’s law (V=IR or I=V/R) into our traditional power equation we can create two new equations. The first, purely in terms of voltage and resistance:

P=V^2/R

So, in our previous example, 9V2/10Ω (V2/R) is 8.1W, and we never have to calculate the current running through the resistor.

A second power equation can be formed solely in terms of current and resistance:

P=I^2*R


Why do we care about the power dropped on a resistor? Or any other component for that matter. Remember that power is the transfer of energy from one type to another. When that electrical energy running from the power source hits the resistor, the energy transforms into heat. Possibly more heat than the resistor can handle. Which leads us to…power ratings.

Power Ratings

All electronic components transfer energy from one type to another. Some energy transfers are desired: LEDs emitting light, motors spinning, batteries charging. Other energy transfers are undesirable, but also unavoidable. These unwanted energy transfers are power losses, which usually show up in the form of heat. Too much power loss – too much heat on a component – can become very undesirable.

Even when energy transfers are the main goal of a component, there’ll still be losses to other forms of energy. LEDs and motors, for example, will still produce heat as a byproduct of their other energy transfers.

Most components have a rating for maximum power they can dissipate, and it’s important to keep them operating under that value. This’ll help you avoid what we lovingly refer to as “letting the magic smoke out”.

Resistor Power Ratings

Resistors are some of the more notorious culprits of power loss. When you drop some voltage across a resistor, you’re also going to induce current flow across it. More voltage, means more current, means more power.

Remember back to our first power-calculation example, where we found that if 9V were dropped across a 10Ω resistor, that resistor would dissipate 8.1W. 8.1 is a lot of watts for most resistors. Most resistors are rated for anywhere from ⅛W (0.125W) to ½W (0.5W). If you drop 8W across a standard ½W resistor, ready a fire extinguisher.

1/2 and 1/4W resistors

If you’ve seen resistors before, you’ve probably seen these. Top is a ½W resistor and below that a ¼W. These aren’t built to dissipate very much power.

There are resistors built to handle large power drops. These are specifically called out as power resistors.

Power resistors

These large resistors are built to dissipate lots of power. From left to right: two 3W 22kΩ resistors, two 5W 0.1Ω resistors, and 25W 3Ω and 2Ω resistors.

If you ever find yourself picking out a resistor value. Keep it’s power rating in mind as well. And, unless your goal is to heat something up (heating elements are basically really high-power resistors), try to minimize power loss in a resistor.

For Example

Resistor power ratings can come into play when you’re trying to decide on a value for an LED current-limiting resistor. Say, for example, you want to light up a 10mm super-bright red LED at maximum brightness, using a 9V battery.

Red LED lit up

That LED has a maximum forward current of 80mA, and a forward voltage of about 2.2V. So to deliver 80mA to the LED, you’d need an 85Ω resistor to do so.

LED circuit with current-limiting resistor

6.8V dropped on the resistor, and 80mA running through it means 0.544W (6.8V*0.08A) of power lost on it. A half-watt resistor isn’t going to like that very much! It probably won’t melt, but it’ll get hot. Play it safe and move up to a 1W resistor (or save power and use a dedicated LED driver).


Resistors certainly aren’t the only components where maximum power ratings must be considered. Any component with a resistive property to it is going to produce thermal power losses. Working with components that are commonly subjected to high power – voltage regulators, diodes, amplifiers, and motor drivers, for example – means paying extra special attention to power loss and thermal stress.

Resources and Going Further

Now that you’re familiar with the concept of electric power, check out some of these related tutorials!

  • How to Power Your Project – Well, you know what “power” is. But how do you get it to your project?
  • Light – Light is a useful tool for the electrical engineer. Understanding how light relates to electronics is a fundamental skill for many projects.
  • What is an Arduino – We talked about this Arduino thing a lot in this tutorial. If you’re still unclear about what that is, check this tutorial out!
  • Diodes – Whether they’re converting AC to DC, or just lighting up a power indicator LED, diodes are an especially handy component for powering projects.
  • Resistors – The most basic of electronic components, resistors are a requirement in just about every circuit there is.
  • MP3 Player Shield Music Box – Talk about energy transfer! This project combines electricity, motion, and sound to make a Doctor Who-themed music box.