100 5v led Fairy lights, 2 wires 2 nano pins, H bridge?

Hi,

I have a string of 2 wire LED fairy lights, there are 100 LED's all in parallel with 50% of them reverse polarity. I want to change the controller as the original sequencing is a bit fierce! These fairy lights originally were 5v USB powered. I've written some code which uses two digital to outputs to create a signal on one pin and inverse that signal to the second pin. This works ok with a few leds but the Arduino Nano obviously can't power up 100 led's. I thought maybe I could use a couple of mosfets but although I can get one polarity to light up the reverse polarity does not. I'd assumed that connecting the string of leds to the output's of the mosfets the same way that you'd connect the two wire string to the pins of the Arduino would work but it doesn't. Am I going to have to use an H bridge? I suspect I'm probably going to have to modify my code if I do. For what its worth, the original controller is pretty cool, two small sm chips, a few resistors and a IR detector for the remote control all this from a USB port with 100 very bright leds! I'm not entirely sure I know how to control an H bridge if I have to use one. The following code produces a soft alternating glow with random speed changes every five seconds and at some point I'd like to make time length for the changes random as well however it is the hardware that I'm having a problem with..at the moment. Any pointers or ideas would gratefully received.

const uint16_t sintable2[]={
1021,1046,1071,1096,1121,1146,1171,1196,
1220,1245,1269,1293,1317,1341,1365,1388,
1412,1435,1458,1480,1502,1524,1546,1567,
1588,1609,1629,1649,1669,1688,1707,1725,
1743,1760,1778,1794,1810,1826,1841,1856,
1870,1884,1897,1909,1921,1933,1944,1954,
1964,1974,1982,1990,1998,2005,2011,2017,
2022,2027,2031,2034,2037,2039,2041,2042,
2042,2042,2041,2039,2037,2034,2031,2027,
2022,2017,2011,2005,1998,1990,1982,1974,
1964,1954,1944,1933,1921,1909,1897,1884,
1870,1856,1841,1826,1810,1794,1778,1760,
1743,1725,1707,1688,1669,1649,1629,1609,
1588,1567,1546,1524,1502,1480,1458,1435,
1412,1388,1365,1341,1317,1293,1269,1245,
1220,1196,1171,1146,1121,1096,1071,1046,
1021,996,971,946,921,896,871,846,
822,797,773,749,725,701,677,654,
630,607,584,562,540,518,496,475,
454,433,413,393,373,354,335,317,
299,282,264,248,232,216,201,186,
172,158,145,133,121,109,98,88,
78,68,60,52,44,37,31,25,
20,15,11,8,5,3,1,0,
0,0,1,3,5,8,11,15,
20,25,31,37,44,52,60,68,
78,88,98,109,121,133,145,158,
172,186,201,216,232,248,264,282,
299,317,335,354,373,393,413,433,
454,475,496,518,540,562,584,607,
630,654,677,701,725,749,773,797,
822,846,871,896,921,946,971,996,
};

int idx;
unsigned long startMicros; 
unsigned long currentMicros;
unsigned long rateMicros;
unsigned long rate;
unsigned long changetimer;

const unsigned long period = 2042;  //sets the pwm frequency in microseconds, 2042 microseconds=490hz
const byte ledPin3 = 3;
const byte ledPin4 = 4;
unsigned long duty; 
unsigned long startDuty;

void setup() {
  
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  digitalWrite(ledPin3,LOW);
  digitalWrite(ledPin4,LOW);
 
}

void loop() {

  currentMicros=micros();

  if (currentMicros - changetimer>=5000000){rate=random(1000,3000); 
                                            changetimer=currentMicros; 
                                            rateMicros = currentMicros;} 

  if (currentMicros - rateMicros >= rate){rateMicros = currentMicros;
                                          idx++;
                                          if(idx>=255){idx=0;}
                                          duty=sintable2[idx];}

  if (currentMicros - startMicros >= period){digitalWrite(ledPin3,HIGH);
                                             digitalWrite(ledPin4,LOW);
                                             startDuty=currentMicros;
                                             startMicros = currentMicros;}

 if (currentMicros - startDuty   >= duty  ){digitalWrite(ledPin3,LOW);
                                            digitalWrite(ledPin4,HIGH);
                                            startDuty=currentMicros;}
 
}

How does that fit together with

Sounds reasonable.

led
Original controller probably using H bridge with pwm, pretty standard really.

Using an H-Bridge would work fine. You use one of the arduino PWM outputs to control brightness and the other to select forward or reverse. Forget about using a L293 you will spend a lot of energy compensating for the voltage drop caused by the two darlington pairs used as outputs. Connect the LEDs to the motor output and power the bridge with a 5V power supply rated at least 1 amp for the LEDs, that is assuming 50 LEDs on at 20mA.

A bridge with MOSFETs as outputs would work great. I use BTS7960 H-Bridges, they are inexpensive and drive a lot of amps but will not work here as they need more then 5V on the motor power side.

Using an H-Bridge would work fine. You use one of the Arduino PWM outputs to control brightness and the other to select forward or reverse

Thanks, yes, maybe an H bridge isn't quite as daunting as I thought it might be it's just I've no previous experience with them. I've just been looking at an L9110 2 channel module which seems to fit the bill, cheap, works at low voltage and can handle 800ma so should be fine as the original USB power supply would have been around 500 or 900ma, also looks like there would be minimal code modification too.

1 Like

Are the 100 lights really too much for the Nano to power? Fairy lights are pretty small. My cheap, clunky 50-pixel WS2811 string supposedly draws 60 mA and I think that has three LEDs (RGB) per pixel so 150 LEDs. The fairy lights only light 50 at a time, right? If you’re allowed 40mA per pin maybe the Nano will do it?

I haven’t confirmed the 60 mA number.

That's 60mA per LED when fully white, so 50*0.06 = 3Amp.
Or 60mA per three LEDs if it's a 12volt WS2811 string, = 1Amp.
Leo..

Got it, thanks. Paul_B PM'd me the same info. I had assumed that was for the string; the WS2811 isn't powered from a data pin so it never affected me (although I do power it from the 5V pin and it's working).

I think I'll find some fairy lights to play with but it looks like I should order an H-bridge, too. Thanks for the correction! And the code snippet.

Until the 500mA backflow protection diode of the Nano blows, or the USB port of the laptop stops working.
Leo..

I normally drive the string with a supposedly 5W iPhone cube. Almost certainly I'm getting away with it because the patterns I run come nowhere near max output (last year's lights pattern was probably average of 1.5 colors and an 80% duty cycle, the current one is less than half of that).

Anyway, thanks for the input and if I get any concrete data on fairy pixels that informs this thread I'll be sure to post if it doesn't get locked first.

Yes they are, they will light up but very dim! I actually have two sets now running at slightly different speeds using a dual H bridge and powered by a USB type wall wart controlled by the nano, works really well!

You now will know where to look when it stops working.
It's quite common that the backflow diode of a classic Nano works as a 500mA slow-blow fuse.
You can find that diode right under the USB socket.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.