Wednesday, April 20, 2022

Widget Wednesday: Vive la Résistance!

First things first:  What is it good for?  In terms of Physics, two interrelated things:

  • Regulating the amount of current in its circuit, and 
  • Absorbing of voltage that would fry the other widget(s) in its circuit.

In more practical micro-controller unit (MCU) and "widget" terms, this amounts to:

  • In digital output mode:  Protecting downstream widgets from excessive voltage/current
  • In digital input mode:  "Is this widget ON or is it OFF right now?"
  •  In analogue input mode:  Protecting the micro-controller from excessive voltage/current
  • Also in analogue input mode:  "If this widget is ON, how much is it actually ON?"

But let's hop back to Physics for a second, because all this ultimately boils down to a straightforward bit of Algebra knowns as Ohm's Law.  The simple version, at least.  In Ohm's Law, voltage is simply what you get when_X_ amount of current flows through a material with _Y_ amount of resistance.  Ohms (abbreviated with the Greek capital letter omega, or 'Ω') are a unit-measure of resistance, as Amperes (abbreviated as "Amp" or just 'A') are the unit of current.

Putting these together with the more familiar Volt ('V'), we get:   

1V = 1A * 1Ω.

Now.  One big, biiiiiig caveat when you're first working with widgets and microcontrollers is that you need to remember is that, while you're working with whole Volts and whole Ohms, currents will measured in mA -- i.e. one-thousandths of an Ampere.  Definitely something that you need to to keep in mind while you're looking at datasheets and doing the math accordingly.  

A typical LED, for instance, will operate at a mere 20mA -- one fiftieth of an Amp.  Fortunately for all our purses, the kinds of resistors we use in bread-boarding go from one Ω up to a million Ω and more -- and they're typically all priced the same.

 

Controlling Output Current/Voltage


As I mentioned, a 5mm LED like this should draw no more than 20mA of current.  (This also happens to be w/in the safe operating range of a micro-controller pin on the Arduino/Boardulno.)  Depending on its colour, it will operate at a voltage level somewhere between 1.8 and 3.6 Volts.  Many electronics tutorials will play it safe by assigning a 220Ω resistor for all colours.  But if you want something brighter, yet still within the safe range, you need to do a little math.  

In this example, our red 5mm "extra-bright" LED has a range of 1.8 - 2.6 Volts and 20mA of current.  By default, an Arduino digital pin in output mode operates at 5V.  So what to do about the excess 2.4 - 3.2 Volts?  

That's mainly where the resistor comes in.  By definition, it "resists" the flow of current and it does this by dissipating electricity in the form of heat.  (Which is why you need to pay attention to the Wattage rating of your resistor, but we'll get to that in a bit.)

Let's say that we want to run this LED something close to its maximum voltage.  So, to stay a bit on the safe side, we shoot for 2.5 Volts, a.k.a. 2V5.  

So, 5V - 2V5 = 2V5.  

That means that the resistor has to dissipate the excess 2V5 while maintaining a 20mA current.  Again, we have to remember that we're operating in fractions of Amperes here and translate that 20mA -- twenty thousandths of an Ampere -- into 0.02A when we plug it into Ohm's law and solve for X.

If 1V = 1A * 1Ω and we know how many Volts and Amps we're dealing with here, we enter our known values and rewrite the equation as:

=> 2.5V = 0.02A * _X_Ω.  
=> _X_Ω = 2.5V / 0.02A
=> _X_ = 125Ω

That's the basic principle of how resistance (and resistors) work within a given circuit.  Easy-peasy-Mac-'n-Cheesy, amirite?

But Ohm's law doesn't have bupkis to say about how that resistance plays out with mass-produced widgets.  Particularly not when we're trying to stick with inexpensive, readily-available, bread-boardable widgets.  That's where wiring configuration comes in.  For our purposes, resistance plays out in three configurations:

  • Resistors in Series
  • Resistors in Parallel 
  • Voltage-divider Circuits 

 

Resistors in Series

With the inexpensive carbon-film resistors we'll be wrangling into breadboards, we may have to fudge the values a bit.  That's because the out-of-the-box values are standardised. By which I mean that they tend to come in multiples of 10, 12, 15, 18, and so on.   

But in the green LED example above, we're looking for 125Ω of resistance.  But, even in the variety-packs that we can buy over-the-counter -- because who wants to pay $10 shipping for a 5-cent part -- that's not an option.  You can settle for 120Ω -- no judgements from me -- or you can edge up on the "ideal" value.

One -- but not the only -- trick to keep in your pocket is to remember that there's no law that says that the 125Ω has to be supplied by a single resistor.  If you have two in your collection that add up to something close to that number, you can wire your way around it if you line them up in series.  Fortunately, when resistors in series are daisy-chained, the math is Grade 1 arithmetic: 

R(Total) = R1 + R2 + R3 + ... + Rn

 


In this example, we have some (unspecified) widget that requires a (fairly high) resistance of 500Ω.  The bad news is that we don't happen to have that value in our stash.  The good news, however, is that we have a whack of 100Ω resistors handy.  We can arrange them on the breadboard so that they form a chain.  The overlapping of the resistors' ends forces the current to hop-scotch through them to complete the circuit.  (Always remember that, if you give current a path of least resistance to GND, it will take it.  This path doesn't allow give it alternatives.)

Safety Warning:  But before moving on, I want to cover the concept of rated Wattage.  Basically, this means that a resistor -- or any widget, really -- has an upper limit in how much voltage and current it can tolerate before Bad Things(TM) start to happen.  That upper limit is measured in Watts -- a.k.a. Volts * Amperes.  

But wait a minute!  Isn't Amperage already part of Voltage?  Aren't we basically talking about Ohms multiplied by Amps squared?  Yes, yes we are.  Ultimately, it doesn't matter how you do the math, though.  All we care about in this case is how close we're running to that resistor's upper tolerance.  (Which, for the record, will be 0.25 Watts for these inexpensive carbon-film resistors.  For whatever widget(s) are in their circuit?  That's on the datasheet, fam.)

