All posts by 石, 钟熙

Using EAGLE: Schematic

Introduction

PCB design in EAGLE is a two-step process. First you design your schematic, then you lay out a PCB based on that schematic. EAGLE’s board and schematic editors work hand-in-hand. A well-designed schematic is critical to the overall PCB design process. It will help you catch errors before the board is fabricated, and it’ll help you debug a board when something doesn’t work.

This tutorial is the first of a two-part Using EAGLE series, and it’s devoted entirely to the schematic-designing side of EAGLE. In part 2, Using EAGLE: Board Layout, we’ll use the schematic designed in this tutorial as the basis for our example board layout.

1

Suggested Reading

If you’d like to follow along with this tutorial, make sure you’ve installed and setup the EAGLE software. Our How to Install and Setup EAGLE tutorial goes over this process step-by-step, and it also covers the basics of what EAGLE is and what makes it great. It also covers how to download and install the SparkFun EAGLE libraries we’ll be using in this tutorial. Definitely read through that tutorial before you continue on.

We’d also recommend you read and understand the concepts behind these tutorials:

Create a Project

We’ll start by making a new project folder for our design. In the control panel, under the “Projects” tree, right click on the directory where you want the project to live (by default EAGLE creates an “eagle” directory in your home folder), and select “New Project”.

2

Give the newly created, red project folder a descriptive name. How about “Bare Bones Arduino”.

3

Project folders are like any regular file system folder, except they contain a file named “eagle.epf”. The EPF file links your schematic and board design together, and also stores any settings you may have set especially for the project.

Create a Schematic

The project folder will house both our schematic and board design files (and eventually our gerber files too). To begin the design process, we need to lay out a schematic.

To add a schematic to a project folder, right-click the folder, hover over “New” and select “Schematic”.

4

A new, blank window should immediately pop up. Welcome to the schematic editor!

Adding Parts to a Schematic

Schematic design is a two step process. First you have to add all of the parts to the schematic sheet, then those parts need to be wired together. You can intermix the steps – add a few parts, wire a few parts, then add some more – but since we already have a reference design we’ll just add everything in one swoop.

Using the ADD Tool

The ADD tool – (on the left toolbar, or under the Edit menu) – is what you’ll use to place every single component on the schematic. The ADD tool opens up a library navigator, where you can expand specific libraries and look at the parts it holds. With a part selected on the left side, the view on the right half should update to show both the schematic symbol of the part and its package.

5

The ADD tool also has search functionality – very helpful when you have to navigate through dozens of libraries to find a part. The search is very literal, so don’t misspell stuff! You can add wildcards to your search by placing an asterisk (*) before and/or after your search term. For example if you search for atmega328 you should find a single part/package combo in the SparkFun-DigitalIC library, but if you search *atmega328* (note asterisks before and after), you’ll discover two more versions of the IC (because they’re actually named “ATMEGA328P”). You’ll probably want to get accustomed to always adding an asterisk before and after your search term.

6

To actually add a part from a library either select the part you want and click “OK”, or double-click your part.

Step 1: Add a Frame

The frame isn’t a critical component for what will be the final PCB layout, but it keeps your schematic looking clean and organized. The frame we want should be in the SparkFun-Aesthetics library, and it’s named FRAME-LETTER. Find that by either searching or navigating and add it to your schematic.

7

After selecting the part you want to add, it’ll “glow” and start hovering around following your mouse cursor. To place the part, left-click (once!). Let’s place the frame so its bottom-left corner runs right over our origin (the small dotted cross, in a static spot on the schematic).

8

After placing a part, the add tool will assume you want to add another – a new frame should start following your cursor. To get out of the add-mode either hit escape (ESC) twice or just select a different tool.

Step 2: Save (And Save Often)

Right now your schematic is an untitled temporary file living in your computer’s ether. To save either go to File > Save, or just click the blue floppy disk icon – . Name your schematic something descriptive. How about “BareBonesArduino.sch” (SCH is the file format for all EAGLE schematics).

As a bonus, after saving, your frame’s title should update accordingly (you may have to move around the screen, or go to View > Redraw).

Step 3: Adding the Power Input

Next we’ll add four different parts all devoted to our voltage supply input. Use the add tool for these parts:

 

Part Description Library Part Name Quantity
5.5mm Barrel Jack (PTH) SparkFun-Connectors POWER_JACKPTH 1
0.1µF Ceramic Capacitor SparkFun-Capacitors CAPPTH 1
Voltage Supply Symbol SparkFun-Aesthetics VCC 1
Ground Symbol SparkFun-Aesthetics GND 2

All of these parts will go in the top-left of the schematic frame. Arranged like this:

10

If you need to move parts around, use the MOVE tool – (left toolbar or under the Edit menu). Left-click once on a part to pick it up (your mouse should be hovering over the part’s red “+” origin). Then left click again when it’s where it needs to be.

Step 4: Microprocessor and Supporting Circuitry

Next we’ll add the main component of the design – the ATmega328 microprocessor – as well as some components to support it. Here are the parts we’ll add:

 

Part Description Library Exact Part Name Quantity
ATmega328P (PTH) SparkFun-DigitalIC ATMEGA328P_PDIP 1
¼W Resistors SparkFun-Resistors RESISTORPTH-1/4W 4
5mm LEDs SparkFun-LED LED5MM 3
0.1µF Ceramic Capacitor SparkFun-Capacitors CAPPTH 1
Voltage Supply Symbol SparkFun-Aesthetics VCC 2
Ground Symbol SparkFun-Aesthetics GND 4

To rotate parts as your placing them, either select one of the four options on the rotate toolbar – – or right click before placing the part. Place your microcontroller in the center of the frame, then add the other parts around it like so:

13

Step 5: Adding the Connectors

Three connectors will finish off our design. One 8-pin connector to break out the analog pins, a 6-pin serial programming header, and a 2x3-pin ICSP programming header. Here are the three parts to add for this step:

 

Part Description Library Exact Part Name Quantity
8-Pin 0.1" Header SparkFun-Connectors M081X08 1
2x3 AVR Programming Header SparkFun-Connectors AVR_SPI_PRG_6PTH 1
6-Pin Serial Programming Header SparkFun-Connectors ARDUINO_SERIAL_PROGRAMPTH 1
Voltage Supply Symbol SparkFun-Aesthetics VCC 2
Ground Symbol SparkFun-Aesthetics GND 2

Finally! Here’s what your schematic should look like with every part added:

14

Next we’ll wire net them all together.

Wiring Up the Schematic

With all of the parts added to our schematic, it’s time to wire them together. There’s one major caveat here before we start: even though we’re wiring parts on the schematic, we not going to use the WIRE tool – – to connect them together. Instead, we’ll use the NET tool – (left toolbar, or under the Draw menu). The WIRE tool would be better-named as a line-drawing tool, NET does a better job of connecting components.

Use NET not WIRE

Using the NET Tool

To use the NET tool, hover over the very end of a pin (as close as possible, zoom in if you have to), and left-click once to start a wire. Now a green line should be following your mouse cursor around. To terminate the net, left-click on either another pin or a net.

17

The hard part, sometimes, is identifying which part on a circuit symbol is actually a pin. Usually they’re recognizable by a thin, horizontal, red line off to the side of a part. Sometimes (not always) they’re labeled with a pin number. Make sure you click on the very end of the pin when you start or finish a net route.

Route the Power Input Circuit

Start back in the upper left, and route the power input circuit like so:

18

Whenever a net splits in two directions a junction node is created. This signifies that all three intersecting nets areconnected. If two nets cross, but there’s not a junction, those nets are not connected.

Route the ATmega328 Circuit

Next we’ll route the ATmega328 to its supporting circuitry. There’s LEDs, a connector, resistor, capacitor and VCC/GND symbols to route to:

19

Don’t forget to add nets between the LEDs, resistors, and GND symbols!

Making Named, Labeled Net Stubs

The remaining nets we have to make are not going to be as easy to cleanly route. For example, we need to connect the TXO pin on JP2 to the ATmega’s RXD pin, all the way on the other side. You could do it, it would work, but it’d be really ugly. Instead, we’ll make net “stubs” and give them unique names to connect them.

We’ll start by adding short, one-sided nets to each of the six pins on the serial connector. Begin by starting a net at a pin, just as you’ve been doing. Terminate the net by left-clicking a few grid-lengths over to the right of the pin. Then, instead of routing to another pin, just hit ESC to finish the route. When you’re done, it should look like this:

20

Next, we’ll use the NAME tool – (left toolbar, or under the Edit menu) – to name each of the six nets. With the NAME tool selected, clicking on a net should open a new dialog. Start by naming the net connected to the top, GND pin. Delete the auto-generated name (e.g. N$14), and replace it with “GND” (sans the quotation marks). This should result in a warning dialog, asking you if you want to connect this net to all of the other nets named “GND” (that would be every net connected to a GND symbol). Thanks for looking out for us EAGLE, but in this case Yes we do want to connect GND to GND.

After naming a net, you should use the LABEL tool – – to add a text label. With the LABEL tool selected, left-click on the net you just named. This should spawn a piece of text that says “GND”, left-click again to place the label down right on top of your net.

Follow that same order of operations for the remaining five net stubs. In the end, they should look like this (note the net connected to the TXO pin is named “RX”, and a “TX” net connects to RXI – that’s on purpose):

23

VCC should be the only other net that warns you that you’ll be connecting to other nets named “VCC” (anything connected to a VCC voltage node). For the other named nets, we’ll need to create this same stub somewhere else. Where exactly? Well, we need to add a “RX” and “TX” net on the ATmega328, and a “DTR” nearby as well:

