Skip to content

Weekend hacks: low-powered LEDs

I’m a suck­er for blink­ing lights. Every­thing I’m build­ing or is sit­ting in my note­book in var­i­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 project. ahem) and dis­cov­ered small cheap bat­tery-pow­ered light strings, I couldn’t resist pick­ing some up. No speci­fic project in mind, but how hard can the­se things be to dri­ve with an Arduino 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­troller relies on a basic timer to run for 6 hours in the evening and stay off the rest of the time. I guess it’s up to the user to go and recal­i­brate the timer every mon­th 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­troller and play around, to get a feel for how the sys­tem was intend­ed to work. And it’s pret­ty sim­ple. There’s a push but­ton on the con­troller to switch between full on, timer mode and off.

Then I opened it up, and the con­troller was about as sim­ple as I expect­ed. There’s a small unmarked IC; undoubt­ed­ly a ven­er­a­ble 555 timer, a few capac­i­tors to run the 555 in astable mode, and a tran­sis­tor to switch the lights.

I’d like to replace that with some sort of Arduino-based con­troller, so I broke out my mul­ti­me­ter to check what the LEDs were run­ning from. I found that the volt­age drop across the string was an even 3V, down a lit­tle from the 3.6V input from my recharge­able 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 Arduinos can typ­i­cal­ly sup­ply from their on-board 3V reg­u­la­tor, so I’d have to provide my own low­er volt­age. But apart from that, mak­ing the­se things slight­ly smarter shouldn’t present any real chal­lenge.

Building a replacement circuit

Drawing up a schematic for a replacement driver

Draw­ing up a schemat­ic for a replace­ment dri­ver

So a replace­ment dri­ver for the­se lights would need two parts; a low­er volt­age pow­er sup­ply, and some­thing to switch them on and off based on input from the Arduino. I pulled out my note­book and start­ed to draw up a solu­tion.

For the pow­er, I used an LM1117 3.3V lin­ear reg­u­la­tor. Thanks, past me, for buy­ing a dozen the last time you need­ed one. All I did with that was copy the exam­ple usage schemat­ic out of the data sheet.

And then I added an NPN tran­sis­tor as a low-side switch (I real­ly like Sparkfun’s tran­sis­tor tuto­ri­al to help under­stand how to use tran­sis­tors as switch­es like this).

That’s real­ly all that’s required. I could run an Arduino from a 5V USB con­nec­tion, feed pow­er from the Arduino’s Vin pin to this cir­cuit, and use a dig­i­tal out­put from the Arduino to switch the lights on and off. Time to see if it works.

Testing and assembly

Assembled circuit on breadboard

Assem­bled cir­cuit on bread­board

While assem­bling I realised my schemat­ic had a cou­ple of prob­lems. First, see­ing as I was receiv­ing a reg­u­lat­ed 5V sup­ply, using two smooth­ing capac­i­tors for the lin­ear reg­u­la­tor would be overkill, so I just omit­ted one. Sec­ond, I wasn’t sure if the LED string would need cur­rent-lim­it­ing resis­tors, so I assumed that it would and added a 100Ω resis­tor.

I put cir­cuit togeth­er on a bread­board and wired my LED string to the board. Then I took a Freetron­ics Leo­stick I had spare, con­nect­ed the 5V and GND pins to my cir­cuit, and the sig­nal to a PWM pin. Load­ed up the Blink exam­ple sketch and… noth­ing hap­pened.

So out came the mul­ti­me­ter again. First check­ing that all of the con­nec­tions were solid, and then I start­ed mea­sur­ing volt­ages in dif­fer­ent places. I had the right volt­age com­ing out of the reg­u­la­tor. The Arduino was switch­ing the right out­put pin on and off. And I was even get­ting the volt­age read­ings I was expect­ing across the LED string. But no blinky-blinky. After glar­ing at it for a min­ute or two inspi­ra­tion struck, and I swapped the leads to the LED string around. Blinky-blinky.

Final­ly, I sol­dered my com­po­nents in to a small strip of pro­to­typ­ing board. I intend­ed it to be a sort of shield for the Leo­stick, so I added head­er pins for pow­er and sig­nal, and the whole con­trap­tion just plugs in on top. I added a cou­ple more head­er pins for the LED string, and crimped DuPont con­nec­tors on to its leads. Hard­ware com­plete!

Assembled driver circuit

Assem­bled dri­ver cir­cuit

Programming the Arduino

I want­ed 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 sta­t­ic lev­el. More advanced com­mands might include blink­ing, or slow­ly fad­ing between two dif­fer­ent lev­els. My FairyLights.ino sketch imple­ments a very sim­ple text pro­to­col to con­trol the lights, cur­rent­ly just set­ting a sta­t­ic lev­el (and the all-impor­tant help com­mand). I’ve writ­ten enough text parsers in Arduino that I real­ly couldn’t be both­ered doing it again, so I picked up the Cmd­Parser library to han­dle all the hard work, mak­ing my sketch very straight­for­ward based on the Cmd­Parser call­back demo code.

Lighting it up

I strung the lights up around the desks in my home office, and plugged my new Arduino-based con­troller in to my desk­top PC. Con­trol­ling this setup over a seri­al con­nec­tion is a triv­ial task in any lan­guage, but see­ing as this machine is most­ly run­ning Win­dows the­se days I thought it’d make sense to talk to it using Pow­er­Shell. My result­ing script takes a num­ber as a para­me­ter, opens a seri­al con­nec­tion and uses the set com­mand to set the LED light lev­el. Unfor­tu­nate­ly Win­dows makes it slight­ly dif­fi­cult to run a Pow­er­Shell script with­out pop­ping up a con­sole, with the com­mon solu­tion being to launch the script from a VBScript. So the Win­dows direc­to­ry for this project includes the con­trol script, as well as a cou­ple 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 Raz­er Chro­ma key­board. And now I have kitc­shy bling at my fin­ger­tips.

Finished project

Fin­ished project

This was a pret­ty point­less but most­ly fun lit­tle hack. As usu­al, all of my code for this is in my arduino repos­i­to­ry. The whole process took me some­where around 6–7 hours over a cou­ple of days. That includ­ed the time I wast­ed with the LED leads the wrong way around, as well as fig­ur­ing out a weird hard­ware-relat­ed prob­lem with Cmd­Parser (see my pull request for details). Hope­ful­ly this post gives a lit­tle insight in to how I think about and put togeth­er my projects, and pro­vides some inspi­ra­tion for oth­er people’s.

Post a Comment

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