Everyone loves blue LEDs and everyone loves coin cell batteries, but if you want to power a blue LED from a coin cell you will need some help. Here is a super-cheap and easy way add a to boost your LED voltage with only an additional capacitor & diode, and a little software.
I love that Atmel AVR chips (ATTINY, ATMEGA, Arduino) can run directly on battery voltages from 1.8 volts up to 5.5 volts. I also love that they can drive LEDs directly connected to their IO pins. If you connect a ATTINY directly to a CR2032 and a red LED and blink your life away until the battery is almost completely dead.
Red LED easy, Blue LED hard
Most blue LEDs need more than 3 volts to light up. A brand new CR2032 coin cell makes about 3.2 volts on a good day, and it is all down hill from there. So how can we light a blue LED from a coin cell?
We need more volts, Schottky!
The typical way is to use a boost converter to boost the battery up to a fixed voltage higher than the blue requires and then feed that into the Vcc of the chip. There are some very nice integrated boost converter chips available, but they are expensive (~$1) and require adding a half dozen parts to your design.
This is also power inefficient because chips like the ATTINY use more power at higher Vcc voltages.
You can also roll your own minimal boost converter with an inductor & transistor and a bit of software too. It looks something like this…
It totally works and being able to harness the power of a collapsing magnetic field does impress folks, but inductors are relatively expensive and transistors are fancy goods where I come from. What is a humble cheapskate hacker to do? What is the absolutely most simple and low cost way to light our blue LED?
Pump up the volts, pump them up!
This, gentle readers, is a souped-down charge pump…
Normally charge pumps are more extravagant affairs, but we are cheating by also using the LED as a blocking diode, and using the IO pin as the oscillator. Cool, right?
How the pump works
It really does work like a water pump. Imagine that the capacitor is a diaphragm (like in an expansion tank) and the LEDs are pressure reducing check valves. The diode forward voltage is the minimum open pressure of the valve. The blue valve needs more pressure to open than the PWM output supplies.
When the PWM goes high, it pushes on the diaphragm which pushes fluid down though the bottom valve. When the PWM then goes low, it sucks back on the diaphragm which shuts the bottom valve and creates a vacuum in the tee between the two values. The top valve opens (blue LED lights up) when it sees the full pressure across it rise above its minimum open pressure (forward voltage). The pressure across it is the sum of of the head from the battery above plus the vacuum below – which totals more than just the battery.
It really is a very good analogy and the water based system would totally work if you built it. I kinda want to. I wonder if there are any practical applications for this?
If you prefer to think in electron flow rather than water flow, check out this simulation on EveryCircuit…
The purple trace is the PWM output going from 0 to 2.4 volts. The green trace is the voltage at the node between the two diodes and it goes from a little less than 1 volt to a little more than -1 volt. The reason that the green trace doesn’t swing all the way between 2.4 volts and -2.4 volts is because of the forward voltage drop in the diodes. See the pumping action?
The negative voltage in the green trace is what makes this work. The LED sees the the positive voltage pushing down in its top and the negative voltage pulling down on its bottom. The total voltage across it is more than the battery voltage we started with.
Built it and it will light
If you want to actually see this working on your bench, grab yourself some…
- 0.1uF capacitor
- Blue LED
- Almost diode
Program up the ATTINY with this code…
…and connect it up like this…
Ooh! Gaze at the pretty blue light!
This charge pump works by blinking the LED on once per cycle. If it blinks quicker than about 60 times per second, then it just looks like it is on to your eyes.
The perceived brightness is a function of (1) how bright each individual blink is, (2) how long each blink lasts, and (3) how long the LED is off between blinks.
The first two are dependent on the battery voltage and the size of the capacitor. The last one is dependent on our software driving the IO pin.
How long should we wait between blinks? How big should the capacitor be?
The smaller the capacitor the shorter each blink will be, so smaller capacitors require shorter times between blinks to maintain the same brightness level.
I used a 100nF cap because it is what I had, and 10KHz is the first oscillator frequency I tried and it seemed to work fine.
The included code bit bangs the port for clarity, but in real life you would almost certainly want to use a hardware Timer to generate the PWM output. The AVR Timers are well suited for this because you can easily control the LED brightness using the Timer’s TOP value, which changes the time between blinks.
Q: You said you can connect an LED directly to an IO pin. You can’t. The world will blow up and you will go to hell.
A: You can. I do it all the time and I am still here on earth. I have shipped hundreds of thousands of products without a single current limiting resistor in them, and they have been intimate parts of people’s lives for years without a single case of the world blowing up (or even an LED related failure). I need to write a full article about why this works and why it is good.
Q: If you connect the chip and LED directly to the battery, then the LED will be too bright when the battery is full and slowly get dimmer as the battery drains.
A: You can dynamically adjust the output PWM in software based on the current battery voltage to maintain a constant brightness.
Q: I have a blue LED that happily lights at 2.6 volts. Why don’t you just use these?
A: I have some of those also and they are so cool. If you can find one that suits your application and you don’t mind going dark when your battery eventually drops below 2.6 volts, then you can skip the charge pump. However, there are times when you want to pick your Blue LED based on other parameters (price, form factor, availability) and so it is nice to know that you can use pretty much any Blue LED with just $0.02 extra parts. For example, here is an RGB LED that costs $0.016 (!) that needs 3.2 volts to light blue. The nearest low voltage replacement part I could find lights at 2.8 volts and costs $0.06. For a board with 6 RGB LEDs on it, this charge pump gives a net savings of $0.24, along with slightly longer run time (because we can run the battery down to a lower voltage before we loose blue) and flexibly to use other LEDs in the future.
Q: Wait, you are totally over-currenting that LED when the IO pin goes low! It is going to smoke!
A: Chill out. Remember that the IO pin is current limited in the chip. This limits how fast we can discharge the cap, which limits the current flowing though the LED. It is all going to be OK.
Q: Where did you hear the most awesomest hack-a-day-crowd sentence ever? (“We need more volts, Schottky!”)
A: I know! Awesome right?! So good at so many levels. I made that up myself! I pretty much wrote this article as an excuse to use that sentence.
Q: Does this only work on AVR chips?
A: You should be able to get this to work on any IO pin on any micro-controller chip.
Q: Why bother with all this, I never have any problems driving blue LEDs on my Arduino.
A: A proper Arduino runs from 5 volts, so will drive a 3+ volt blue LED with ease. But a proper Arduino is power hog. This charge pump starts to matter when you want to make things that run for a long time off batteries, in which case connecting low (and variable) voltage batteries directly to the chip is more efficient.
Q: In your roll-your-own boost converter, why not omit the transistor and connect the inductor directly to the IO pin?
A: It will not work. The IO pins* have ESD protection diodes that prevent their voltage from going lower than ground or higher than Vcc, so when the inductor started to boost the protection diode would turn on and short out that excess voltage.
Q: Do I need a Schottky diode?
A: You can probably get a blue LED working with a 3 volt coin cell and almost any normal diode. That said, Schottky will be more efficient and keep working down to a lower battery voltage. It also makes for better section titles than “We need more volts, general purpose silicon”.
Q: How high of a voltage can I make? I want to power my house with this!
A: With one cap and diode, you can make about double the Vbat voltage less the forward voltage drop of the bottom diode. So, with a dying coin cell at 2.4V and a Shottky diode with a forward drop of 0.2v, you should be able to get about 4.6 volts. Enough to light a blue LED. Don’t over think this.
Q: Still, converting 2.4 volts into 4.6 volts is above unity! If I use rechargeable batteries, then I can use the 4.6 volts to have one battery recharge the other back and forth and make a forever glowing blue flashlight and put big oil out of business!!!
A: Nobody loves making over unity devices more than me, but in this case the piper must be paid. The 4.6 volts is almost double input voltage, but it is only on for less than half of the time. This is perfect for lighting an LED because you can’t see it blinking if blinks fast enough, but for charging (even a perfect) a battery, you’d find that the source battery would go dead when the destination battery was less than half full.