Skip to content

Weekend hacks: low-powered LEDs

I’m a suck­er for blink­ing lights. Everything I’m build­ing or is sit­ting in my note­book in vari­ous stages of think­ing about involves some sort of LED, EL pan­el or oth­er bright thing. So when I went to Bun­nings yes­ter­day (buy­ing lights for a dif­fer­ent pro­ject. ahem) and dis­covered small cheap bat­tery-powered light strings, I couldn’t res­ist pick­ing some up. No spe­cif­ic pro­ject in mind, but how hard can these things be to drive with an Ardu­ino right?

LED Light StringYou get a 6m string of wire with 60 tiny LEDs on it. It runs on 3AA bat­ter­ies, and the con­trol­ler relies on a basic timer to run for 6 hours in the even­ing and stay off the rest of the time. I guess it’s up to the user to go and recal­ib­rate the timer every month or two so it still makes sense. It cost me $15 from Bun­nings, but I couldn’t find it on their web­site just now, so YMMV.

Initial exploration

Testing LED string current

Test­ing LED string cur­rent

The first thing I did was to put bat­ter­ies in to the con­trol­ler and play around, to get a feel for how the sys­tem was inten­ded to work. And it’s pretty simple. There’s a push but­ton on the con­trol­ler to switch between full on, timer mode and off.

Then I opened it up, and the con­trol­ler was about as simple as I expec­ted. There’s a small unmarked IC; undoubtedly a ven­er­able 555 timer, a few capa­cit­ors to run the 555 in astable mode, and a tran­sist­or to switch the lights.

I’d like to replace that with some sort of Ardu­ino-based con­trol­ler, so I broke out my mul­ti­meter to check what the LEDs were run­ning from. I found that the voltage drop across the string was an even 3V, down a little from the 3.6V input from my rechargeable bat­ter­ies, and draw­ing a hair over 92mA.

I didn’t think it would be a great idea try­ing to run them from a 5V sup­ply, and the cur­rent draw was a lot more than Ardu­i­nos can typ­ic­ally sup­ply from their on-board 3V reg­u­lat­or, so I’d have to provide my own lower voltage. But apart from that, mak­ing these things slightly smarter shouldn’t present any real chal­lenge.

Building a replacement circuit

Drawing up a schematic for a replacement driver

Draw­ing up a schem­at­ic for a replace­ment driver

So a replace­ment driver for these lights would need two parts; a lower voltage power sup­ply, and some­thing to switch them on and off based on input from the Ardu­ino. I pulled out my note­book and star­ted to draw up a solu­tion.

For the power, I used an LM1117 3.3V lin­ear reg­u­lat­or. Thanks, past me, for buy­ing a dozen the last time you needed one. All I did with that was copy the example usage schem­at­ic out of the data sheet.

And then I added an NPN tran­sist­or as a low-side switch (I really like Sparkfun’s tran­sist­or tutori­al to help under­stand how to use tran­sist­ors as switches like this).

That’s really all that’s required. I could run an Ardu­ino from a 5V USB con­nec­tion, feed power from the Arduino’s Vin pin to this cir­cuit, and use a digit­al out­put from the Ardu­ino to switch the lights on and off. Time to see if it works.

Testing and assembly

Assembled circuit on breadboard

Assembled cir­cuit on bread­board

While assem­bling I real­ised my schem­at­ic had a couple of prob­lems. First, see­ing as I was receiv­ing a reg­u­lated 5V sup­ply, using two smooth­ing capa­cit­ors for the lin­ear reg­u­lat­or would be overkill, so I just omit­ted one. Second, I wasn’t sure if the LED string would need cur­rent-lim­it­ing res­ist­ors, so I assumed that it would and added a 100Ω res­ist­or.

I put cir­cuit togeth­er on a bread­board and wired my LED string to the board. Then I took a Freet­ron­ics Leostick I had spare, con­nec­ted the 5V and GND pins to my cir­cuit, and the sig­nal to a PWM pin. Loaded up the Blink example sketch and… noth­ing happened.

So out came the mul­ti­meter again. First check­ing that all of the con­nec­tions were sol­id, and then I star­ted meas­ur­ing voltages in dif­fer­ent places. I had the right voltage com­ing out of the reg­u­lat­or. The Ardu­ino was switch­ing the right out­put pin on and off. And I was even get­ting the voltage read­ings I was expect­ing across the LED string. But no blinky-blinky. After glar­ing at it for a minute or two inspir­a­tion struck, and I swapped the leads to the LED string around. Blinky-blinky.

Finally, I soldered my com­pon­ents in to a small strip of pro­to­typ­ing board. I inten­ded it to be a sort of shield for the Leostick, so I added head­er pins for power and sig­nal, and the whole con­trap­tion just plugs in on top. I added a couple more head­er pins for the LED string, and crimped DuPont con­nect­ors on to its leads. Hard­ware com­plete!

Assembled driver circuit

Assembled driver cir­cuit

Programming the Arduino

I wanted to be able to con­trol the lights by send­ing com­mands over a seri­al con­nec­tion. At the very least, I should be able to set them to a stat­ic level. More advanced com­mands might include blink­ing, or slowly fad­ing between two dif­fer­ent levels. My FairyLights.ino sketch imple­ments a very simple text pro­tocol to con­trol the lights, cur­rently just set­ting a stat­ic level (and the all-import­ant help com­mand). I’ve writ­ten enough text pars­ers in Ardu­ino that I really couldn’t be bothered doing it again, so I picked up the Cmd­Pars­er lib­rary to handle all the hard work, mak­ing my sketch very straight­for­ward based on the Cmd­Pars­er call­back demo code.

Lighting it up

I strung the lights up around the desks in my home office, and plugged my new Ardu­ino-based con­trol­ler in to my desktop PC. Con­trolling this setup over a seri­al con­nec­tion is a trivi­al task in any lan­guage, but see­ing as this machine is mostly run­ning Win­dows these days I thought it’d make sense to talk to it using Power­Shell. My res­ult­ing script takes a num­ber as a para­met­er, opens a seri­al con­nec­tion and uses the set com­mand to set the LED light level. Unfor­tu­nately Win­dows makes it slightly dif­fi­cult to run a Power­Shell script without pop­ping up a con­sole, with the com­mon solu­tion being to launch the script from a VBScript. So the Win­dows dir­ect­ory for this pro­ject includes the con­trol script, as well as a couple of vbs wrap­pers to turn the lights on and off.

The final step for me was to bind the on and off com­mands to spare macro keys on my Razer Chroma key­board. And now I have kit­c­shy bling at my fin­ger­tips.

Finished project

Fin­ished pro­ject

This was a pretty point­less but mostly fun little hack. As usu­al, all of my code for this is in my ardu­ino repos­it­ory. The whole pro­cess took me some­where around 6 – 7 hours over a couple of days. That included the time I wasted with the LED leads the wrong way around, as well as fig­ur­ing out a weird hard­ware-related prob­lem with Cmd­Pars­er (see my pull request for details). Hope­fully this post gives a little insight in to how I think about and put togeth­er my pro­jects, and provides some inspir­a­tion for oth­er people’s.

Post a Comment

Your email is never published nor shared. Required fields are marked *