24

Even though there’s no green net connecting these pins, every net with the same, exact name is actually connected.

We need to do a lot of the same to connect the 2x3 programming header to the ATmega328. First, wire up the connector like so (naming/labeling MOSI, MISO, SCK, and RESET):

25

Then, back to the ATmega328, add the same four named/labeled nets:

26

Phew – you’re done. Get excited, it’s about time to lay out a PCB! When your schematic is done, it should look a little something like this:

27


The schematic layout is done, but there are a few tips and tricks we’d like to share before moving over to the PCB layout portion of the tutorial.

Tips and Tricks

Names and Values

Every component on your schematic should have two editable text fields: a name and a value. The name is an identifier like R1, R2, LED3, etc. Every component on the schematic should have a unique name. You can use the NAME tool – on any component to change the name.

A part’s value allows you to define unique characteristics of that part. For example, you can set a resistor’s resistance, or a capacitor’s capacitance. The importance of a part’s value depends on what type of component it is. For parts like resistors, capacitors, inductors, etc. the value is a critical piece of information when you’re generating a bill of materials or assembly sheet. To adjust a part’s value parameter, use the VALUE tool – .

Verifying Connections

The SHOW tool – – is very useful for verifying that pins across your schematic are connected correctly. If you use SHOW on a net, every pin it’s connected to should light up. If you’re dubious of the fact that two like-named nets are connected, give the SHOW tool a try. SHOW-ing a net connected to GND, for example, should result in a lot of GND nets lighting up.

31

As an alternative to show, you can temporarily MOVE a part a part to make sure nets are connected to it. Use MOVE to pick a part up, and the nets connected to it should bend and adjust to remain so. Just make sure you hit ESC to notmove the part (or UNDO if you accidentally move it).

32

If all the nets connected to a part MOVE with it, all connections are good.

If a net isn’t moving along with the part, it’s not connected to the pin correctly. Double check to make sure you routed to the very end of the pin, and not a bit further:

33

If you have any nets incorrectly connected like above, DELETE – – it, and try re-netting.

Group Moving/Deleting/Etc.

Any tool that you use on a single component, can also be used on a group of them. Grouping and performing an action on that group is a two-step process. First, use the group tool – – to select the parts you want to modify. You can either hold down the left-mouse button and drag a box around them, or click multiple times to draw a polygon around a group. Once the group is made, every object in that group should glow.

After grouping, select the tool you want to use. The status box in the far bottom-left will have some helpful information pertaining to using the tool on a group:

Group move status box

In order to perform any action on a group, you have to select the tool, then hold down CTRL and right-click the group. After you CTRL+right-click, the tool will operate on the group just as it does a single component.

Copy/Paste

EAGLE’s Copy – – and Paste – – tools don’t work exactly like other copy/paste tools you may have encountered before. Copy actually performs both a copy and paste when it’s used. As soon as you copy a part (or any object on the schematic – name, text, net, etc.) an exact copy will instantly spawn and follow your mouse awaiting placement. This is useful if you need to add multiples of the same part (like GND nodes or resistors).

Paste can only be used to paste a group that has previously been copied to your clipboard. To use paste you first have to create a group, then (with the copy tool selected) CTRL+right-click to copy it, but hit ESC instead of gluing it down. This’ll store the copied group into your operating system’s clipboard, and you can use paste to place it somewhere. This tool is especially useful if you need to copy parts of one schematic file into another.

(note:the article is from the Sparkfun Community)

Working with Wire

Introduction

When someone mentions the word wire, they are more than likely referring to a flexible, cylindrical piece of metal that can vary in size from just a few millimeters in diameter to several centimeters. Wire can refer to either a mechanical or electrical application. An example of a mechanical wire could be a Guy-wire, but this this guide will focus on electrical wiring.

wire

Inside a stranded wire

Electrical wire is a backbone of our society. There is wire in houses to turn on lights, heat the stove, and even talk on the phone. Wire is used to allow current to flow from one place to another. Most wires have insulation surrounding the metallic core. An electrical insulator is a material whose internal electric charges do not flow freely and, therefore, does not conduct an electric current. A perfect insulator does not exist, but some materials such as glass, paper and Teflon, which have high resistivity, are very good electrical insulators. Insulation exists because touching a bare wire could allow current to flow through a persons body (bad) or into another wire unintentionally.

Recommended Reading:

Here are some topics you might want to explore before reading about wire:

Stranded vs Solid

Wire can come in one of two forms, stranded or solid core.

Solid Wire

Various colors of solid core wire

Solid wire is composed of a single piece of metal wire, also known as a strand. One very common type of solid wire is known as wire wrap. Stranded wire is composed of many pieces of solid wire all bundled into one group.

Stranded Wire

Various colors and sizes of stranded wire

Stranded wire is much more flexible than solid wire of equal size. For this reason, stranded wire is used when the wire needs to move around frequently, in a robot arm for example. Conversely, solid wire is used when little or no movement is needed, such as prototyping circuits on a breadboard. Using solid core wire makes it easy to push the wire into a breadboard. Trying to use stranded wire on a breadboard can be very difficult, as the strands want to separate as they are pressed in.

Wire Thickness

The term ‘gauge’ is used to define the diameter of the wire. The gauge of a wire is used to determine the amount of current a wire can safely handle. Wire gauge can refer to both electrical and mechanical. This tutorial will only cover electrical. There are two main systems for measuring gauge, American Wire Gauge (AWG) and Standard Wire Gauge (SWG). The differences between the two are not critical to this guide.

Wire Gauges

An approximate scale of several different gauges of wire

The amount of current that a wire can carry depends on a few different factors, for example the composition of the wire, wire length, and condition of the wire. In general, thicker wire can carry more current.

Amps to Gauge

An approximate wire thickness to current capability chart

Here at SparkFun we typically use 22 AWG wire for prototyping and breadboarding. When using a breadboard, the solid core is perfect because it fits nicely into the breadboard holes. For other prototyping/building involving soldering, the stranded core is #1, just be sure not to let too much current run through a single wire, it will get hot and could melt!

SparkFun carries a variety of both solid and stranded 22 AWG wire. Check it out!

How to Strip a Wire

Safe, durable electrical connections begin with clean, accurate wire stripping. Removing the outer layer of plastic without nicking the wires underneath is critical. If a wire does get nicked, the connection may break or an electrical short may occur.

Nice Wires

No nicks or gouges. These wires have been properly stripped

The Tool

A simple manual wire stripper is a pair of opposing blades much like scissors. There are several notches of varying size. This allows the user to match the notch size to the wire size, which is very important for not damaging the wires.

Wire Strippers - 30AWG (Hakko)
$9.95

     3

Although a knife would also strip the wires, it may also damage the wire by nicking the metal or cutting into it. Using a knife to strip wire is also really dangerous! The knife can easily slip and cause wicked injuries.

Stripping the Wire

Wire in Stripper

By simply squeezing the handles about ¼" from the end of the wire or the desired length, using the correct notch on the tool, and then twisting it slightly, the insulation will be cut free.

Wire After Strip

Then by pulling the wire strippers towards the end of the wire, the insulation should slide right off of the wire.

Tips, Tricks, and Hints

It is important to match the size of wire to the correct notch in the stripper. If the notch is too large, the wire will not get stripped. If the notch is too small, there is a risk of damaging the wire. Using an undersized notch means the strippers will close too far, digging into the wire underneath. With stranded wire, the tool will cut off the outer ring of wires, decreasing the total diameter of wire and reduce the strength of the wire. A nick in solid core wire will severely reduce the strength and flexibility of the wire. The likelihood of the wire breaking upon being bent increases significantly.

Damaged Wire

This wire was not stripped properly, there are gouges and missing strands

If a wire does accidentally get a nick in it, the best plan of action is to cut the damaged part of the wire off and try again.

How to Crimp an Electrical Connector

An electrical connector is a device for joining electrical circuits together using a mechanical assembly. The connection may be temporary or serve as a permanent electrical joint between two wires.

There are hundreds of types of electrical connectors. Connectors may join two lengths of wire together or connect a wire to an electrical terminal.

Connector Types

The Tool

The word crimping in this context means to join two pieces of metal together by deforming one or both of them to hold the other. The deformity is called the crimp.

crimped

The metal has been deformed to pinch the wire and hold it in place

In order to crimp connectors onto a wire, a special tool is required. Note: Pliers are not crimpers! Neither are hammers, vises, needle nose pliers or flat rocks. A good crimper when used correctly will make a cold weld between the wire and the barrel of the connector. If you were to cut a well executed crimp in half you would see a solid form of wire and connector. Using the wrong tool will not achieve a good crimp!

Why is this level of perfection required? A poor crimp leaves air pockets between the wire and connector. Air pockets allow moisture to collect, moisture causes corrosion, corrosion causes resistance, resistance causes heat, and may ultimately lead to breakage.

Crimper Tools

The top crimper will give better results, however the bottom one works just fine too

There are several different styles of crimpers available. The best crimper, shown on the top, has a built in ratchet. As the handles are squeezed together, it will ratchet and prevent the jaws from opening back up. When enough pressure has been applied, the ratchet will disengage and release the crimped part. This ensures enough pressure has been applied. This style of crimper also has a wide jaw to cover more surface area on the connector.

The crimping tool on the bottom can achieve nearly the same results, although it requires the user be be much more vigilant. This style of crimper is generally less sturdy. Attention must be given while crimping to ensure the jaws are lined up properly on the connector. Misalignment will cause a less than desirable crimp connection. Over time, wear and tear from normal usage can also cause the jaws to become separated and not close fully. Generally, squeezing it as hard as possible will be sufficient.

