A recent conversation reminded me of this horror show:
So I thought it'd be fun to talk about what it is.
Back in high school, I didn't know nearly what I do now about designing electronics. That didn't stop me from trying however, and I still created a number of lame gadgets that only kind of worked. It was a more simple time when everything was through-hole and all my parts were purchased from the Radio Shack which was biking distance from my house. Despite these setbacks, I soldiered (and soldered) on. You could call this era "ch00ftech Alpha".
The above specimen was an attempt at a Slurpee mug that would tell the user the remaining slurpee content using an LED bar graph display. Although...let's face it, it looks horrible, it still did mostly function, and I was the coolest (read: lamest) kid in school as I carried it around.
So what exactly was wrong with it?
If I remember correctly, the circuit for this thing looked something like this:
The idea is that when the switch was closed, charge would enter the mug at the bottom, travel through the liquid, and exit through one or more of the contacts running up the side. This charge would turn on the appropriate transistors and illuminate the LEDs. The farther up the side the current traveled, the more LEDs would light up.
There were a few immediate issues with this thing that should be obvious. Firstly, it looked TERRIBLE. I didn't yet know how to make circuit boards, so I did it all in perf board without any regard for neatness. All of the wires were taped down with camo-print duct tape.
The metal contacts inside the mug were simply the tips of screws that I screwed into the side of the mug. In addition to making the mug less than watertight (and allowing Slurpee to seep into the insulating layers), It was only a matter of time before the acidic Slurpee ate through the screws' zinc coating and they started to rust I'm sure that can't be healthy.
The switch was a panel mount momentary switch that I had purchased at Radio Shack. I mounted the switch cleverly at the top of the handle so it could be depressed by the user's thumb. Unfortunately, this meant that the metal contacts at the bottom of the switch dug into the index finger of the user's hand rather painfully.
All of that aside, there are also a number of interesting electrical issues with the design.
The real problem with this design (and one I remember struggling with at the time) was the configuration of the LEDs and the current limiting resistor.
When filled to about half way and switched on, the LED bank looked something like this:
As you can see, six the LEDs are on, but they're not very even. The bottom LED is substantially brighter than the rest and the LED second from the top of the illuminated portion looks to be hardly lit up at all. It isn't very obvious from this image, but it was very clear in person that the LEDs simply weren't lighting up right. I noticed that with just one or two LEDs, it looked okay, but once a few more lit up, they started to get dimmer with some of them barely lighting up at all.
It wasn't until sophomore year in college (four years later) when I overheard a conversation between a TA and a student in lab that I finally understood what the problem was.
Given how complicated this circuit was sure to be (wires flying everywhere), I was trying to find ways to reduce the number of components required. For example, I opted to use a bar-graph display instead of individual LEDs.
My other corner-cuting technique was to use a single current-limiting resistor for the whole array. I honestly can't remember what value I used or what I even did to calculate it.
This was dumb for a number of reasons. The first and most obvious reason is that the display lit up varying numbers of LEDs depending on how much Slurpee I had left. That means that whatever formula I used to calculate the resistor value with one LED was no longer valid as soon as more LEDs were turned on. This explains why the lights got dimmer as more Slurpee was added.
The second issue has to do with the fact that I had all of the LEDs essentially lit up in parallel.
You Can't Wire LEDs in Parallel!
This is a problem that a lot of budding hobbyists (myself included) have with LED circuits. LEDs are fun. They're cheap, bright, and who doesn't want to just cover their body with them?
On the down side, they are fairly sophisticated semiconductor devices. One of the first things that EEs learn how to do is combining resistors in series in parallel. If you put two resistors of equal value in parallel, you can expect the current through each to be equal. If you were a hobbyist born in 1950, you'd probably be connecting miniature light bulbs in series and parallel to illuminate your model train set or ...jalopy or whatever, and these simple laws of electricity would apply perfectly as light bulbs are basically resistors.
Unfortunately, if you were born in more recent times, your electronics projects typically use LEDs instead of light bulbs, and while much more efficient and colorful, they are a lot more complicated.
An LED is at its core a diode (that's what the D is for). Diodes allow current to travel in just one direction. As charge flows through a diode, it experiences a drop in potential. Most silicon diodes have about a .7V drop from anode to cathode while special Schottky diodes have a smaller drop of about .3V-.4V. We call this the "forward voltage" or . These voltage drops are relatively constant regardless of the amount of current passing through them. If there is not enough potential across the diode to overcome that voltage drop, no current will flow.
This principle can be illustrated using this graph from page 4 of a datasheet for the 1N4148 diode:
If you look at plot 2 (typical values), you can see that zero current conducts until you reach .7V, and after that, the current rapidly shoots up (in theory, it should shoot straight up).
The unfortunate result of this voltage drop is the overall inefficiency of it. When current passes through a device and potential drops across it, that device is dissipating energy (). Show me a diode with a 0V forward voltage and I'll show you a Nobel Prize.
In the case of an LED however, this dissipated energy takes the form of light. Because the photoelectric effect at work here produces exactly one photon per electron and higher frequency photons carry higher energy, higher frequency LEDs must have a larger voltage drop so that they output more power for a given current. Basically, a blue LED will have a forward voltage around 3-3.5V while a red LED will have a drop of about 1.9-2V. So a red LED (like the ones in my Slurpee cup) will conduct very little or zero electricity until the potential across it is about 1.95V.
The real kicker in the previous paragraph is the word "about". In reality, the exact forward voltage of an LED (and any diode for that matter) can vary from component to component. In fact, a lot of datasheets simply give you a range for the forward voltage such as on page 3 of the datasheet for this green LED:
Here they're saying that the forward voltage can be anywhere between 2.1 and 2.6V. That's quite a range!
So now the question is: how do you deal with a device with such ridiculous voltage requirements? The LED needs enough voltage to overcome its forward voltage, but if you exceed it by even a small amount, the current will shoot up and potentially damage it. Further exacerbating the issue, you can't even tell exactly what the forward voltage is from the datasheet!
The easiest solution is to add a resistor in series. The voltage across the LED is relatively constant (defined by the datasheet), while the voltage across a resistor depends on the current passing through it. Let's consider a simple case of a resistor in series with our green LED powered by a 5V source:
The potential drop across the resistor and diode together must add up to 5V.
The voltage across the resistor will be proportional to its current as Ohm's law dictates:
Now, from what we said before, as soon as the voltage across the LED goes even a little bit higher than , the current will try to shoot up and damage the LED. With this configuration though, you can see from the formula that the voltage drop across the resistor () will increase as the current increases. As a result, the voltage drop across the LED must decrease back down to a safe level.
This will act as a sort of feedback system. With this feedback system in place, the potential across the LED will hover at just about its forward voltage regardless of what that exact forward voltage happens to be.
That resistor is customizing the potential drop across the LED to match its specific .
When setting up a circuit with an LED and resistor, all you need to do is plug the values into the equation above (approximating using the datasheet range) and choosing the appropriate resistor for your desired current flow (usually around 20mA).
Note that this trick also works for LEDs in series. By adding the s of the LEDs together, you can treat the group as one giant meta-LED and plug the sum into your equation for .
Now, one of the first things any hobbyist tries to do is wire up a bunch of LEDs at once. This becomes a problem because connecting them in series will require a very large voltage supply to overcome the meta-forward voltage.
You might be tempted to do something like this:
This would be a perfectly valid approach if you were dealing with light-bulbs, but as we established before, LEDs are different.
In a perfect world, this solution would work. Both of the LEDs would have precisely the same and the current in the circuit would settle at a safe level. You would want to choose a resistor value that drops the appropriate amount of voltage given the current passing through it which in this case would be the sum of the currents passing through each LED (about 40mA).
Unfortunately, this isn't a perfect world.
Let's take our single-LED circuit from before and add a blue LED in parallel with the green one:
The forward voltage across the green LED is around 2.1V while the forward voltage of the blue LED is around 3V (higher frequency = higher remember)?.
So what's going to happen in this circuit? Well, if you keep everything the same from before, nothing will change. The green LED will light up as it did, and the voltage across the blue LED will not be high enough to turn it on, and no current will flow through it. You might as well have never added the blue LED at all. If you actually expected the blue LED to light up, you're out of luck.
So what about our two green LEDs?
Well, remember how the forward voltage of an LED will vary from component to component? The probability of these two LEDs having exactly the same is basically zero. Just like with our green-blue example, all of the current will travel through the LED with the slightly lower , and the other LED won't light up at all.
What's worse is that if you picked your resistor for the combined current of both LEDs (40mA), you will now have 40mA traveling through one LED! This could potentially shorten its lifespan. If you were running hundreds of LEDs in parallel, this would immediately blow up the LED with the lowest .
In practice, the isn't quite so sharp, and some current will flow through an LED even when it's slightly below its , but the important thing is that much more current will flow through one LED than the other.
So the reason that my circuit was being lit so unevenly is because I was doing exactly that. I suspect that the bottom LED had the lowest of the bunch, while the dimmest one had the highest .
A better design would have a current-limiting resistor on each branch:
You could even combine series and parallel:
So this is a mistake that I think every hobbyist makes at some point. In fact, even the Mythbusters screwed this one up.
Here, Tory is busting the myth that LEDs on your car can somehow fool a LIDAR speed detector. He's attaching a few LEDs to a toy car to act as a scale model. Here's a close up.
OOPS! I don't think wiring the LEDs differently would alter the outcome of the myth (which was busted by the way), but he could definitely have done a better job wiring this. Looks like he doesn't have a current limiting resistor at all!
So anyway, I hope you enjoyed this little foray into semiconductor physics that I think is tragically left out of most intro-level electronics courses. If you want to make your own super mega flashlight, just make sure you wire your LEDs right.
Sweet article! You're a great teacher
I agree. The write-up is well done and is 'forward' moving... ( I kid I kid )
Well done... and while it might not seem it.. for the hobbyist very useful.
Pingback: Ultrasonic parking sensor | ch00ftech Industries