In the case of our LED, we're more than good here.  Because 2.5V * 0.02A = 0.05W.  In other words, we're safely running at one-fifth, or 20% capacity.  All good here.  That being said, checking the wattage rating on every single widget before you plug it in and flip the switch is a habit that absolutely cannot be developed too early. 


Resistors in Parallel

LEDs, as long as you swing for the lower end of their operating voltage, tend to be pretty forgiving.  Yeah, lower voltage == dimmer bulb...but at least you know it's working.  Once in awhile, though, you might -- and likely will -- encounter fussier widgets that rely on much more specific resistor values.  If you don't have that specific value on hand, or even values that will add up to that value, you can fall back on a more advanced version of Ohm's law -- one that covers resistors in parallel.  If you haaaaaated the tedium of adding fractions like I did in middle school, you're not going to like this.  Sorry, but them's the breaks.

Resistance in parallel (figuratively and Algebraically) turns resistors-in-series math on its head.  No, really.  Assuming we have any number of resistor values, R1 through Rn, the formula looks like:

1/R(Total) = 1/R1 + 1/R2 + 1/R3 + ... + 1/Rn

Mercifully, we can get the fractions out from underfoot in one shot by re-writing the formula as:

R(Total) = (R1 * R2 * R3 * ... * Rn) / (R1 + R2 + R3 + ... + Rn)

Let's take the same five 100Ω resistors from the "Series" example and re-wire them in parallel on the breadboard (with a little help from jumper-wires):


The resulting resistance, however, is something quite different.  Plugging in the numbers:

R(Total) = (100Ω * 100Ω * 100Ω * 100Ω * 100Ω) / (100Ω + 100Ω + 100Ω + 100Ω + 100Ω)
=> 100^5Ω / 500Ω
=> 10,000,000,000Ω / 500Ω
=> 20,000,000Ω
=> 20MΩ  (Yeah, that's mega-Ohms.)

Wowza.  At 5V, the trickle of current through that circuit will likely be un-measurable to our poor multi-meters.  And, let's be honest, will likely be impractical for basically anything we'd do on a breadboard.  (I'm not an electrical engineer, so I can't speak to whether that would even work on a printed circuit board (PCB).)  But the basic idea is that the difference in scale between in-series resistors and in-parallel resistors is literal multiple orders of magnitude.

But my Gentle Reader gets the point, yes?  Like resistors in series, the resistors in parallel configuration is another tool in your toolbox when you have a limited range of resistor-values handy and none of them are close to what you need for your project.  (In fairness, I will admit that I've never needed to cut it this fine with any project.  YMMV.)  

 

Voltage Divider Circuit

The third and final resistor wiring configuration that I'm going to cover here is a special case known as the voltage divider circuit.  As we've seen, the series resistor configuration adds resistances and the parallel configuration (mostly) multiplies them.  In contrast, the voltage divider configuration is useful for outputting a ratio of whatever current is fed into it. 

In practical terms, that means that (within the limits of the resistors' rated wattage) you can cheaply step down the voltage flowing to whatever widget is downstream in the circuit.  That, bee-tee-dubs, can include output widgets (e.g. LEDs, buzzers, etc.) or input widgets that can measure a range of values read by a micro-controller.  

In either case, the formula is:

R(Output) = R2 / (R1 + R2)

Notice that we're limited to two (vs. a potentially infinite number of) resistors.  But what's super-important to remember is that, unlike series & parallel resistor configurations, the relative values of R1 and R2 make all the difference (unless, of course, they're equal.)  But, for our purposes, equal values of R1 and R2 can still be useful.  

My Gentle Reader might already have crunched the numbers and realised that, when R1 = R2, the output voltage is 2/3 of the original.  Which comes in super-handy when we need to step 5V down to 3V3.  In that case, 1/4W resistors should carry no more than 50mA of current.  But since we already limit ourselves to <= 20mA, this shouldn't be an issue...riiiiiiiiiiiiiiiiiight??????

On the breadboard, a voltage-divider circuit looks something like:  


One final thought is that the actual values of the resistors involved in a voltage-divider circuit don't really matter -- everything boils down to their relative values.  In other words, it's All About the Ratio.  

In the above example, two 100Ω resistors could be swapped out for two 1Ω resistors.  Or two 1Ω resistors, for that matter.  All that truly matters is staying within the resistors' rated Wattage.  But it's what makes a voltage divider circuit so powerful.  For outputted current and, as we'll later explore with variable-value resistors, inputted current.

 

Controlling Digital Input Current/Voltage

The same principles apply here, only the voltage is flowing into the micro-controller unit (MCU) rather than from it.  (A little vocabulary-builder here:  

(Vocabulary Builder:  When a pin on the MCU is powering your widget as an output device, it's called "sourcing" current.  When the widget is sending current to the MCU pin as an input device, it's "sinking" current.)  

Micro-controllers like the Arduino can usually sink more current than they source and still stay within safe operating ranges.  But on the level of individual pins, stick with 20mA for input and output.  Which, naturally, means that you need to double-check the datasheet of each and every widget in your Arduino/Boarduino project.  No more than 5V under any circumstances, and (again) stick with 20mA maximum on any given input pin.  Burn those values into your synapses, tattoo them onto the inside of your eyelids -- whatever does the trick.

That-all being said, let's assume that your input widget -- digital or analogue -- comes in on the cool side of these 20mA@5V thresholds.  Then the same basic math as output applies -- with a twist.  Namely that, even for digital input, there's no law that says that the voltage level must be 5V.  The reason being that, within limits, "digital" is just another word for a micro-controller's digital ON vs. OFF dichotomy.  

With the Arduino, the the bar is HIGH, not high.  Yeah, bad pun.  Sorry-not-sorry.  It turns out that you actually have a little slop.  Which is fortunate because, although the vast majority of widgets that I've encountered (thus far) are cool with 5V, a non-trivial percentage insist upon 3.3 Volts (abbreviated "3V3").  The consensus is that a minimum of three Volts digital input is a safe bet.  After testing that myself with an UNO, I tend to agree.  Yes, you can fudge it down a bit (meaning 2V8 and above), but below that you risk very random results.

 

Controlling Analogue Input Voltage

On the standard Arduino (the UNO, whose Atmel ATMega328-based chip also plugs into a breadboard), six pins are available for analogue input.  In other words, they can measure variable levels of voltage.  When working with the standard Arduino UNO, this means that any voltage between 0V and 5V is translated into an integer number between 0 and 1023. (In the Boarduino universe, there's a titch more flexibility.  But, as my Gentle Reader has heard many times already, this is another topic for another post.)

The upshot is that if you've ever felt like you're just another number, you're in good company.  And I mean that in a good way:  Just scrounging through my stash, I can hang with a delightful, motley, and very useful crew. 




Welcome to the Resistance.  [rim shot]

As input widgets, they can measure things like:

  • Light intensity
  • Weight
  • Moisture / Water Level
  • The presence of gasses like CO2, CO, NH3, etc.
  • Tension along a fixed area

As output widgets, they can:

  • Control how much current goes to another widget
  • Generate heat
  • Generate cold

Some can even be used for inputs or output.  Output tends to be pretty straighforward.  But the point of analogue input is not to tell you whether or not the widget in question is sending an electrical current (or not) to the Arduino's analogue pin; it's  how much voltage it's sending.  We're looking for nuance here, my ducks.

The basic idea is that we have some sort of range.  In the case of the Arduino, it's typically an integer between 0 and 1023 and it's up to us to decide what that number means.  (Hint:  We usually translate into a 0 - 100 percentage, but not always.)

Some, more advanced, widgets (usually "breakout boards") will handle the translation for you right out of the box.  So long as you can verify that their voltage doesn't exceed 5V and their current stays pretty close to 20mA, plugging them straight into the Arduino should be safe.  

But with the more "primitive" widgets, you want to add resistance.  Whether that is resistance in series, resistance in parallel, or a voltage-divider circuit depends upon the widget in question and the values of resistors that you have on hand.  For most purposes, inexpensive 0.25W or even 0.125W carbon-film resistors get the job done.  

But now I'm getting ahead of myself.  Those basic carbon-film resistors -- which are a whole genre unto themselves -- will be the focus of the next installment.  Until then, Tchein ton siault d'beluets!

Wednesday, March 16, 2022

Widget Wednesday: Simple Switches

Okay, so I lied last time.  In 20/20 hindsight, it would be rude to dump my Gentle Reader into the world of analogue before discussing binary.  Which, of course, is what switches are all about.  And the majority of potential inputs (and all of the outputs) on an Arduino are binary.

First things first:  What is it good for?  In the proverbial nutshell, a switch controls whether or not current flows through a circuit.  In electronics parlance, it's HIGH or LOW. No nuance -- the current is either ON or OFF and we (mostly) don't care about how much.  For the purposes of micro-controller units (MCUs), I'm going to talk about switches as sensors.  All the MCU needs to know is "Is current flowing to this pin when I check it?"

Switches can be incredibly fancy -- to the point where it's easy to forget that they're switches under the hood.  Eventually, we'll take a deeper dive into widgets like ultrasonic range-finders and DHT (Digital Humidity & Temperature) sensors, which pulse data in the form of micro- or milli-second bursts of ON and OFF.  But as an introduction, we're going to look their much simpler, entirely mechanical, cousins.

Example 1:  Reed Switch

 


First things first:  What is it good for?  Basically any project where you need  to detect a magnetic force within a small radius.  (Depending on the strength and orientation of the magnet, you can figure 10cm as a maximum.)

This is probably the simplest one in my stash and has a delightful old-school retro-sci-fi vibe.  It's also a little more straightforward to understand.  For tasters, it's transparent -- literally and figuratively.  Basically, it's comprised of two ends of a switch hermetically sealed inside a tiny glass bubble.  One of those ends is susceptible to magnetic force.  

When an appropriate magnetic force -- in our case, the pull from a rare-earth magnet -- is applied, the switch opens or closes, depending on both its design and the polarity of the magnetic force. 

Reed-switches come in two flavours:

  • Normally Open -- i.e., by default the two ends do not touch and have to be pushed together by a magnet. 
  • Normally Closed -- i.e. the ends touch by default and have to be forced apart by a magnet.

Of the two styles, the Normally Open (abbreviated "NO") version is more useful when you're trying to conserve battery power.  But there are definitely useful cases for the Normally Closed (NC) style, namely in something known as a "deadman switch."  There, the switch is watching for a drop of current from some source to indicate that, for instance, a door is open.

Example 2:  Momentary Push-button

 


 First things first:  What is it good for?  Very brief human interaction:   "Reset" buttons, console buttons, highly un-ergonomic keyboards.

This form-factor should look pretty familiar; it's the kind of button you smash for video games or hold down and count alligators to reboot your laptop.  Depending on how you wire your project, these can be configured as Normally Open or Normally Closed. 

Our human model of this kind switch probably runs something like this:  Somewhere in the middle of the switch's descent from up to down (or back), the switch crosses a decisive cut-off point between Closed and Open.

Only that the Laws of Physics(TM) plus the realities of mass-manufacturing make that hypothesis more...interesting.  Especially when combined with our human reflexes.  Compared to micro-controllers like the ones that go into Arduinos, we humans are about as responsive as a tree-sloth on quaaludes (thanks, Dave Berry!). 

When the MCU is checking the button's ON/OFF state hundreds or thousands of times per second, what we in Meatspace(TM) perceive as "instantaneous" is a quasi-eternity of quantum ambiguity for the micro-controller.  

Mainly because, with these inexpensive buttons, we're not actually making an unambiguous downward/upward movement.  That "springiness" we feel in the button translates to a semi-random sequence of ONs and OFFs that rivals the relationship status of celebrity couples by orders of magnitude.   

Hardware-wise, you might be able to work around it with higher-quality switches and maybe some current-dampening via a resistor.  In this case, you're better off with fixing it at the software level with what's known as "de-bouncing code."  At some point, I will do a deep-dive into momentary push-buttons with a de-bouncing code example.  Just not today.

Example 3:  Latched Push-button

 


 This version of a push-button should also be familiar, except that once the button snaps into the "down" state, it stays there ("latched") until it's pressed again.  

First things first:  What is it good for?  Human interaction, but mainly in a set-it-and-forget-it way. 

Again, from the micro-controller's perspective, the transition from "Latched" to "Unlatched" will not seem so binary.  And thus will still require some amount of de-bouncing code to handle the ambiguities of being smooshed by apes with social media accounts.  The main difference, of course, is that once the switch "clicks' into place it's set.  That removes some -- but not all -- ambiguity.  From a software perspective, it's best to treat momentary and latched push-buttons more or less identically in code.

But this particular model packs one extra feature in that it has six pins vs. the four of the "momentary" style.  Which, for all practical purposes, allows you to switch two circuits with the same button.  Which, as we'll eventually see, opens up all sorts of possibilities.

Before then, however, I do need to cover the fundamentals of resistors and the basic algebra that goes into pretty much any home-brew circuitry.  Until then:  Tchein ton siault d'beluets!

Wednesday, March 9, 2022

Widget Wednesday: Breadboard Power Supplies/Adapters

First things first:  What is it good for?  Supplying a even flow of DC (direct current) to your electronics project at an expected voltage.  ("A clean signal" is the term my favourite electronics repair folks like to throw around.)  Granted, this seems pretty obvious on the surface but we tend to take that "even flow" part for granted.  Fiddling with electronics -- particularly micro-controllers (MCUs) -- will likely change that.

For relatively simple electronics (e.g. LEDs), it's likely you wouldn't notice that its power supply's voltage level is dropping for a few milliseconds at a time because the human eye can't perceive that.  Micro-controllers, in contrast, live microsecond-to-microsecond.  A voltage-drop on an input circuit can be interpreted as a sensor being tripped.  A voltage drop on the MCU's "Reset" pin will reboot the code uploaded to its memory.

With batteries, these fluctuations generally aren't so much an issue as what happens when the voltage level drops too low.  Power supplied by an outlet can be another story but, barring outages, you should only have to worry about this at setup time.  (For today's purposes, we're going to rule out any solar-/wind-powered project that doesn't have a rechargeable battery in the mix.)

Let's talk about batteries, though.

Pros:

  • Project not tied to an outlet.
  • Shouldn't require additional electronics to "clean up" the signal.
  • Lithium-Ion and AA, AAA, 9V rechargeable batteries (and a charger) are easy to find & inexpensive relative to the long-term cost of non-rechargeables.
  • Calculating current consumption is a good kick in the shins for reading the datasheet.

Cons: 

  • Require a way to monitor for low battery.
  • Project downtime while swapping in freshly-charged batteries.
  • Rechargeable AA and AAA cells operate at a different voltage level than alkaline equivalents.  (Grrrrr...)
  • Not rated for temperatures below the freezing-point.

Personally, I lean on rechargeable NiMH (Nickel Metal Hydride) AA and AAA batteries for everyday electronics anyway, so the up-front cost of the batteries and the charger made sense.  One trip to Canadian Tire and done.  

AA battery-holders are a common form-factor and come in a variety of capacities:  1, 2, 3, 4, and 6.  The holders are dirt-cheap and the ends of the positive and negative leads are generally pre-stripped.  Which means that they, in a pinch, can be jammed directly into the positive and negative power-rails of the breadboard.  I absolutely do not recommend that -- mainly because you don't have to do it too many times before you mangle the ends.  For breadboard prototyping purposes, you (or your favourite electronics repair shop) can solder the raw end of each tip to one end of something called a "male header-pin," and cover the solder-point with shrink-tubing:

 



Again, this is an option only for the prototyping phase of a project.  For a project in active use?   Just don't.  I stone-cold mean it.  That's beyond too dangerous.  The "ground" wire coming loose is bad enough; the "positive" wire coming loose means that anything within its range can become its ground wire.  That includes you, bee-tee-dubs.  And both?  [shudder]  (The possibility of two loose wires at once is why I like to cut positive leads longer than the negative leads.  It's not stupid-proof, mind you, but a little extra insurance doesn't hurt.)

That's where something called a breadboard power adapter comes in.  A power adapter is separate from a power supply in that it outputs a DC current but does not generate it.  Its header-pins seat into the breadboard at least an order of magnitude more securely the ends of the battery pack's leads.  (Sometimes securely enough that seating/unseating the adapter risks bending/breaking header-pins if you're too forceful all at once.  This is particularly common with new breadboards.)  

In addition to securing the power connection to your breadboard, adapters offer amenities such as:

  • Smoothing out ripples in the current.  Maybe.
  • Providing a "standard" socket (e.g. barrel-jack, USB, JST).
  • Providing a specific voltage-level (e.g. 5V, 3.3V).
  • (Possibly) including an On/Off switch (something you'll appreciate when the project is in use).

Let's look at a few examples, with their strengths/weaknesses.

 

This model allows you to power your breadboard via either a 2.1mm barrel-jack or a USB-A male connector.   USB generally standardises on 5V.  The barrel-jack gives you more flexibility which we'll get to in a bit.  Either way, you should figure on your project consuming no more than 500mA of current at any given time.

 


On the plus side, this style is fairly inexpensive, despite basically being the Cadillac of breadboard power adapters.  For mixed-voltage projects, you have the option of powering one side at 5V and the other at 3.3V (a.k.a. 3V3) via jumper-blocks (the yellow rectangles on the left and right).  

On the downside, this form-factor is a pig for space.  On a full-size breadboard, this will probably be negligible.   Half-size breadboards, on the other hand, might require you to break out your Tetris skills.  But their biggest drawback, by far, has been their quality.  My first batch of five came with one D.O.A. and another bricked the first time I pressed the power-button and heard a fateful "snap" in place of the usual springy "click."  (Which is a clue to why I tend to buy them five at a time*.) 

And, even with higher-end power-supply, they have a tendency to just wear out over time.  In fairness, I use these 24/7 in production, rather than occasional prototyping.  

Right.  I promised to get back to the barrel-jack power-supply and voltages.  As I mentioned, USB pretty much comes with 5V baked in.  (Although of course you're going to double-check with your multi-meter, riiiiiiiiiiiight?!?!?!)  The barrel-jack is engineered to expect something more than 5V and step it down.  Now, if your project is based on 3V3, 5V should probably be okay.  But I've had brown-outs with a 5V wall-wart -- a decent-quality one, too.  Switching to 9V made that problem go away.

Oh, and before I forget -- make sure your breadboard positive and negative power-rails match the adapter's +/- labels.

 

 

This model functions much the same.  Fewer bells and whistles mean that it takes up less breadboard space.  Same 2.1mm barrel-jack, but the USB connector is a USB-C (a.k.a. "USB micro").  The tiny black slider-switch in the middle toggles between 5V and 3V3 for the entire unit.  In other words, both breadboard power-rails operate on the same voltage; you can't cherry-pick like the above model.

To be honest, I have really only used this model for mockups & prototyping, not a Boarduino workhorse.  So I can't speak to to the overall quality or longevity of this model.  As with its heftier counterpart, make sure that its +/- pins match the red and blue stripes on the power-rails of your breadboard**.



Okay, this is basically a hack.  The (Sparkfun) breakout board attached to the mini-breadboard is technically meant to interface with all five potential wires of a USB connection.  But that doesn't mean that you can't ignore the middle three pins and use the 5V VCC (positive DC voltage) and GND (negative DC voltage) for your own nefarious (and squee) purposes.

Like all hacks, this is a use-at-your-own-risk kind of deal.  Most notably, there is absolutely no reverse-polarity protection.  You mix up positive and negative?  The "magic smoke" (or worse) is all on you.  This will also not doctor the electrical input.  Whatever voltage is input will be output.  And, probably more important for project stability, there is zero current conditioning -- it will not smooth out drops in voltage or protect you from brown-outs.  Now, if you power your project from, say, the USB port on your laptop, this shouldn't be an issue.  (Or if it is, you have bigger issues.)  Anything else is up to you and your electrical engineering know-how (or lack thereof).

There are other form-factors for these power supplies.  Adafruit, for instance, offers one with adjustable output voltage; Sparkfun offers a beefier version of the mini-supply.  This is just what I have in my stash at the moment.

Mostly, I've been talking about breadboard adapters in terms of power provided by an outlet via a wall-wart.  2.1mm barrel-jacks tend to be the standard (in North America, anyway).  (You might be able to find a wall-wart with a USB-micro connection, but normally you want to save those for your Raspberry Pi)  The prevalence -- meaning re-usability -- of the 2.1mm jack, however, is why I would make the rare argument for splurging on higher-end models.  The current/voltage that comes from our outlets can be shockingly (pun intended) sloppy.  That's why any serious electronics -- including the better wall-warts -- are engineered to clean up the signal. 

 



For battery-powered options, I'd tend to opt for the longevity and and sheer capacity of a Lithium-Ion power stick over NiMH rechargeables.  All other things being equal, of course.  Your project specs -- milliamp-hours of current, size, temperature, etc. all have to be factored the trade-offs that are engineering.

I'm too lazy to double-check my notes, but I think that the next installment will start to tackle resistors.  Until next time, Tchein ton siault d'beluets!

- - - - - 

* If that looks like red nail polish on the barrel-jack, you're absolutely correct!  This adapter's USB power-supply is the only functioning input.  So the red is intended to distinguish this particular unit from others.  See what I mean about this style being notoriously flakey right out of the box? :~/

** Yes, breadboard plastic can get that yellow.  ABS plastic does that.  This workhorse saw some kilometers as the "brains" of a project in continuous service for a couple of years.  I've since learned to be more mindful about distributing current-load, trust me.

Wednesday, March 2, 2022

Widget Wednesday: Wiring

 First things first:  What is it good for?  Actually, two things:

  1. Connecting widgets to the tie-points (i.e. holes, a.k.a. "pins") on a breadboard
  2. Connecting the breadboard tie-points to each other to make complete circuits

 For "Boarduino" purposes, there are two (realistic) options:

  • Flexible jumper-wire
  • Solid-core AWG wire

Let's break down the differences, which are almost-but-not-quite diametrically opposed.

  • Flexible wire is ideal for prototyping.
  • Flexible wire is also fine when you have to connect a breadboard-hostile widget to your project.
  • Solid-core AWG wire is what you use to connect breadboard pins for a project in full-time, real-world use.

In case it isn't obvious right now, you're going to want a mix of both kinds in your kit.

Flexible jumper-wire:  This is made for prototyping and not real-life.  Mostly.  The exception is when the widget doesn't actually plug into the breadboard.  That situation might or might not come with additional issues.  We'll get to those in a bit.

This kind of jumper-wire, under the coloured plastic coating, is actually a bunch of very fine copper wires.  Which is is less likely to break.  But, in my experience, it does like to degrade.  

"War-story":  I was experimenting with something called a Serial-to-Parallel chip to try and control 8-16 LEDs with an Arduino by way of three wires.  Problem was that one of the wires was going wonkier by the minute.  Well, no.  Problem was that I'm a programmer by trade.  So if anything goes wrong, my first instinct is to blame my code.  (Second instinct is to blame file/folder/network permissions, but that doesn't apply here.)

Ultimately, I had the great, good luxury of having an extra breadboard and enough extra widgets to duplicate my setup.  The second version worked flawlessly.  So I methodically replaced each wire in the original breadboarding project and realised that I had a bad one.  The wires weren't even that old, but it's not like they come with an UL rating, either.  So lesson learned.  (End of "war-story.")

Back to those "additional issues."  Off the top of my head, I can think of two widgets that I can only describe as "breadboard-hostile."  One is a common version of the passive infrared (PIR) sensor.  There are two of them below, so that you can see the underside and top-side of the unit.  The top-side (right side) is the lens that acts sort of like an eyeball; the brains -- including the header-pins that connect the sensor to the rest of your project are on the bottom of the board (left side).

The header-pins are the yellow bits near the middle of the pair.  Solid, clearly-labeled header-pins...blocked by two capacitors.  (If you don't know what capacitors are, don't worry; we'll get to that, too.  Just not today.)  

Everyone associated with this board's design is a jerkface.  Not only can you not plug this widget into a breadboard, even a printed circuit-board would have to be designed around this layout-felony.  

It doesn't have to be this way.  The first PIR sensor I ever ordered certainly wasn't this way.  But some slovenly, bean-counting dweeb decided that their rat-race-to-the-bottom retailers could shave $0.00000000000001 off the cost of each unit by massively inconveniencing their customers.  A pox and a plague and a sock-eating dryer upon everyone responsible for this travesty.  (Did I mention that these people are jerkfaces?)

Anyhoo.  Sometimes this sort of stupidity can be turned into a virtue.  But in this case it was only because I had a variety of jumper-wires on-hand.

As some of my Gentle Readers know, my very first real-world Arduino project was designed to teach our omnivorous ElderCat to stay off the counters. 

And, while Mister Kitty is not exactly the sharpest tool in the shed, it only took it three rounds with this thing to convince him that his hoomins were onto him.  (After ten years of yelling and squirt-guns and locking him in the basement after hearing the tell-tale "thump" of his paws hitting the kitchen floor, you're darned tootin' I'm patting myself on the head for that breakthrough.)

The mechanics of this setup are pretty straightforward:

  • Top right is the Arduino-ish Adafruit "Trinket" that is the brains of the outfit.
  • The green board at the bottom-left is a passive infrared (PIR) sensor that detects deviations from the ambient temperature (i.e. a warm, moving body) w/in 3-4 meters
  • The black button is a piezzo buzzer -- a crude audio speaker.

When the PIR sensor detected a warm body in motion w/in the 3-4 meter range, the Trinket fired off a sequence of timed electrical pulses which made the piezzo buzzer play Looney Tunes Tweety-Bird's "I Taught I Taw A Puddy-Tat."  And -- dude! -- it was loud.  Which, of course, was the point.



 

But at the time, we hoomins weren't certain that it would be that easy to convince Mister Kitty that he was being watched.  Also, it didn't take much for either of us to trigger this thing.  And we probably levitated as much as Mister Kitty.  Clearly, we needed a bit more precision.  So I added something called an ultra-sonic range-finder, which acts somewhat like a bat's echo-location.  

In the Mark II version, the PIR sensor detected a warm body moving somewhere in that 3-4 meter range and only then did the Arduino trigger the range-finder to determine whether there was a solid body within a half meter or so away.  Only when those two conditions were met would the piezo element sing its loony-tune to tattle.  

Muuuuuch less levitation on the part of the hoomins.  And after a month or so, the Mark II followed its predecessor into honourable retirement.



Problem was, the 2nd PIR sensor I bought came with that obnoxious, breadboard-hostile layout.  Which is why, in this case, you see it attached to the rest of the project via an umbilical cord of jumper-wires.  But it turned out to be the proverbial blessing in disguise in that also gave us more flexibility in how we could orient the PIR sensor and the ultrasonic range-finder.  Otherwise, we'd be limited to 90-/180-/270-degree angles.  There might be folks in this world with such geometrically-pure lines of sight on their kitchen counters.  Those people are psychopaths who Doordash all three meals. ;~P

And, as much as an chick raised as an anglophone during the 1970s rolls her eyes at the notion of anything under the sun -- including electronics and language -- being gendered, flexible jumper-wires are labelled with three gender-pairings [thumbs nose].  

  • M/M wires have "male" (i.e. solid wire) headers on both ends.  Because they cover at least 90% of prototyping, you will likely get far, far more mileage out of these than the other two kinds.  Stock up accordingly, 
  • M/F wires are...hermaphroditic.  A solid wire on one end and a matching socket on the other. Again, sometimes you need to connect widgets off-board; these are your play.  Those both came into play with the examples above.  Again, stock up accordingly.
  • F/F have the socket on both ends.  Thus far, I can't recall needing any.  But I can recall being a few $CDN short of the threshold for "free" shipping, and so the small handful I have were basically "free." [shrugs]

Regardless of form-factor, jumper-wires (like the solid-core wires we'll be talking about shortly) come in a rainbow of colours.  In the language of electrical engineering, a few colours matter.  Like far too many other things, which country/region you live in determines the norm.  In this (Canadian) series, we're dealing exclusively with two colours/functions:

  • Red == Positive
  • Black == Ground (functionally equivalent to Negative for our DC purposes)

Norms (and consistency) matter -- particularly when you need someone else's help debugging a layout.  Beyond that, it's up to personal preference.  Shocking precisely no one, I have a couple of those:

  • The "warm" colours (orange, yellow, white) I use for "output."  In practice, that means things like lighting up an LED, buzzing a Piezo element, controlling some sort of motor, what-have-you.
  • The "cool" colours (blue, green, purple) I use for "input."  In practice, that means things like listening for the user to press a button, reading a sensor-value, what-have-you.

Again, that's personal preference.  But it's worked out pretty well so far.  Especially when one of my creations stops working and I haven't looked at it in awhile.  Like every person with a full-time job, debugging my personal projects is done in one-/two-/maybe-three-if-I'm-lucky-hour bursts.  Colour-coding in the here-and-now is a priceless gift from Present Me fiddling on a weekend to Future Me trying to get something up and running before bedtime on a weeknight.  'Nuff said.

Okay, assuming that you're done with prototyping and ready to put your invention into real-world use, AWG-based wiring, by laying flush with the breadboard, is far, far less likely than even a short jumper-wire to be accidentally pulled out where it could become a menace. 

Solid-core American Wire Gauge (AWG) wire:  Again, first things first.  AWG22 wire is your no-brainer breadboarding go-to.  In a pinch, you can probably get away with AWG20 (which, incidentally, is thicker than AWG22, not thinner).  There will be more wear & tear on your breadboard, but if that's all you can find down at the local hardware or auto parts store, it will get you through until you can order 22-gauge. 

Whatever else you do, give the pre-formed wire-kits a big ol' pass. #DoAsISayNotAsIDid  The reason being is that pre-formed wire is colour-coded by length, not function.  We'll deal with why that's a problem in just a bit.

Now.  The thing with AWG wire (of any gauge) right off the roll is that you will need an extra tool -- more likely two tools -- to work with it.  First and foremost is a wire-stripper to separate the insulating plastic from the conductive metal.   Any self-respecting wire-stripper will come with a variety of notches (corresponding to different gauges) plus a wire-cutter built in at the rear of its "jaw."

Because you're already expecting to work in AWG22, my strong recommendation is to permanently mark the 22 "notch."  Grab a tooth-pick and break out (or borrow) a bottle of nail-polish.  Bright red, hot pink, baby-blue, glitter-gold -- whatever will stand out against the dull black or maybe dull silver of the jaws.  Dunk ~1cm-worth of toothpick into the nail-polish and use it as a pen to draw a stripe parallel with the "22" groove on all four sides of the notch.  Then there should never be any ambiguity about which notch you're using to strip the wire.  Because when your wire-stripper includes finer gauges (e.g. AWG24, AWG26, etc.), "ambiguity" can mean that you cut your wire where you meant to strip it.  Ask me how I know.  :~/

When you're cutting wires for breadboarding, you will probably also want basic needle-nose pliers to bend the wire at right angles.  Yes, you might be able to skip the pliers and do this with your fingers.  Assuming that you're, um, blessed with something like the ten scrawny won't-last-a-day-after-The-Apocalypse twigs that my DNA gave me.  And even I prefer the precision of pliers  Pony up a few bucks at Home Hardware and call it a day, already.

Cutting wires for breadboarding has a learning-curve (albeit shallow).  But because I hate waste as much as I love you, I'll try to save everyone a few cm of wasted wire and go over my technique here in a "FWIW" spirit:

  1. With the wire-stripper, strip just under 1cm of coating from the free end of the wire.  My go-to technique is to grab onto the wire where I want to cut the plastic and twist the cutting edge of the notch around the wire core to ensure I cut through all the coating. 
  2. Insert the stripped ~1cm of wire into the "From" breadboard tie-point/pin.
  3. Bend the wire at a 90-degree to lie flush with the breadboard. 
  4. Stretch the wire to the "To" breadboard tie-point.
  5. Bend the wire at a 90-degree angle north of the breadboard -- i.e. the loose end of the wire should point up.
  6. Clip the free end of the wire ~1cm above the surface of the breadboard.
  7. Temporarily remove the "From" end of the wire from the breadboard to make the wire easier to finish off.
  8. Strip the coating off the "To" end of the wire from about half-way into the curve.
  9. Using your needle-nose pliers, bend the newly-stripped wire 180 degrees.
  10. Insert both ends of the wire into the breadboard tie-points.

(Bee-tee-dubs?  The same colour-coding principles as flexible wires apply.)

Once you have cut, stripped, and formed AWG jumper-wire, it tends to be less reusable than the flexible wires used for prototyping.  So until you develop an instinct for breadboard layout, you can save yourself a bunch of scrap by virtually breadboarding your project.  I talked about a couple of options (Tinkercad and Fritzing) toward the end of the "Breadboards" installment.  If you haven't checked them out yet, please do.

Next time, I want to talk about options for powering breadboarded projects.  Until then:  Tchein ton siault d'beluets!

Wednesday, February 16, 2022

Widget Wednesday: Breadboard Basics

As much as I lost my heart to -- and built my first Arduino project on -- Adafruit's Trinket, the game-changer (for me) was stumbling across the chip-on-board form-factor.  That form-factor is not unique to the Arduino universe, where it's sometimes called "Boarduino."  We'll get to that in a later post.  For now, however, I want to focus on the mechanics of the breadboard itself.  Because [extremely schmoozy voice] that's where the magic happens [/extremely schmoozy voice]

First things first:  What is it good for?  "Prototyping" is the obvious answer.  But, chez fivechimera, there's also a long -- and sometimes even honourable -- history of prototypes being "good enough" for literal years of full-time use. Until they're not and the parts go back into their Cabela's tackle-boxes for next time.

This is not a novel concept: "Breadboarding" gets its name from the days of yore -- by which I mean literally a hundred years ago -- when you wired up your project by literally pounding nails into a breadboard (or any wide slab of wood), and winding copper wire around them to create a circuit.  Homebrew ("cat's whisker") radios were a Very Big Deal.  (See also: https://www.mikeselectronicparts.com/wp-content/uploads/building-a-crystal-radio.pdf)  

But, doubtless, one big selling point in those pre-Radio Shack days, was that once that project's usefulness ended, one could always pry loose the widgets, un-string the wire for later use (copper is expensive, y'all!), and pull the nails from the breadboard to restore it to its blank-canvas state.

And so reusability is the main reason I prefer the Boarduino form-factor.  Assuming that you're working w/in certain constraints, reducing project footprint is the second-best reason.  Assuming, of course, that the project can live inside certain limitations:

  1. Current limitations:  Each small hole (a.k.a. "tie point," a.k.a. "pin") on a solderless breadboard should never carry more than 500mA, or 1/2 of an Amp. of current through it.  Theoretically, they can take up to one Amp.  Just don't.  Most especially projects that will be up and running for awhile.  It's not worth the risk.
  2. Voltage limitations:  Stick to 5 volts DC.  Again, you want to stay well within the safety zone.  
  3. Pin spacing:  If the widgets you're planning to plug into your breadboard don't have pins 2.5mm (or 0.1 inch) apart, you're going to need to make other wiring arrangements.  We'll get to those options in a subsequent post.
  4. "Stupid-proofing":  Nothing in a breadboard's construction limits current polarity.  By which I mean, if you mix up positive and ground, the breadboard will not step in to save you.  At best, your project just won't work.  A short can melt the breadboard plastic.  (Ask me how I know.)  You also risk frying any widget connected to the faulty wiring -- up to and including the microcontroller.
  5. Layout limitations:  Do you have enough room on the breadboard for the microcontroller chip (a.k.a. MCU) and all your widgets?  If not, how are you going to work around that when your project is up and running in the real world?

Which brings me to breadboard sizes and their features (or lack thereof).  There might be a few exotic outliers, but here's the range I've stumbled over through the last few years:


I would say that they come in all shapes and sizes, except that the shape is limited to rectangular.

Half-size (top left):  In my experience, this is usually the optimal size for a Boarduino projects. The holes ("pins") come in two flavours.  



  • The two rows that run (horizontally) along the long edges of each side are often referred to as "power rails."  Traditionally, red is connected to the positive end of the power source and runs, uninterrupted from one end to the other.  Ground is wired into blue.  By default, the power rails on each side are independent of each other.
  •  If we consider the power rails to be "rows," then the other flavour of pins can be considered "columns."  These run perpendicular to the rails.  The five pins of each column -- highlighted in neon green -- are connected to each other.  They are not, however, connected to the column on the other side of the trench that runs between them.  

Full size (right):  Similar to the half-size with more "tie points" and often more flexibility.  Depending on the manufacturer, you might need to bridge the two halves of the power-rails.  Or not, depending on your project layout.

Mini (middle left):  In this case, there are no power-rails "rows"; only "columns" of five interconnected pins.  You will have to use one column for a positive rail and one for the negative.  Which brings one big no-no:  Never, EVER wire positive and negative into the same column.  Even for the simplest project.

Micro (bottom left, shown top and bottom):  For grins, I'm throwing this one in.  And, no, I have no idea what's going on with those "Lego-bumps" on the underside except to guess that they allow the breadboard to be glued/screwed into place from the underside of some project???  Again, I have no idea.

Now.  All of the above assumes that you have some basic understanding of how circuits work.  If you're still new to the concepts and/or hesitant to play with live electricity, you can "practice" your wiring skills virtually. 

Most electronics prototyping/visualisation software is geared for PCBs -- printed circuit boards.  That's both an intermediate/advanced move as well as one more or less alien to this feature's "Boarduino" focus.  If you're serious about electronics design, you will need to learn how to "think" in PCB.  For now, don't worry about it.  In practice, that leaves two non-trivial options:

TinkerCad is "free" in the sense that you can give AutoDesk your email address -- be sure to use the "spam" one -- and play around in the "Electronics" section to see what I mean.  

  • Pros:  It's "free" in the sense that you're giving a large company your email address and the user interface is quite intuitive.  Also, it's online, so no PC-vs.-Mac-vs.-Linux issues to worry about
  • Cons:  AutoDesk offers shockingly small range of "widgets" to plug into the breadboard.   

Fritzing is payware.  (Normally, I'm more than happy to trade money-for-value...until that money is processed by [spits] Paypal.)

  • Pros:  A much, much broader variety of widgets.  Some vendors (wisely) contribute to the Fritzing project; others don't.  But you can normally find something "close enough."
  • Cons:  A slightly steeper -- if unsurprising -- learning-curve because there are more features.  (Pro tip:  Save yourself a bunch of grief and learn how to "lock" main widgets like the breadboard in place.  Otherwise, it's far, far too reminiscent of the mayhem of resizing and image in Microsoft Word.)

Of the two, I personally prefer the features-vs.-complexity balance of Fritzing.  If you're not sure that you're going to stick with this hobby (or don't have access to a payment method that [spits] Paypal will accept), TinkerCad should be more than enough to get a feel for breadboard circuitry.

That' about all I have for this installment.  An excellent deep-dive into the construction of breadboards can be found here: https://protosupplies.com/guide-to-solderless-breadboards.

Next time, I'm planning on going through the often-overlooked mechanics of creating circuits, with, of course, a particular emphasis on breadboards.

Until then, Tchein ton siault d'beluets!

- - - - -

Credit where it's due:  Dennis Freeberg, for the square-on photo of the half-size breadboard.