Crimp the Connector

There are several arguments for and against using solid core wire with crimp connections. Many believe crimping to solid core wire creates a weak point in the wire, which can lead to breakage. There is also a greater chance for a crimp connection to come loose with solid core wire because the wire will not conform to the terminal as well. If you must use solid core wire, it is a good idea to solder the wire in place after you crimp it.

First, the correct size wire must be chosen for the terminal size, or vice versa. Next, strip the wire. The amount of exposed wire should be equal to the length of the metal barrel on the connector, usually around ¼” or so. If the stripped wire fits up into the metal portion of the barrel with little or no free space, the connector is the right size.

Good Length

A good length of wire to barrel ratio

Remember: If the wire does not fit in the barrel, or is excessively loose, the wrong size of either wire or connector was chosen.

The wire should then be inserted until the insulation on the wire touches the end of the barrel.

Good Crimp Example

Good: The wire is sticking past the barrel just a little

The wire and terminal are then inserted into the crimper. The color of the terminal’s insulation needs to be matched with the same color on the crimping tool. So if the terminal’s insulation is red, use the spot marked by the red dot on the crimpers. Alternatively, if the crimper does not have color markings, use the gauge markings on the side.

The terminal should be sitting horizontal with the barrel side up. The tool is then held perpendicular to the terminal and placed over the barrel, nearest to the ring (or other connection type). To finish the crimp, the tool is squeezed with a considerable force. In general, it is almost impossible to ‘over crimp’ a connection.

crimped

After the crimp is completed, the wire and connector should still hold together after trying to pull them apart with great force. If the connection can be pulled apart, the crimp was not done correctly. It is better to have the crimp fail now, versus after it has been installed in its application. Below is a military spec chart for crimped connections.

Mil Spec Chart

Common Mishaps

Wrong size connector for the wire or wrong size wire for the connector.

bad crimp 1

Bad crimp. Connector was too small for the gauge of wire chosen.

Be cautious not to strip too much insulation off.

bad crimp 2

Too much insulation has been stripped off, too much bare wire exposed

It is also worth mentioning that, while not necessarily harmful, The wire should not be protruding too far past the barrel. If this happens, trimming the wire is recommended.

bad crimp 3

The excess bare wire should be trimmed off

Resources and Going Further

You should now be familiar with electrical wire and how useful it is in the world of electronics. Whether you’re prototyping, reworking, or building a final product, electrical wire can be your best friend.

Here are some other tutorials you can explore that involve electrical wire.

  • Wire is the most basic element when creating your own circuits.
  • Unsure which connectors to use? Have a look at Connector Basics to get what you need!
  • Want to start prototyping? Check out Breadboards to get going!

 


cc

 Creative Commonstutorials are CC BY-SA 4.0

Original From:

https://learn.sparkfun.com/tutorials/working-with-wire

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.

Connector Basics

Introduction

Connectors are used to join subsections of circuits together. Usually, a connector is used where it may be desirable to disconnect the subsections at some future time: power inputs, peripheral connections, or boards which may need to be replaced.

Covered in This Tutorial

In this tutorial we will go over:

  • Basic connector terminology
  • Categorize connectors into distinguishable categories
  • Talk about the differences between connectors within those categories.
  • Show how to identify polarized connectors
  • Talk about which connectors are best suited for certain applications

Suggested Reading

You may find these concepts useful before starting on this tutorial:

Connector Terminology

Before we get started discussing some commonly used connectors, let’s explore the terminology used to describe connectors.

Gender - The gender of a connector refers to whether it plugs in or is plugged into and is typically male or female, respectively (kids, ask your parents for a more thorough explanation). Unfortunately, there are cases where a connector may be referred to as “male” when it would appear to be female; in the examples section, we’ll point a few of those out as we discuss individual component types and explain why that’s the case.

Male and female 2.0mm PH series JST connectors

Male (left) and female 2.0mm PH series JST connectors. In this case, gender is determined by the individual conductor.

Polarity - Most connectors can only be connected in one orientation. This trait is called polarity, and connectors which have some means to prevent them being connected wrong are said to be polarized, or sometimes keyed.

North America wall plug

A polarized North American wall plug. By having two different widths for the plug blades, the plug will only go into the outlet one way.

Contact - Contacts are the business portion of the connector. They are the metal parts which touch each other, forming an electrical connection. This is also where problems occur: the contacts can become soiled or oxidized, or the springiness required to hold the contacts together may fade with time.

ADH8066 mating connector

The contacts on this connector are clearly visible.

Pitch - Many connectors consist of an array of contacts in a repeated pattern. The pitch of the connector is the distance from the center of one contact to the center of the next. This is important, because there are many families of contacts which look very similar but may differ in pitch, making it difficult to know that you are purchasing the right mating connector.

.1" pin header connector examples

The pitch of the pins on the headers on a standard Arduino is .1".

Mating cycles - Connectors have a finite life, and connecting and disconnecting them is what wears them out. Datasheets usually present that information in terms of mating cycles, and it varies widely from one technology to another. A USB connector may have a lifetime in the thousands or tens of thousands of cycles, while a board-to-board connector designed for use inside of consumer electronics may be limited to tens of cycles. It’s important that you select a connector with a suitable life for the application.

Connector for GS406 GPS module

Mating connector for the GS406 GPS module. The connector’s datasheet indicates a maximum of 50 insertion cycles for this part.

Mount - This one has the potential for being confusing. The term “mount” can refer to several things: how the connector is mounted in use (panel mount, free-hanging, board mount), what the angle of the connector is relative to its attachment (straight or right-angle), or how it is mechanically attached (solder tab, surface mount, through hole). We’ll discuss this more in the examples section for each individual connector.

Comparison of different mounting methods for barrel-type connectors

A comparison of three different methods of mounting the same barrel connector: (left to right) board mount, inline cable mount, and panel mount.

Strain relief - When a connector mounts to a board or cable, the electrical connections tend to be somewhat fragile. It is typical to provide some kind of strain relief to transfer any forces acting on that connector to a more mechanically sound object than the fragile electrical connections. Again, there will be some good examples of this later on.

1/8" Headphone jack showing strain relief

This 1/8" headphone jack comes with a strain relief “boot” slid over the cable to prevent forces on the cable from being transmitted directly to the electrical joints.

USB Connectors

USB connectors come in two flavors: host and peripheral. In the USB standard, there is a difference between the two, and the connectors on cables and devices reflect this. However, all USB connectors will have some things in common:

  • Polarization - A USB connector can only nominally be inserted one way. It may be possible to force a connector in wrong, but that will result in damage to the device.
  • Four contacts - All USB connectors have at least four contacts (although some may have five, and USB 3.0connectors have even more). These are for power, ground, and two data lines (D+ and D-). USB connectors are designed to transmit 5V, up to 500mA.
  • Shielding - USB connectors are shielded, such that a metal shell which is not part of the electrical circuit is provided. This is important to keep the signal intact in environments with a lot of electrical “noise”.
  • Robust power connection - It’s important for the power pins to make connection before the data lines, to avoid trying to power the device over the data lines. All USB connectors are designed with this in mind.
  • Molded strain relief - All USB cables have plastic overmolding at the connector to prevent strain on the cable that could potentially damage the electrical connections.

Labeled image of USB extension cable

USB extension cable, with some of the common features of USB connectors labeled.

USB-A Connectors

USB-A female is the standard “host” connector type. This is found on computers, hubs, or any device intended to have peripherals plugged into it. It is also possible to find extension cables with a female A connector and a male A connector on the other end.

USB-A ports on a laptop computer.

Female USB-A ports on the side of a laptop. The blue connector is USB 3.0 compliant.

USB-A male is the standard “peripheral” connector type. Most USB cables will have one end terminating in a USB-A male connector, and many devices (such as keyboards and mice) will have a built-in cable terminated with a USB-A male connector. It’s also possible to find USB-A male connectors that are board mountable, for devices like USB memory sticks.

USB-A male connector examples

Two types of Male USB-A connectors, on a SparkFun Cerberus cable and an AVR Stick development board.

USB-B Connectors

USB-B female is a standard for peripheral devices. It’s bulky, but robust, so in applications where size is not an issue, it’s the preferred means for providing a removable connector for USB connectivity. It is usually a through-hole board mount connector, for maximum reliability, but there are panel-mount options for it as well.

USB-B connector on an Arduino Uno

Arduino boards, including this Uno, have long used the female USB-B connector, due to its low cost and durability.

USB-B male is almost exclusively found at the end of a cable. USB-B cables are ubiquitous and inexpensive, which also contributes to the popularity of the USB-B connection.

Male USB-B connector

USB-B male connector on the end of a SparkFun Cerberus cable.

USB-Mini Connectors

The USB-Mini connection was the first standard attempt to reduce the size of the USB connector for smaller devices. USB-Mini female is typically found on smaller peripherals (MP3 players, older cellphones, small external hard drives), and is usually a surface mount connector, trading robustness for size. USB-Mini is slowly being phased out in favor of the USB-Micro connector.

USB-Mini female connector

USB-Mini female connector on a Protosnap Pro Mini.

USB-Mini male is another cable-only connector. As with USB-B, it’s extremely common, and cables can be found cheaply almost anywhere.

USB-Mini male connector

USB-Mini male connector on the end of a SparkFun Cerberus cable.

USB-Micro Connectors

