Hey folks,
I picked up an Arduino Mega for a project I'm working on which requires a bunch of PWM outputs. Basically I want to use motion sensors to detect family members approaching a stairway, and once detected I want to fade in a set of 4 LED's (2 per side of the step) in sequence to the top (or bottom, depending on which motion sensor), and then fade out sequentially after a set time period. There are 8 steps.
The coding I have no problem with, but the hardware has me stumped.
I picked up some 3W 5-35V 700mA LED drivers with PWM input from AliExpress, but they have nothing included to show how best to wire them. I suspect the LED's need to be wired in series, as they are blue LED's with a forward voltage of 3.4 volts (and the minimum for the driver is 5v). What I don't know is whether these drivers are going to just work with the 4 LED's attached, or whether I need resistors, etc. to keep them from cooking. I've read articles on runaway voltage, etc. and it's getting to be quite the headache so I'm hoping someone has experience with this.
I was planning on wiring each step (4 LED's) to their own individual LED driver, controlled on a digital pin of the Arduino for PWM.
Can someone provide some insight into how I can properly wire these LED drivers to save me a smokeshow?
That is the link for the drivers. The LEDs are just some 1/8" diameter clear LEDs that light up blue. As I've had them in a bag from a purchased item that I scavenged years ago, I unfortunately don't have a link for them.
Warning take all of this with a grain of salt. I do not believe these to be the correct part for standard indication LEDs. These are likely designed for high power LEDs.
This is circuit is actually based on Buck DC/DC converter. It has two feedback circuits. One for current and one for voltage. I found the datasheet here, but it does not go into much detail on certain things.
Your module is likely based on Typical Application Circuit (Buck LED Constant Current Driver) on page 4. It may be interesting to know the values of R1, R2 and R3. The SMD codes is good enough. However I will assume their values based on 3W .7A output with 5-35V input.
I suspect this circuit is really a switch mode regulator. FB is a voltage feedback pin which may have the voltage set to 4.29V. (3W / .7A = 4.29V) You may be able to test this with open circuit load, dummy power resistor or high ohm resistor.
Unlike switch mode regulator there is current feedback pin, CS. This pin measures the output current and may attempt to regulate the voltage. I suspect this is secretly a second voltage feedback circuit by measuring the voltage drop across a current sense resistor. FB sets the max voltage to the LED while CS limits the current through the LED.
If this this correct I would need to know how much current is needed by each LED. Likely the LEDs would need to be in parallel. A current limiting resistor is needed for a forward voltage of 3.4V. This is to burn off the excess voltage and force FB to throttle current. Aka constant voltage.
If the LEDs are very high power and consume a decent amount of current. Then you may not need a resistor. However these should not be parallel LEDs without careful balancing. If the current draw of the LEDs is near 700mA then CS will throttle voltage. Aka constant current.
Please note the PWM pin is secretly the regulators enable pin. (EN) It is active low. The max frequency for this is not specified.
I looked at the board. FB is actually connected to ground. Only CS is used in this circuit. R1, R2 and R3 are parallel current sense resistors. This circuit has max output voltage of 37V.
Do not use this unless you will drive 700mA
Edit:
If you change resistors you can make it work. R = 0.155 / I. So for 20mA you need 7.75 Ohms. You will be able to do this with a single resistor more than likely. Take this also with a grain of salt.
I can use any voltage really. As I mentioned earlier, no stats on the LED's as they were removed from something I purchased.
I don't necessarily need to use those LED's. I could purchase some of those 700mA high power LED's for this project, but they may get a little hot for my application. I have just 3d printed some small PLA enclosures that I drilled out to accommodate my LED's, and high power LED's could get too hot for PLA.
Really, any combination of driver or power supply would be fine with me, I just need to know what I'm shopping for.
I should mention as well, I originally planned on building this with a 74HC595 shift register, until I realized that each shift register required 3 separate PWM pins on the Arduino to make it work. Hence the approach to use an LED driver, of which I obviously hadn't researched enough before buying what I did.
You should only need one or two shift registers. Ironically, I would be tempted to just use GPIO on this. (8 to 16 pins.) Using one or two ULN2801A for current sink. You could drive that from shift register. I think it would be better to use ATMega's underlying pin banks. Then use BCM/BAM with timer or maybe something simpler.
If willing to use 16 wires, I would send a wire to each side of the steps. So 8 wires on each side. Two LEDs in series on each side of the step. Then send a power wire up each side also. The power wire is in parallel, feeding each LED chain.
The 16 wires return each channel of two ULN2801A. I would recommend using something like 12V for the power line. Which could be used to power the Arduino Mega. If you only want to use a single ULN2801A and 8 pins on Arduino Mega. Connect both sides of a single step to the same channel of the ULN2801A.
Note this will require series resistors here to limit the current of each of the 16 wires to 20mA. The ULN2801A has a high voltage drop however should not be too bad at 20mA. I think you would need 16 240 ohm resistors placed in series with the LEDs. This should also work a single ULN2801A.
Note if you decide to increase the current per wire to increase brightness you can. However I would not recommend exceeding 150mA per channel for two ULN2801As and 75mA for a single ULN2801A. (Assuming you plan to use all channels at once from time to time.) Current resistors would need to be recalculated and you may need to increase the power wire voltage, which may exceed Arduino Mega's input range.
I do not know if any of this was helpful or not.
Edit:
You could also use the Arduino Mega's PWM pins. This may make the software a little cleaner.
What if I used 8 shift registers (1 per step) and linked the clock and data pin of all shift registers to the same PWM pins on the Arduino Mega? Or would it overload the pins somehow?
Using this method, I would only need 8 more PWM pins from the Arduino Mega for the latch pins of each shift register and they could all be controlled independantly.
So you want to make a chain of 8 shift registers. Have the latch and clock in parallel. While the data is cascaded. The output enable pin of each is connected to is own PWM pin on the Mega. Is this correct?
I am guessing you want to use 74HC595's because you have a few on hand, correct?
If so you are basically using the 74HC595's as ULN2801A's. We may be able to get the circuit down to 8 pins. You plan to control the LED's through the Arduino Mega's PWM pins which is connected to 74HC595's OE pin, correct?
If so what you can do is wire the data input of the 74HC595 to VCC. Wire OE, clock and latch together to that 74HC595's Arduino Mega PWM pin. There is not need to chain the 74HC595's with this setup. What your setup logic will need to do is generate a 50 percent duty cycle for a specific number of cycles on all 8 PWM pins. This will need to be more than 8 cycles at least. What this will do is propagate ones into the shift and latch registers. Which will allow output enable to control the LEDs.
This will be very similar to the configuration of the ULN2801A. However there is less current and voltage capacity. Overall this circuit is more expensive unless you have them already. Note you will use more wire if the the shift registers are located with the LEDs. However in this case it may be recommended to do this. We will get into that next, assuming both of these assumptions are correct.
Edit:
We will want to control the frequency of the PWM pins. If we do this there will be no timing violation on the 74HC595. We should be able to set the frequency to a number which will not affect the LEDs but ensure proper timing even against low/high duty cycles. I do not know how many PWM bits are required.
ULN2801A avoids a lot of these problems, but this should be possible on 74HC595. Note you may not get full 20mA on all four LEDs with 74HC595. However you can if you use max allowed voltage on 74HC595 which is about 7V. This may require a level shifter. 7V power supply can power Arduino Mega.