Thursday, February 27, 2014

It's always the Red Wire

There's that one thriller where the bomb squad guy has been chasing the same mad bomber for years, finds himself with the inevitable ticking clock in his lap, and remarks something like "I know him, it's always the red wire." and of course he is right. Apparently all hollywood mad bombers since were trained at the same technical school.

There is an underlying truth here... when you're building electronics devices, especially prototypes, there are a lot of wires. (And that, my friends, was an understatement.) There are some wires that it's fine to mix up - digital signals especially. Mistake data and clock lines and the worst that happens is some head-scratching. But there are other wires - like 12v high-current motor connections - which if you swap them with the digital lines, will cause the magic smoke to come out of expensive components and create intense sadness in you.

This is especially likely to happen at 2am, when the last thing left is to plug everything back together and put the case on. "I've done this a hundred times" you think, and you swap two otherwise identical looking leads, and you get smoke and sadness.

If you think that's an acute problem, consider electricians; where getting it wrong means potential death for yourself or the next guy who has to come along and work on the same wires. They mostly solve it using a very strict color-code for "Active", "Neutral" and "Earth" and if you don't follow it you can't be an electrician anymore. They take it that seriously.

So, here's a pro tip for people using those excellent "Dupont" IDC connectors for their Arduino Projects - the wires will generally arrive looking like this:

Oh, so pretty. And the instinct is to leave the ribbon unbesmirched. But here is the first thing you should do:

Immediately separate the cable into a couple of "sets" of wires with specific purpose.
My personal color scheme (constrained by the 'standard colour ordering' of these cables) goes:

Red and Brown: Low Voltage DC, usually the primary 5V (or 3.3) supply. Red is positive, Brown is negative, and helpfully those two colours occur next to each other on the ribbon! These days I like to do power distribution looms so it's obvious when everything's right. If you're really slick, you could twist the pairs to cancel inductive effects.

Orange: High Power DC/AC, like 12V or motor connections or 'raw' power inputs. Orange is the highest-visibility colour, reserved for the most dangerous wires. These are the ones that will kill your project if plugged in the wrong place.

Black: Signal Ground wires - electrically equivalent to brown, but preferentially for low-current 'reference ground' purposes. Signal ground should technically star-propagate from the uController (not the power supply) if you really care about the millivolts, because when significant currents flow in the brown power wires, end-to-end voltages start to differ (current times resistance) which can affect sensors and ADC. But if you get black and brown mixed up - the most likely of all - nothing exciting happens.

The rest are a mish-mash of colours that, in the dark, look pretty much like each other. Use for signal and logic lines and misc.

That's how I roll, anyway. Whatever scheme you pick, follow it religiously. Feel deep inner shame and sin if you violate it. That's why I keep my list short (no standard colours for negative rails, etc) because otherwise I would have to stop using those colours generally. There's never enough red and brown, and too much orange piling up, as it is.

Remember, this is the original Murphy's Law we're talking about. Most people know the generalized version, but Captain Murphy coined it after another test-run was ruined because every single sensor had been wired up backwards. "If there's a way to do it wrong, he will." said Murphy, and recommended buying better plugs.

At some point you will connect an orange wire, notice you just attached it to a blue wire, and will mutter "Hang on..." In that half-second of hesitation, you will save days or weeks of work.

Even in the future, we will still need assorted lengths of coloured wire and cable. This is one of those "habits of a lifetime" things.

The Professor knows what I mean.

"Here's where I keep assorted lengths of wire."
"Whoa! A real live spaceship!"
"I designed it myself. Let me show you some of the different lengths of wire that I used."

No comments:

Post a Comment