USB-Micro is a fairly recent addition to the USB connector family. As with USB-Mini, the primary concern is size reduction, but USB-Micro adds a fifth pin for low-speed signalling, allowing it to be used in USB-OTG (On-the-go) applications where a device may want to operate as either a host or a peripheral depending on circumstances.

USB-Micro female is found on many newer peripherals, such as digital cameras and MP3 players. The adoption of USB-micro as a standard charge port for all new cellular phones and tablet computers means that chargers and data cables are becoming increasingly common, and USB-Micro is likely to supplant USB-Mini in the coming years as the small-factor USB connector of choice.

USB-Micro female connector

USB-Micro female connector on a LilyPad Arduino USB board.

USB-Micro male is also a cable-only connector. There are generally two types of cables with USB-Micro male ends: one for connecting a device with a USB-Micro port as a peripheral to a USB host device and one for adapting the USB-Micro female port to a USB-A female port, to be used in USB-OTG capable devices.

USB-Micro male connector

USB-Micro male connector on the SparkFun Cerberus cable.

USB-A female to USB-Micro adapter

Adapter pigtail for using USB-OTG capable devices having only a USB-Micro port with standard USB peripherals. Note that not all devices supporting USB-OTG will work with this pigtail.

Audio Connectors

Another familiar connector group are those used for audio-visual applications–RCA and phono. While these can’t truly be considered to be of the same family, as the various USB connectors are, we’ll consider both of them to be in the same vein.

“Phone” Type Connectors

You’ll probably immediately recognize the 1/8" version of this connector as a the plug on the end of a pair of headphones. These connectors actually come in three common sizes: ¼" (6.35mm), 1/8" (3.5mm), and 2.5mm. ¼" size connectors find a lot of use in the professional audio and music community- most electric guitars and amplifiers have ¼" tip-sleeve (TS) jacks on them. 1/8" tip-ring-sleeve (TRS) is very common as the connector for headphones or audio output signals on MP3 players or computers. Some cell phones will provide a 2.5mm tip-ring-ring-sleeve (TRRS) jack for connecting to headphones that also include a microphone for hands-free communications.

The common availability of these connectors and cables makes them a good candidate for general purpose connectivity applications–for instance, long before USB, Texas Instruments graphing calculators used a 2.5mm TRS connector for a serial programming connector. It should be remembered that tip-sleeve connector types are not designed for carrying power; during insertion, the tip and the sleeve can be momentarily shorted together, which may damage the power supply. The lack of shielding makes them poor candidates for high-speed data, but low speed serial data can be passed through these connectors.

1/8" TRS phone plug

Headphone-type TRS phone plug, 1/8". Typically, tip and ring will carry the stereo audio signals while sleeve will be connected to ground.

1/8" TS phone plug

1/8" phone plug. Note the lack of a ring contact on this connector.

1/8" board mount headphone jack

1/8" board mount headphone jack with pins corresponding pin connections labeled. When no jack is inserted, an internal switch connects the tip and ring pins to the adjacent unmarked pins, allowing insertion detection.

RCA Connectors

Familiar as the home-stereo connector of choice for many decades, the RCA connector was introduced in the 1940s by RCA for home phonographs. It is slowly being supplanted by connections like HDMI in the audio-visual realm, but the ubiquity of the connectors and cables makes it a good candidate for home-built systems. It will be a long time before it is obsolete.

Female RCA connectors are usually found on devices, although it is possible to find extension or conversion cables with female jacks on them. Most RCA connectors are connected to one of four types of signals: component video (PAL or NTSC, depending on where the equipment was sold), composite video, stereo audio, or S/PDIF audio.

Female RCA plug, for video signals.

Female RCA connector, for video signals. Typically, NTSC or PAL video signal connectors will be yellow.

Male RCA connectors are usually found on cables.

Male RCA plugs

Male RCA plugs. Red and white are usually for audio applications, with red denoting the “right” audio channel.

Power Connectors

While many connectors carry power in addition to data, some connectors are used specifically to provide power connections to devices. These vary widely by application and size, but we will only focus on some of the most common ones here.

Barrel Connectors

Barrel connectors are typically found on low-cost consumer electronics which can be plugged into wall power via bulky AC wall adaptors. Wall adaptors are widely available, in a variety of power ratings and voltages, making barrel connectors a common means for connecting power to small projects.

The female barrel connector, or “jack”, can be purchased in several varieties: PCB mounted (surface mount or through hole), cable mount, or panel mount. Some of these connectors will have an additional contact that allows the application to detect whether a power supply is plugged into the barrel jack or not, thus allowing the device to bypass batteries and save battery life when running on external power.

Female barrel connector

Female barrel connector. When no plug is inserted, the “insertion detection” pin will be shorted to the “sleeve” pin.

The male barrel connector, or “plug”, is usually only found in a wire termination variety, although there are multiple methods of attaching the plug to the end of the wire. It’s also possible to get plugs that come pre-attached to a cable.

Male barrel plug

Unattached male barrel plug, for attachment to any power supply. Note that the sleeve connection is designed to be crimped onto the wire for extra strain relief.

Barrel connectors provide only two connections, frequently referred to as “pin” or “tip” and “sleeve”. When ordering, there are three differentiating characteristics of a barrel connection- inner diameter (the diameter of the pin inside the jack), outer diameter (the diameter of the sleeve on the outside of the plug), and polarity (whether the sleeve voltage is higher or lower than the tip voltage).

Sleeve diameter is most commonly either 5.5mm or 3.5mm.

Pin diameter is contingent upon sleeve diameter; a 5.5mm sleeve will have either a 2.5mm or 2.1mm pin. Unfortunately, this means that a plug designed for a 2.5mm pin will fit in a 2.1mm jack, but that the connection will be, at best, intermittent. 3.5mm sleeve plugs usually mate to a jack with a 1.3mm pin.

Polarity is the final aspect to consider; most often, the sleeve will be considered 0V and the tip will be a positive voltage relative to the sleeve. Many devices will have a small diagram indicating the polarity expected by the device; care should be taken to adhere to this, as an improper power supply may damage the device.

Plugs of both sleeve sizes are usually 9.5mm long, but longer and shorter ones do exist. All SparkFun products use a positive polarity 5.5mm sleeve and a 2.1mm pin; we recommend sticking to that standard where possible, as it seems to be the most common flavor found in the wild.

Barrel connector polarity label

Common polarity diagrams for AC adaptors with barrel plugs. Positive polarity (tip positive, sleeve 0V) is most common. Diagram courtesy Wikipedia user Three-quarter-ten.

“Molex” Connectors

Most computer hard drives, optical drives, and other internal peripherals get power through what is typically called a “Molex” connector. To be more accurate, it’s a Molex series 8981 connector–Molex is actually the name of the company which initially designed this connector back in the 1950s–but common usage has denuded that fact somewhat.

Molex connectors are designed to carry a lot of current: up to 11A per pin. For projects where a lot of power may be needed–a CNC machine, for instance, or a 3D printer- a very common method for powering the project is to use a desktop PC power supply and connecting the various system circuits through Molex connectors.

The Molex connector is one where the male/female terminology is a bit odd. The female connector is usually found on the end of a cable, and it slips inside of a plastic shell which surrounds the male pins on the male connector. Usually, the connectors are press-fit only, and very, very tight–they are intended to be connected and disconnected only a few times and, as such, are a bad choice for systems where connections will frequently be changed.

Male Molex connector

Male Molex connector. The gender of the pins inside the connector is what signifies the gender of the connector as a whole.

Female Molex connector

Female Molex connector on a project power supply.

IEC Connector

As with the Molex connector, this is a case where a generalized component name has come to be synonymous with a single, particular item. IEC connector usually refers to the power supply inlet which is commonly seen on desktop PC power supplies. Strictly speaking, that’s an IEC 60320-1 C13 (female) and C14 (male) connector.

IEC 60320-1 C14 male connector

C14 male IEC power inlet, on a DC project power supply. Note that, as with the Molex connector, the gender of the connector is defined by the pins within the hood.

C13 female IEC power connector

C13 female IEC power connector, on a fairly standard AC power supply cable. Cables with this end can be found all around the world, usually with the dominant local AC connector at the other end.

IEC connectors are used almost exclusively for AC power input. The nice thing about using one on a project is that IEC-to-wall cables are extremely common and available with localized wall plugs for most international locations!

JST Connector

At SparkFun, we frequently refer to “2.0mm JST Connectors”. This is yet another generalization of a specific product- JST is a Japanese company which makes high-quality connectors, and our 2.0mm JST connector of choice is the PH series two-position polarized connector.

All of SparkFun’s single-cell lithium-polymer ion batteries come standard with this type of JST connector, and many of our boards include this connector (or a footprint for it) as a power supply input. It has the advantage of being compact, durable, and difficult to connect backwards. Another feature, which can be an advantage or a disadvantage, depending on how you look at it, is that the JST connector is wicked hard to disconnect (although a carefully applied diagonal cuttercan be helpful!) once it’s mated. While this makes it unlikely to fail during use, it also means that disconnecting the battery for charging can damage the battery connector.

2-Pin JST male connector on a LilyPad Arduino USB board

2-Pin JST male connector on a LilyPad Arduino USB board. Again, as with the Molex, the pins inside the hood determine the gender of the connector.

Male and female 2-pin JST connectors

Male and female 2-pin JST connectors.

There are PH series connectors with more than two positions; SparkFun even sells them. However, our most frequent application is for the 2-position battery connection.

Pin Header Connectors

Pin header connectors comprise several different means of connection. Generally, one side is a series of pins which are soldered to a PCB, and they can either be at a right-angle to the PCB surface (usually called “straight”) or parallel to the board’s surface (confusingly referred to as “right-angle” pins). Such connectors come in a variety of pitches, and may have any number of individual rows of pins.

Right angle female header pin connector

Right-angle female header pin connection on an FTDI basic board.

The most commonly seen pin headers are .1" single or double row connectors. These come in male and femaleversions, and are the connectors used to connect Arduino boards and shields together. Other pitches are not uncommon; for instance, the XBee wireless module uses a 2.0mm pitch version of the same connector.

.1" pin header connector examples

.1" pin header connectors, male and female, on an Arduino Uno board.

A common variation on this part is a “machine pin” version. While the normal version is formed out of stamped and folded sheet metal, machine pin connectors are formed by tooling the metal into the desired shape. The result is a more robust connector, with a better joint and longer life, making it somewhat more expensive.

Female machine pin headers

Female machine pin headers. Note that these are designed to be snapped apart into smaller sections, while standard .1" female header pin connectors are not. It’s also important to note that not all non-machine pin header connectors will mate with the machine pin variety.

Cables made to connect to these pin headers are usually one of two types: individual wires with crimp connectors on them or ribbon cables with insulation displacement connectors. These can simply be clamped onto the end of a ribbon cable, which creates a connection to each one of the conductors in the ribbon cable. Generally, cables are only available as female gender and expect a male pin to mate with.

Crimp connected header cable

Six-position crimp-type cable. Each wire is individually stripped, a connector crimped to it, and then the connectors are inserted into the plastic frame.

2x5 insulation displacement connectors on a ribbon cable

2x5 insulation displacement connectors (IDC) on a ribbon cable. This type of cable can be quickly assembled because it does not require stripping of individual connectors. It also has polarizing tabs on each end, to prevent incorrect insertion in the mating board-side connector.

Temporary connectors

Screw Terminals

In some cases, it may be desirable to be able to connect bare, unterminated wire to a circuit. Screw terminals provide a good solution for this. They are also good for situations in which a connection should be capable of supporting multiple different connecting devices.

The downside of screw terminals is that they can come undone fairly easily, leaving a bare wire waving around in your circuit. A small dab of hot glue can address this without being too difficult to remove later.

Screw terminals are typically designed for a narrow range of wire gauges, and wires that are too small can be as big a problem as wires that are too big. SparkFun carries two types of screw terminal–a .1" pitch version and a 3.5mm version. Most screw terminals are highly modular, and they can easily be extended at the same pitch by simply connecting two or more smaller sections together.

3.5mm screw terminals


-> 3.5mm pitch screw terminals, showing the insertion point of the wire to be connected, the retention screw which holds the wire in place, and the modular connectors on the sides of the individual units allowing multiple pieces to be ganged together. <-

Banana Connector

Most pieces of power test equipment (multimeters, power supplies) have a very simple connector called a “banana jack” on it. These mate to “banana plugs”, crimped, sprung metal plugs, meant to make a single power connection. They are frequently available in a stackable configuration and can be easily connected to any type of wire. They are capable of carrying several amps of current and are inexpensive.

Banana plug

Stackable banana plug. Note that there are two different ways to plug in an additional banana plug.

Variable power supply with banana plugs

Extech variable bench supply with banana jacks on the front.

Alligator Clip

Named for obvious reasons, alligator clips are good for test connections to posts or bare wires. They tend to be bulky, easily cause shorts to nearby bare metal, and have a reasonably poor grip that can be easily compromised. They are primarily used for low-cost connections during debugging.

Alligator clips

“third hand” tool, which uses alligator clips to hold work pieces, holding a wire terminated with an alligator clip for electrical test. Note the plastic boot surrounding the alligator clip, to make it less likely to short to other connections.

IC Clip (or IC Hook)

For more delicate probing operations, there are a variety of IC clips on the market. These are sized to allow a user to clip them onto the pins of an IC without contacting adjacent pins; some of them are delicate enough to be clipped onto even fine-pitched SMD component legs. These smaller clips can be found on logic analyzers as well as test leads, which are great for prototyping or troubleshooting circuits.

Large IC clip

large IC clip on the end of a wire. This clip is still small enough to be connected to a single leg on a through-hole chip without causing a problem for adjacent pins.

Other Connectors

RJ-type Modular Connectors

Registered jack connectors are standard for telecommunications equipment into a local exchange. The names one normally hears associated with them (RJ45, RJ12, etc) are not necessarily correct, as the RJ designator is a based on a combination of the number of positions, the number of conductors actually present, and the wiring pattern. For example, while the ends of a standard ethernet cable are usually referred to as “RJ45”, RJ45 actually implies not only an 8 position, 8 conductor modular jack, it also implies that it is wired for ethernet.

These modular connectors can be very useful, since they combine ready availability, multiple conductors, moderate flexibility, low cost, and moderate current carrying capacity. While not originally intended to deliver a great deal of power, these cables can be used to deliver data and a couple of hundred milliamps from one device to another. Care should be taken to ensure that jacks provided for applications like this are not connected to conventional ethernet ports, as damage will result.

8p8c "RJ45" style modular jack

A standard 8p8c (8-position, 8-conductor) “RJ45” modular jack. Be aware that if you intend to use this type of jack to pass DC signals and power, you must avoid using connectors with built-in signal transformers.

D-sub Type Connectors

Named for the shape of their shell, D-subminiature connectors are a classic standard in the computing world. There are four very common varieties of this connector: DA-15, DB-25, DE-15, and DE-9. The pin number indicates the number of connections provided, and the letter combination indicates the size of the shell. Thus, DE-15 and DE-9 have the same shell size, but a different number of connections.

Female board-mount DE9 connector

Female DE-9 board-mount connector. Gender is defined by the pins or sockets associated with each signal, not the connector as a whole, making this connector female despite the fact that it effectively inserts into the shell of the mating connector.

DB-25 and DE-9 are the most useful to the hardware hacker; many desktop computers still include at least one DE-9 serial port, and often one DB-25 parallel port. Cables terminated with DE-9 and DB-25 connectors are widely available, too. As with the modular connector above, these can be used to provide power and point-to-point communications between two devices. Again, since the common usage of these cables does not include power transmission, it is very important that any repurposing of the cables be done cautiously, as a non-standard device plugged into a standard port can easily cause damage.

Resources and Going Further

You should now have a good idea which connectors are suited best for certain applications and which connectors will be useful to you in your next project. Please check out these other links to lean more about connectors.

  • Giant database of connectors and pinouts - Everything you never wanted to know about pretty much any connector, ever. A good site for basic info about connectors, but often quite shy on interface details.
  • Wikipedia article on registered jack connectors - More on the confusing world of the registered jack (RJ) connector, which is often misunderstood and misused.
  • Wikipedia article on D-subminiature connectors - As with the registered jack connector, misinformation abounds on the D-subminiature standard. Wikipedia has a great article about it.
  • Mouser electronics catalog - Browsing an electronics supplier catalog is often a great place to start looking for the name of an unidentified connector; Mouser’s enhanced online catalog is just as good as the print version, with fewer papercuts!

If you’d like top explore more SparkFun tutorials, check out these other offerings:

 


cc

 Creative Commonstutorials are CC BY-SA 4.0

Original From:

https://learn.sparkfun.com/tutorials/connector-basics

PCB Basics

Overview

One of the key concepts in electronics is the printed circuit board or PCB. It’s so fundamental that people often forget to explain what a PCB is. This tutorial will breakdown what makes up a PCB and some of the common terms used in the PCB world.

Blank PCB from the ClockIt Kit

Over the next few pages, we’ll discuss the composition of a printed circuit board, cover some terminology, a look at methods of assembly, and discuss briefly the design process behind creating a new PCB.

Suggested Reading

Before you get started you may want to read up on some concepts we build upon in this tutorial:


Translations

Minh Tuấn was kind enough to translate this tutorial to Vietnamese. You can view the translation here.

What's a PCB?

Printed circuit board is the most common name but may also be called “printed wiring boards” or “printed wiring cards”. Before the advent of the PCB circuits were constructed through a laborious process of point-to-point wiring. This led to frequent failures at wire junctions and short circuits when wire insulation began to age and crack.

Mass of wire wrap
courtesy Wikipedia user Wikinaut

A significant advance was the development of wire wrapping, where a small gauge wire is literally wrapped around a post at each connection point, creating a gas-tight connection which is highly durable and easily changeable.

As electronics moved from vacuum tubes and relays to silicon and integrated circuits, the size and cost of electronic components began to decrease. Electronics became more prevalent in consumer goods, and the pressure to reduce the size and manufacturing costs of electronic products drove manufacturers to look for better solutions. Thus was born the PCB.

LilyPad PCB

PCB is an acronym for printed circuit board. It is a board that has lines and pads that connect various points together. In the picture above, there are traces that electrically connect the various connectors and components to each other. A PCB allows signals and power to be routed between physical devices. Solder is the metal that makes the electrical connections between the surface of the PCB and the electronic components. Being metal, solder also serves as a strong mechanical adhesive.

Composition

A PCB is sort of like a layer cake or lasagna- there are alternating layers of different materials which are laminated together with heat and adhesive such that the result is a single object.

alt text

Let’s start in the middle and work our way out.

FR4

The base material, or substrate, is usually fiberglass. Historically, the most common designator for this fiberglass is “FR4”. This solid core gives the PCB its rigidity and thickness. There are also flexible PCBs built on flexible high-temperature plastic (Kapton or the equivalent).

You will find many different thickness PCBs; the most common thickness for SparkFun products is 1.6mm (0.063"). Some of our products- LilyPad boards and Arudino Pro Micro boards- use a 0.8mm thick board.

Perf board

Cheaper PCBs and perf boards (shown above) will be made with other materials such as epoxies or phenolics which lack the durability of FR4 but are much less expensive. You will know you are working with this type of PCB when you solder to it - they have a very distictive bad smell. These types of substrates are also typically found in low-end consumer electronics. Phenolics have a low thermal decomposition temperature which causes them to delaminate, smoke and char when the soldering iron is held too long on the board.

Copper

The next layer is a thin copper foil, which is laminated to the board with heat and adhesive. On common, double sided PCBs, copper is applied to both sides of the substrate. In lower cost electronic gadgets the PCB may have copper on only one side. When we refer to a double sided or 2-layer board we are referring to the number of copper layers (2) in our lasagna. This can be as few as 1 layer or as many as 16 layers or more.

Exposed Copper on PCB

PCB with copper exposed, no solder mask or silkscreen.

The copper thickness can vary and is specified by weight, in ounces per square foot. The vast majority of PCBs have 1 ounce of copper per square foot but some PCBs that handle very high power may use 2 or 3 ounce copper. Each ounce per square translates to about 35 micrometers or 1.4 thousandths of an inch of thickness of copper.

Soldermask

The layer on top of the copper foil is called the soldermask layer. This layer gives the PCB its green (or, at SparkFun, red) color. It is overlaid onto the copper layer to insulate the copper traces from accidental contact with other metal, solder, or conductive bits. This layer helps the user to solder to the correct places and prevent solder jumpers.

In the example below, the green solder mask is applied to the majority of the PCB, covering up the small traces but leaving the silver rings and SMD pads exposed so they can be soldered to.

Green Solder Mask

Soldermask is most commonly green in color but nearly any color is possible. We use red for almost all the SparkFun boards, white for the IOIO board, and purple for the LilyPad boards.

Silkscreen

The white silkscreen layer is applied on top of the soldermask layer. The silkscreen adds letters, numbers, and symbols to the PCB that allow for easier assembly and indicators for humans to better understand the board. We often use silkscreen labels to indicate what the function of each pin or LED.

PCB with silkscreen

Silkscreen is most commonly white but any ink color can be used. Black, gray, red, and even yellow silkscreen colors are widely available; it is, however, uncommon to see more than one color on a single board.

Terminology

Now that you’ve got an idea of what a PCB structure is, let’s define some terms that you may hear when dealing with PCBs:

  • Annular ring - the ring of copper around a plated through hole in a PCB.

Annular ring on resistor Annular ring on vias

Examples of annular rings.

  • DRC - design rule check. A software check of your design to make sure the design does not contain errors such as traces that incorrectly touch, traces too skinny, or drill holes that are too small.
  • Drill hit - places on a design where a hole should be drilled, or where they actually were drilled on the board. Inaccurate drill hits caused by dull bits are a common manufacturing issue.

Bad drill hits

Not so accurate, but functional drill hits.

  • Finger - exposed metal pads along the edge of a board, used to create a connection between two circuit boards. Common examples are along the edges of computer expansion or memory boards and older cartridge-based video games.
  • Mouse bites - an alternative to v-score for separating boards from panels. A number of drill hits are clustered close together, creating a weak spot where the board can be broken easily after the fact. See the SparkFun Protosnap boards for a good example.

LilyPad Protosnap with mouse bites

Mouse bites on the LilyPad ProtoSnap allow the PCB to be snapped apart easily.

  • Pad - a portion of exposed metal on the surface of a board to which a component is soldered.

PTH Pads SMD Pads

PTH (plated through-hole) pads on the left, SMD (surface mount device) pads on the right.

  • Panel - a larger circuit board composed of many smaller boards which will be broken apart before use. Automated circuit board handling equipment frequently has trouble with smaller boards, and by aggregating several boards together at once, the process can be sped up significantly.
  • Paste stencil - a thin, metal (or sometimes plastic) stencil which lies over the board, allowing solder paste to be deposited in specific areas during assembly.

Abe does a quick demonstration of how to line up a paste stencil and apply solder paste.

  • Pick-and-place - the machine or process by which components are placed on a circuit board.

Bob shows us the SparkFun MyData Pick and Place machine. It’s pretty awesome.

  • Plane - a continuous block of copper on a circuit board, define by borders rather than by a path. Also commonly called a “pour”.

PCB ground pour

Various portions of the PCB that have no traces but has a ground pour instead.

  • Plated through hole - a hole on a board which has an annular ring and which is plated all the way through the board. May be a connection point for a through hole component, a via to pass a signal through, or a mounting hole.

Plated through hole resistor

A PTH resistor inserted into the FabFM PCB, ready to be soldered. The legs of the resistor go through the holes. The plated holes can have traces connected to them on the front of the PCB and the rear of the PCB.

  • Pogo pin - spring-loaded contact used to make a temporary connection for test or programming purposes.

Pogo Pin

The popular pogo pin with pointed tip. We use tons of these on our test beds.

  • Reflow - melting the solder to create joints between pads and component leads.
  • Silkscreen - the letters, number, symbols, and imagery on a circuit board. Usually only one color is available, and resolution is usually fairly low.

Silkscreen

Silkscreen identifying this LED as the power LED.

  • Slot - any hole in a board which is not round. Slots may or may not be plated. Slots sometimes add to add cost to the board because they require extra cut-out time.

slot

Complex slots cut into the ProtoSnap - Pro Mini. There are also many mouse bites shown. Note: the corners of the slots cannot be made completely square because they are cut with a circular routing bit.

  • Solder paste - small balls of solder suspended in a gel medium which, with the aid of a paste stencil, are applied to the surface mount pads on a PCB before the components are placed. During reflow, the solder in the paste melts, creating electrical and mechanical joints between the pads and the component.

alt text

Solder paste on a PCB shortly before the components are placed. Be sure to read about paste stencil above as well.

  • Solder pot - a pot used to quickly hand solder boards with through hole components. Usually contains a small amount of molten solder into which the board is quickly dipped, leaving solder joints on all exposed pads.
  • Soldermask - a layer of protective material laid over the metal to prevent short circuits, corrosion, and other problems. Frequently green, although other colors (SparkFun red, Arduino blue, or Apple black) are possible. Occasionally referred to as “resist”.

alt text

Solder mask covers up the signal traces but leaves the pads to solder to.

  • Solder jumper - a small, blob of solder connecting two adjacent pins on a component on a circuit board. Depending on the design, a solder jumper can be used to connect two pads or pins together. It can also cause unwanted shorts.
  • Surface mount - construction method which allows components to be simply set on a board, not requiring that leads pass through holes in the board. This is the dominant method of assembly in use today, and allows boards to be populated quickly and easily.
  • Thermal - a small trace used to connect a pad to a plane. If a pad is not thermally relieved, it becomes difficult to get the pad to a high enough temperature to create a good solder joint. An improperly thermally relieved pad will feel “sticky” when you attempt to solder to it, and will take an abnormally long time to reflow.

thermal

On the left, a solder pad with two small traces (thermals) connecting the pin to the ground plane. On the right, a via with no thermals connecting it completely to the ground plane.

  • Thieving - hatching, gridlines, or dots of copper left in areas of a board where no plane or traces exist. Reduces difficulty of etching because less time in the bath is required to remove unneeded copper.
  • Trace - a continuous path of copper on a circuit board.

Traces on PCB

A small trace connecting the Reset pad to elsewhere on the board. A larger, thicker trace connects to the 5V power pin.

  • V-score- a partial cut through a board, allowing the board to be easily snapped along a line.
  • Via - a hole in a board used to pass a signal from one layer to another. Tented vias are covered by soldermask to protect them from being soldered to. Vias where connectors and components are to be attached are often untented (uncovered) so that they can be easily soldered.

alt text alt text

Front and back of the same PCB showing a tented via. This via brings the signal from the front side of the PCB, through the middle of the board, to the back side.

  • Wave solder - a method of soldering used on boards with through-hole components where the board is passed over a standing wave of molten solder, which adheres to exposed pads and component leads.

Designing Your Own!

How do you go about designing your own PCB? The ins and outs of PCB design are way too in depth to get into here, but if you really want to get started, here are some pointers:

  1. Find a CAD package: there are a lot of low-cost or free options out there on the market for PCB design. Things to consider when choosing a package:
    • Community support: are there a lot of people using the package? The more people using it, the more likely you are to find ready-made libraries with the parts you need.
    • Ease-of-use: if it’s painful to use it, you won’t.
    • Capability: some programs place limitations on your design- number of layers, number of components, size of board, etc. Most of them allow you to pay for a license to upgrade their capability.
    • Portability: some free programs do not allow you to export or convert your designs, locking you in to one supplier only. Maybe that’s a fair price to pay for convenience and price, maybe not.
  2. Look at other people’s layouts to see what they have done. Open Source Hardware makes this easier than ever.
  3. Practice, practice, practice.
  4. Maintain low expectations. Your first board design will have lots of problems. Your 20th board design will have fewer, but will still have some. You’ll never get rid of them all.
  5. Schematics are important. Trying to design a board without a good schematic in place first is an exercise in futility.

Finally, a few words on the utility of designing your own circuit boards. If you plan on making more than one or two of a given project, the payback on designing a board is pretty good- point-to-point wiring circuits on a protoboard is a hassle, and they tend to be less robust than purpose-designed boards. It also allows you to sell your design if it turns out to be popular.

(中文) 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!

Using EAGLE: Board Layout

Previously on Using EAGLE

EAGLE’s board designer is where a good portion of the magic happens. It’s here where the dimensions of the board come together, parts are arranged, and connected by copper traces. In the board editor, the conceptual, idealized schematic you’ve designed becomes a precisely dimensioned and routed PCB.

In this tutorial we’ll cover every step in EAGLE PCB design: from placing parts, to routing them, to generating gerber files to send to a fab house. We’ll also go over the basics of EAGLE’s board editor, beginning with explaining how the layers in EAGLE match up to the layers of a PCB.

 

Create a Board From Schematic

Before starting this tutorial, read through and follow along with the Using EAGLE: Schematic tutorial (not to mention the Setting Up EAGLE tutorial before that). The schematic designed in that tutorial will be used as the foundation for the PCB designed here.

1

           The schematic from previous tutorial, complete with an ATmega328P, barrel jack connector, LEDs, resistors, capacitors, and connectors.

To switch from the schematic editor to the related board, simply click the Generate/Switch to Board command –  (on the top toolbar, or under the File menu) – which should prompt a new, board editor window to open. All of the parts you added from the schematic should be there, stacked on top of each other, ready to be placed and routed.

2

The board and schematic editors share a few similarities, but, for the most part, they’re completely different animals. On the next page, we’ll look at the colored layers of the board editor, and see how they compare to the actual layers of a PCB.

Layers Overview

           PCB composition is all about layering one material over another. The thickest, middle part of the board is a insulating substrate (usually FR4). On either side of that is a thin layer of copper, where our electric signals pass through. To insulate and protect the copper layers, we cover them with a thin layer of lacquer-like solder mask, which is what gives the PCB color (green, red, blue, etc.). Finally, to top it all off, we add a layer of ink-like silkscreen, which can add text and logos to the PCB.

3

The layers of a double-sided PCB (image from the PCB Basics tutorial).

EAGLE’s Layers

The EAGLE board designer has layers just like an actual PCB, and they overlap too. We use a palette of colors to represent the different layers. Here are the layers you’ll be working with in the board designer:

Color Layer Name Layer Number Layer Purpose
Top 1 Top layer of copper
Bottom 16 Bottom layer of copper
Pads 17 Through-hole pads. Any part of the green circle is exposed copper on both top and bottom sides of the board.
Vias 18 Vias. Smaller copper-filled drill holes used to route a signal from top to bottom side. These are usually covered over by soldermask. Also indicates copper on both layers.
Unrouted 19 Airwires. Rubber-band-like lines that show which pads need to be connected.
Dimension 20 Outline of the board.
tPlace 21 Silkscreen printed on the top side of the board.
bPlace 22 Silkscreen printed on the bottom side of the board.
tOrigins 23 Top origins, which you click to move and manipulate an individual part.
bOrigins 24 Origins for parts on the bottom side of the board.
/ / Hatch tStop 29 Top stopmask. These define where soldermask should not be applied.
\ \ Hatch bStop 30 Absent soldermask on the bottom side of the board.
Holes 45 Non-conducting (not a via or pad) holes. These are usually drill holes for stand-offs or for special part requirements.
tDocu 51 Top documentation layer. Just for reference. This might show the outline of a part, or other useful information.

 

To turn any layer off or on, click the “Layer Settings…” button –  – and then click a layer’s number to select or de-select it. Before you start routing, make sure the layers above (aside from tStop and bStop) are visible.

Selecting From Overlapping Objects

Here’s one last tip before we get to laying our board out. This is an interface trick that trips a lot of people up. Since the board view is entirely two-dimensional, and different layers are bound to overlap, sometimes you have to do some finagling to select an object when there are others on top of it.

Normally, you use the mouse’s left-click to select an object (whether it’s a trace, via, part, etc.), but when there are two parts overlapping exactly where you’re clicking, EAGLE doesn’t know which one you want to pick up. In cases like that, EAGLE will pick one of the two overlapping objects, and ask if that’s the one you want. If it is, you have to left-click again to confirm. If you were trying to grab one of the other overlapping objects, right-click to cycle to the next part. EAGLE’s status box, in the very bottom-left of the window, provides some helpful information when you’re trying to select a part.

4

           For example: In the GIF above, a VCC net overlaps another named Reset. We left-click once directly where they overlap, and EAGLE asks us if we meant to select VCC. We right-click to cycle, and it asks us instead if we’d like to select Reset. Right-clicking again cycles back to VCC, and a final left-click selects that as the net we want to move.

Whew! Enough pointers, let’s lay out a PCB!

 

Arranging the Board

Create a Board From Schematic

If you haven’t already, click the Generate/Switch to Board icon –  – in the schematic editor to create a new PCB design based on your schematic: 

5

The new board file should show all of the parts from your schematic. The gold lines, called air wires, connect between pins and reflect the net connections you made on the schematic. There should also be a faint, light-gray outline of a board dimension to the right of all of the parts.

Our first job in this PCB layout will be arranging the parts, and then minimizing the area of our PCB dimension outline. PCB costs are usually related to the board size, so a smaller board is a cheaper board.

Understanding the Grid

In the schematic editor we never even looked at the grid, but in the board editor it becomes much more important. The grid should be visible in the board editor. You can adjust the granularity of the grid, by clicking on the GRID icon – . A 0.05" grid, and 0.005" alternate grid is a good size for this kind of board.

6

           EAGLE forces your parts, traces, and other objects to “snap” to the grid defined in the Size box. If you need finer control, hold down ALT on your keyboard to access the alternate grid, which is defined in the Alt box.

Moving Parts

Using the MOVE tool –  – you can start to move parts within the dimension box. While you’re moving parts, you can rotate them by either right-clicking or changing the angle in the drop-down box near the top.

The way you arrange your parts has a huge impact on how easy or hard the next step will be. As you’re moving, rotating, and placing parts, there are some factors you should take into consideration:

           Don’t overlap parts: All of your components need some space to breathe. The green via holes need a good amount of clearance between them too. Remember those green rings are exposed copper on both sides of the board, if copper overlaps, streams will cross and short circuits will happen.

           Minimize intersecting airwires: While you move parts, notice how the airwires move with them. Limiting criss-crossing airwires as much as you can will make routing much easier in the long run. While you’re relocating parts, hit the RATSNEST button –  – to get the airwires to recalculate.

 

           Part placement requirements: Some parts may require special consideration during placement. For example, you’ll probably want the insertion point of the barrel jack connector to be facing the edge of the board. And make sure that decoupling capacitoris nice and close to the IC.

Tighter placement means a smaller and cheaper board, but it also makes routing harder.

Below is an example of how you might lay out your board while considering those factors. We’ve minimized airwire intersections by cleverly placing the LEDs and their current-limiting resistors. Some parts are placed where they just have to go (the barrel jack, and decoupling capacitor). And the layout is relatively tight.

Note: The tNames layer (which isn’t visible by default) was turned on to help identify which part is which.

Adjusting the Dimension Layer

Now that the parts are placed, we’re starting to get a better idea of how the board will look. Now we just need to fix our dimension outline. You can either move the dimensions lines that are already there, or just start from scratch. Use the DELETE tool –– to erase all four of the dimension lines.

Then use the WIRE tool – (– to draw a new outline. Before you draw anything though, go up to the options bar and set the layer to20 Dimension. Also up there, you may want to turn down the width a bit (we usually set it to 0.008").

7

           Then, starting at the origin, draw a box around your parts. Don’t intersect the dimension layer with any holes, or they’ll be cut off! Make sure you end where you started.

8

           That’s a fine start. With the parts laid out, and the dimension adjusted, we’re ready to start routing some copper!

Routing the Board

Routing is the most fun part of this entire process. It’s like solving a puzzle! Our job will be turning each of those gold airwires into top or bottom copper traces. At the same time, you also have to make sure not to overlap two different signals.

Using the Route Tool

To draw all of our copper traces, we’ll use the ROUTE tool–– (not the WIRE tool!). After selecting the tool, there are a few options to consider on the toolbar above:

9

Layer: On a 2-layer board like this, you’ll have to choose whether you want to start routing on the top (1) or bottom (16) layer.

Bend Style: Usually you’ll want to use 45° angles for your routes (wire bend styles 1 and 3), but it can be fun to make loopy traces too.

Width: This defines how wide your copper will be. Usually 0.01" is a good default size. You shouldn’t go any smaller than 0.007" (or you’ll probably end up paying extra). Wider traces can allow for more current to safely pass through. If you need to supply 1A through a trace, it’d need to be much wider (to find out how much, exactly, use atrace width calculator).

Via Options: You can also set a few via characteristics here. The shape, diameter, and drill can be set, but usually the defaults (round, auto, and 0.02" respectively) are perfect.

 

With those all set, you start a route by left-clicking on a pin where a airwire terminates. The airwire, and connected pins will “glow”, and a red or blue line will start on the pin. You finish the trace by left-clicking again on top of the other pin the airwire connects to. Between the pins, you can left-click as much as you need to “glue” a trace down.

10

While routing it’s important to avoid two cases of overlap: copper over vias, and copper over copper. Remember that all of these copper traces are basically bare wire. If two signals overlap, they’ll short out, and neither will do what it’s supposed to.

11

If traces do cross each other, make sure they do so on opposite sides of the board. It’s perfectly acceptable for a trace on the top side to intersect with one on the bottom. That’s why there are two layers!

If you need more precise control over your routes, you can hold down the ALT key on your keyboard to access the alternate grid. By default, this is set to be a much more fine 0.005".

Placing Vias

Vias are really tiny drill holes that are filled with copper. We use them mid-route to move a trace from one side of the board to the other.

To place a via mid-route, first left-click in the black ether between pins to “glue” your trace down. Then you can either change the layer manually in the options bar up top, or click your middle mouse buttonto swap sides. And continue routing to your destination. EAGLE will automatically add a via for you.

12

Route Clearance

Make sure you leave enough space between two different signal traces. PCB fabricators should have clearly defied minimum widths that they’ll allow between traces – probably around 0.006" for standard boards. As a good rule-of-thumb, if you don’t have enough space between two traces to fit another (not saying you should), they’re too close together.

Ripping Up Traces

Much like the WIRE tool isn’t actually used to make wires, the DELETE tool can’t actually be used to delete traces. If you need to go back and re-work a route, use theRIPUPtool –  – to remove traces. This tool turns routed traces back into airwires.

You can also use UNDO and REDO to back/forward-track.

Route Away!

That’s about all the simple rules there are. Go have the time of your life solving the routing puzzle! You may want to start on the closest, easiest traces first. Or, you might want to route the important signals – like power and ground – first. Here’s an example of a fully-routed board:

13

           See if you can do a better job than that! Make your board smaller. Or try to avoid using any vias.

After you feel like the routing is done, there are a few checks we can do to make sure it’s 100% complete. We’ll cover those on the next page.

Or Use the Autorouter (Cheater!)

If you’re short on time, or having trouble solving the routing puzzle, you can try loading up EAGLE’s Autorouter –– to see if it can finish the job. Open up the autorouter, don’t worry about these other tabs for now, just click OK.

14

If you don’t like the job the autorouter did, you can quickly hit Undo to go back to where you were.

The autorouter won’t always be able to finish the job, so it’s still important to understand how to manually route pads (plus manual routes look much better). After running the autorouter, check the bottom-left status box to see how it did. If it says anything other than “OptimizeN: 100% finished”, you’ve still got some work to do. If your autorouter couldn’t finish the job, try turning Routing Grid down from 50mil 10mil.

There are tons of optimizations and settings to be made in the autorouter. If you want to dig deeper into the subject, consider checking out EAGLE’s manual where an entire chapter is devoted to it.

 

Checking for Errors

Before we package the design up and send it off to the fabrication house, there are a few tools we can use to check our design for errors.

Ratsnest – Nothing To Do!

The first check is to make sure you’ve actually routed all of the nets in your schematic. To do this, hit the RATSNEST icon –  – and then immediately check the bottom left status box. If you’ve routed everything, it should say “Ratsnest: Nothing to do!”

As denoted by the exclamation mark, having “nothing to do” is very exciting. It means you’ve made every route required.

If ratsnest says you have “N airwires” left to route, double check your board for any floating golden lines and route them up. If you’ve looked all over, and can’t find the suspect airwire, try turning off every layer except19 Unrouted.

Design Rule Check

Once you’re done routing there’s just one more check to be made: the design rule check (DRC). For this step, we recommend you use the SparkFun design rules, which you can download here. To load up the DRC, click the DRC icon –  – which opens up this dialog:

15

The tabs in this view (Layers, Clearance, Distance, etc.) help define a huge set of design rules which your layout needs to pass. These rules define things like minimum clearance distances, or trace widths, or drill hole sizes…all sorts of fun stuff. Instead of setting each of those manually, you can load up a set of design rules using a DRU file. To do this, hitLoad… and select the SparkFun.dru file you just downloaded. The title of the window will change to “DRC (SparkFun)”, and some values on the other tabs will change. Then hit the Check button.

Again, look down to the bottom-left of the editor. If your design is perfect, you should see “DRC: No errors.” But if things didn’t go so swell, you’ll instead be greeted by the dreaded “DRC Errors” window. The error window lists all of the open errors, and it also highlights where the error is. Click on any of the errors listed, and EAGLE will point to the offender.

16

           There are all sorts of errors that the DRC can find, but here are some of the most common:

           Clearance: A trace is too close to either another trace or a via. You’ll probably have to nudge the trace around using the MOVE tool.

           Overlap: Two different signal traces are overlapping each other. This will create a short if it’s not fixed. You might have to RIPUP one trace, and try routing it on the other side of the board. Or find a new way for it to reach its destination.

           Dimension: A trace, pad, or via is intersecting with (or too close to) a dimension line. If this isn’t fixed that part of the board will just be cut off.

Once you’ve seen both “No airwires left!” and “DRC: No errors.”, your board is ready to send to the fab house, which means it’s time to generate some gerber files. Before we do that though, let’s add some finishing touches to the design.

 

Finishing Touches

Adding Copper Pours

Copper pours are usually a great addition to a board. They look professional and they actually have a good reason for existing. Not to mention they make routing much easier. Usually, when you’re adding a copper pour it’s for the ground signal. So let’s add some ground pours to the design.

Start by selecting the POLYGON tool – . Then (as usual), you’ll need to adjust some settings in the options bar. Select the top copper (1) layer. Also adjust the Isolate setting which defines how much clearance the ground pour gives other signals, 0.012" for this is usually good.

17

           Next, draw a set of lines just like you did the dimension box. In fact, just draw right on top of the dimension lines. Start drawing at the origin, trace all the way around, and finish back at the same spot. A dotted red box should appear around the dimension of the board.

After you’ve drawn the polygon, you have to connect it to a net using the NAME tool – . This works just like naming nets on a schematic. Use that tool on the dotted red line you just created, and in the dialog that pops up type “GND”. (Click here to see an animated GIF of the entire process.)

The last step is to hit ratsnest, to watch the glorious red pour fill just about the entire area of your board. You’ll probably hate me for telling you this now, but adding ground pours to your design at the very beginning (after placing parts, before routing) makes manual routing much easier.

You can (and probably should) have ground pours on both sides of the board, so follow the same set of steps on the bottom layer.

18

 

It can be hard to tell what is and isn’t connected to the ground pour. If you see a black gap separating a pad and the pour, there is no connection. If you see some traces forming a “target” over the pad, there is a connection from the pour to that pad.

If you ever want to hide the polygon (it’s hard to see other stuff with it on there), use the RIPUP tool on the polygon border you just drew. Don’t worry, the polygon is still there, just hit ratsnest to bring it back.

Adding Silkscreen

Although it has no real effect on the circuit your designing, silkscreen can be a critical part of the PCB design. You want it to look good, right? Some silkscreen – like part outlines – is automatically placed on the board because it’s a piece of the part. We can manually add other information, like labels, logos, and names. A variety of draw tools – wire (), text (), circle (), arc (), rectangle (), and polygon () – can be used to draw on the silkscreen layer (tPlace for top, bPlace for bottom).

Have fun and explore with these tools. You could add labels for the headers, or values for the resistors, or even create a nifty logo.

19

The draw tools are a bit limited, but that doesn’t mean you can’t make it look good!

Generating Gerbers

When you’ve finalized your design, the last step before sending it off to the fab house is to generate gerber files. Gerber files are kind of a “universal language” for PCB designs. EAGLE is far from the only PCB CAD software out there, and its design files are nothing like those of Orcad or Altium. Fab houses can’t possibly support every piece of software out there, so we send them the gerber files instead.

Gerber files – note the plurality – each describe single layers of the PCB. One gerber might describe the silkscreen, while another defines where the top copper is. In all, we’ll generate seven gerber files to send to the fab house.

CAM Processor

Before we get too much further, you’ll need to download another definition file: SparkFun’s CAM file.

Then, load up the CAM processor by clicking the CAM icon –  – which will open up this window:

20

           From here, go to the File menu, then go Open > Job…. In the file browser that opens, select the sfe-gerb274x.camfile that you just downloaded. Now the CAM processor window should have a series of tabs: “Top Copper”, “Bottom Copper”, “Top Silkscreen”, etc. Each of these tabs define how to create one of the gerber files. Now all you have to do is click Process Job. If you haven’t saved recently, it’ll prompt you to.

The gerber generation process should be pretty quick. Once it’s run its course, have a look in your project directory, which should have loads of new files in it. In addition to the board (BRD) and schematic (SCH) files, there should now be a .dri, .GBL, .GBO, .GBS, .GML, .gpi, .GTO, .GTP, .GTS, and a .TXT. Meet the Gerbers!

Gerber File Extension
Bottom Copper GBL
Bottom Silkscreen GBO
Bottom Soldermask GBS
Top Copper GTL
Top Silkscreen GTO
Top Soldermask GTS
Drill File TXT
Drill Station Info File dri
Photoplotter Info File gpi
Mill Layer GML
Top Paste GTP

 

Picking a PCB Manufacturer

There are PCB manufacturers all over the world, so you shouldn’t have any trouble finding one. OSH Park is pretty great for low-volume, high-quality PCBs (plus, they’re purple!). Advanced Circuits is awesomely fast. Gold Phoenix is cheap. We could go on and on, but Ladyada has a great list over on her website.

Before they fabricate the board, the fab house will usually run a quick design for manufacturability (DFM) check, and let you know if something on your design will cause in a problem.

Delivering the Gerbers

The process of sending gerber files varies by fab house. Most will ask you to send them a zipped folder of select files. Which gerber files? Check with your fab house again (e.g. Advanced Circuits and OSH Park’s guidelines), but usually you want to send them GTL, GBL, GTS, GBS, GTO, GBO and the TXT files. The GTP file isn’t necessary for the PCB fabrication, but (if your design had SMD parts) it can be used to create a stencil.

21

           So zip those gerbers up. Play the waiting game. And get ready to assemble your very own PCB!