20W LED Stuck 'On' with IRF520

Hi all.
I built and tested the below motion detector using a Nano, MPU6050, and IRF520 MOSFET to drive a shaped pulse on a 20W LED. Worked fine, so went ahead and built+installed 50 units as per my plan.
However: Of the 50 working units, 4 or 5 (I think the same ones) behave badly. Once the motion threshold is tripped, the pulse sequence seems to work as usual, but the LED then remains stuck On, until I or reset or power off-on the unit.

Any idea what might be causing this ‘Stuck On’ state? :confused:
(PS - I am an Arduino noob…)

(circuit diagram attached below)

(role of the 40 ohm resistor is to slightly lower the voltage seen by Vin pin. Was using cheap knock-off Arduino’s and was advised not to trust the 12 (15V?) Vin max spec).

And here’s the code:

int ledPin=3;
float sinVal;
int ledVal;
const int MPU_addr=0x68;  // I2C address of the MPU-6050
const int Thr=500; // Movement sensing threshold to trigger the LED
int16_t AcX,AcY,AcZ,TotAc,TotAcOld;
void setup(){
 TotAcOld=Thr;
  pinMode(ledPin, OUTPUT);
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,6,true);  // request a total of 6 registerMs - Acceleration only
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  TotAc=int(sqrt(sq(long(AcX))+sq(long(AcY))+sq(long(AcZ)))); 
  if (abs(TotAc-TotAcOld)>Thr){
    PulseLed(); 
  }
  TotAcOld=TotAc; 
  //Serial.println(TotAc);
  delay(200);
}

void PulseLed(){
  for (int x=3; x<178; x++) {
// to get quick rise and slower decay pulse shape
sinVal = (sin(x*(3.1412/180)));
ledVal = int(sinVal*255);
analogWrite(ledPin, ledVal);
delay(x/10);
}
for (int x=100; x>0; x--) {
//slowly decaying tail of pulse
analogWrite(ledPin,x/8);
delay(400/(x+0.5));
}
digitalWrite(ledPin,LOW);
}

Your circuit diagram didn't load. so i don't know how you have it wired. But i've recently watched a couple detailed videos concerning mosfets to learn more about them to build a power supply, and i'm going to assume that you don't have a 1K resistor from the gate to the ground. Mosfets are designed once they receive a pulse and turn on, they will remain on until the gate grounds and looses all of it's charge. which is why it's staying on until you reset it. when you get time, check out this video. Power MOSFET Magic - YouTube

Thanks widlcat99s, yet something's wrong with the image URL so I attached as a file.
The 1k reistor IS there - see diagram - presumably to avoid the situation you describe. Tx.

So you built 50 units. and out of all of those, 4 or 5 are messing up? and rest of them work normally? or does the glitch effect all of the units? are they all wired together.... supposed to come on and go off together? or are they sequential and only the ones that are triggered turn on and then turn off a short time later.... and those 4-5 are stuck on?

The IRF520 is not a logic level MOSFET, and requires 10V on the gate for full switching. It can't be relied upon to switch using 5V logic. The LED and series resistor don't help.

That would not explain why it is stuck on, though. Perhaps some are defective (the gate can be destroyed by static electricity during handling).

Your schematic, posted properly:

The MPU6050 won't work without a ground connection.

Your schematic doesn't show any current limiting for the LED!!! Is that a raw LED or a 12V LED light bulb with circuitry built in?

You might be "killing" the MOSFET, but it's an odd symptom to latch-on once and then switch off with a reset.

What's the regular-little LED doing? Is it going on & off as expected?

(The 1K resistor shouldn't make a difference after Arduino is powered-up & working properly with D3 configured as an output...)

DVDdoug:
Your schematic doesn't show any current limiting for the LED!!! Is that a raw LED or a 12V LED light bulb with circuitry built in?

You might be "killing" the MOSFET, but it's an odd symptom to latch-on once and then switch off with a reset.

What's the regular-little LED doing? Is it going on & off as expected?

(The 1K resistor shouldn't make a difference after Arduino is powered-up & working properly with D3 configured as an output...)

Yea, I kind of thought the same thing except that I don't know if any 20W single raw LED that runs at 12v. Most of the 10W units run around 9 to 11v and then jump to 30v-32v for 20W, 30W, 50W, and 100W.

But I agree with the MOSFET as perhaps an issue and would have used the switching flavors such as the FQP30N06L.

But if "only" a 10% failure rate I guess isn't too bad (ha). Were all the parts true blue real components from reputable vendors such as Mouser, Digikey, or Farnell? Or sourced from sometimes questionable Ebay vendors?

What I'm implying is that there might be a defective part in those bad units. Try switching out the LED or MOSFET with a known working unit and try and isolate the issue.

And BTW to the OP: Would you share what the purpose or plan behind 50 of these? I could see this as a security device to make sure there is an alert if someone moves some particular valuable item. Or they could be a new version of the old school pinball tilt protection.

Between the mosfet selection and the gate circuit with the led indicator, it’s just luck that it works. Did you ever measure the drain to source voltage when they where on to see how much power they were dissipating? That should be part of any post production acceptance test.

With respect to the latch up, the elephant in the room is that 40 ohm resistor in series with Vin and the lack of a gate series resistor to limit AVR output current at turn on.

When the mosfet turns on, you get a fairly large current spike due to the gate capacitance and you’ll have voltage drop across the resistor which can cause the regulator to drop out, dipping the supply voltage to the processor, causing lock up. Reset would put things right as the voltage is back in spec in micro/milliseconds.

That’s the theory at least. Checking the voltage drop at turn on with a scope would be the best/easiest way to confirm what’s happing.

DVDdoug:
Your schematic doesn't show any current limiting for the LED!!! Is that a raw LED or a 12V LED light bulb with circuitry built in?

You might be "killing" the MOSFET, but it's an odd symptom to latch-on once and then switch off with a reset.

What's the regular-little LED doing? Is it going on & off as expected?

(The 1K resistor shouldn't make a difference after Arduino is powered-up & working properly with D3 configured as an output...)

Thanks DVDoug
Its actually raw LEDs - two 10W LEDs wired in parallel.
I doubt the MOSFET is killed - it's spec says 2A max Ids - but with a supply voltage of 12V, we should still be under 2A for a 20W load (and - i dont think 20W is exceeded - the LEDs arent burning out).
Note that the IRF520 is a module (not a standalone MOSFET), that includes the regular little LED (to indicate signal) and resistors, on-board. Yes, it goes on and off as per the signal from the Nano.

WattsThat:
Between the mosfet selection and the gate circuit with the led indicator, it’s just luck that it works. Did you ever measure the drain to source voltage when they where on to see how much power they were dissipating? That should be part of any post production acceptance test.

With respect to the latch up, the elephant in the room is that 40 ohm resistor in series with Vin and the lack of a gate series resistor to limit AVR output current at turn on.

When the mosfet turns on, you get a fairly large current spike due to the gate capacitance and you’ll have voltage drop across the resistor which can cause the regulator to drop out, dipping the supply voltage to the processor, causing lock up. Reset would put things right as the voltage is back in spec in micro/milliseconds.

That’s the theory at least. Checking the voltage drop at turn on with a scope would be the best/easiest way to confirm what’s happing.

Thanks that’s a great comment, I was actually also thinking along the same lines - is there a current spike that might undermine Vin momentarily, due to the resistor. However: Looking at the circuit diagram, I cant see how that might happen, as the current spike will go throught the MOSFET and the LED directly between Vcc and Ground - and NOT (as far as I can see) affect, or traverse through, the 40 ohm resistor. Will def try looking with a scope, however: Can you propose how said current spike might actually traverse the 40 ohm resistor, etc?

jremington:
The IRF520 is not a logic level MOSFET, and requires 10V on the gate for full switching. It can't be relied upon to switch using 5V logic. The LED and series resistor don't help.

That would not explain why it is stuck on, though. Perhaps some are defective (the gate can be destroyed by static electricity during handling).

Your schematic, posted properly:

The MPU6050 won't work without a ground connection.

Thanks for reposting the diagram properly, jremington.
You're of course correct about the 6050 ground connection - It does of course exist (GND pin to ground), but my circuit drawing is sloppy, i missed that in the diagram...
The LED and resistors in the MOSFET gate circuit are part of the IRF520 module board. And, despite the need for 10V - it does respond to the Nano output, and switch. Nor do i think the bad units are destroyed - they do respond, but behave differently, as i described...

Its actually raw LEDs - two 10W LEDs wired in parallel.
I doubt the MOSFET is killed - it's spec says 2A max Ids - but with a supply voltage of 12V, we should still be under 2A for a 20W load (and - i dont think 20W is exceeded - the LEDs arent burning out).

It would be a good idea to measure the current.

Sometimes you can get-away without current control/limiting but it's usually a "bad design". It may be OK for a one-off hobbyist project, but when you "go into production" with 50 units, or if you need reliability, you might want to think twice.

LEDs are the opposite of light bulbs. With a light bulb (or almost anything else) you supply a fixed voltage and the current "falls into place". But LEDs are non-linear... Their resistance changes with voltage, dropping drastically as voltage increases so it's easy to get excessive current. You normally supply a fixed current and the voltage "falls into place". (It's not "easy" to make a constant-current supply.)

The LED isn't burned out and the MOSFET isn't totally fried either since it turns-off with a reset but something "funny" is happening to the MOSFET. It's not always the LED that goes first with over-current... Is the MOSFET too hot to touch?

Note that the IRF520 is a module (not a standalone MOSFET), that includes the regular little LED (to indicate signal) and resistors, on-board.

Did you buy it from a reputable supplier or from eBay or some other cheap source?

Yes, it goes on and off as per the signal from the Nano.

OK, that proves the Arduino is working, but I'd take-out that 40 Ohm resistor.

Thanks for all helpful answers yesterday!
Following a day of oscilloscope analysis + tweaking, here's what I found:

  • Indeed interference on Vin pin due to LED current switching
  • Occurs both on a 500Hz/1V ptp basis (mirroring the LED's pwm switching); as well as very intense spikes - tens of volts peak (!!?!) for tens of nanoseconds, then decaying ringing; More so when the LED extinguishes
  • Not affected by presence or absence of the 40ohm resistor
  • Adding a 225nf capacitor to ground on the 12V supply entry and on the Vin pin eliminates the spikes and ringing, but not the lower frequency 1V ptp interference
  • The 'stuck' state is difficult to reproduce, which doesnt ease the debugging... Yet I have been able to determine that when it occurs, the nano's PWM output is still active (same characteristics as when not stuck). There's also a host of non-stuck behaviors that are nevertheless erroneous, such as the pulse appearing twice instead of once, or with a very deformed, erratic waveform. All appear to revert to normal after a reset.
  • I've been advised and added to the code a Watchdog Timer (neat trick!), which resets the nano after 4 seconds in the absence of the normal running loop. Easy peasy, but, as noted above - wasnt able to fully verify it's effectiveness against the 'stuck' state.

Any further insights on above?
(eg - How on earth are spikes >3x larger than Vcc occurring?? Is it worthwhile sweating to eliminate the 1V ptp low frequency interference on Vin? Any further insights on use of Watchdog Timer? etc)

Its actually raw LEDs - two 10W LEDs wired in parallel.

  • Indeed interference on Vin pin due to LED current switching
  • Occurs both on a 500Hz/1V ptp basis (mirroring the LED's pwm switching);

Those 2 things combined suggest to me that maybe the power supply is going into current limit because there are is no current limit to the LEDs. As the LED lamps have no current limit they will draw a lot of current, possibly pushing the PSU into current limit which which would drop the output voltage in the manner you describe. I suggest you put appropriate limiting resistors in series with each LED lamp. Note I do mean in series with each one, you say you have 2 * 10W LED lamps in parallel, this alone is bad because the won't split the current equally between them. Each one should have its own resistor.

PerryBebbington:
Those 2 things combined suggest to me that maybe the power supply is going into current limit because there are is no current limit to the LEDs. As the LED lamps have no current limit they will draw a lot of current, possibly pushing the PSU into current limit which which would drop the output voltage in the manner you describe. I suggest you put appropriate limiting resistors in series with each LED lamp. Note I do mean in series with each one, you say you have 2 * 10W LED lamps in parallel, this alone is bad because the won't split the current equally between them. Each one should have its own resistor.

Thanks PerryBebbington!!
Interesting, but I doubt it: The PSUs are rated 30Amps, each of them supplies 16 units. Now, I've measured the LEDs current draw when On, and it matches the theoretical (at 20W) number of 1.6 to 1.8 Amps. If lit all together, the combined 16 units approaches the 30A limit - but they almost never light up together. And, I can observe the low & high frequency noises on Vin when only ONE is operating ... Doesnt that suggest it is not a PSU current limit?

Personally i’ve never had any issues running raw leds in certain situations like when hooked up to a solid DC source like a battery. AC/DC supplies usually have some type of noise in the conversion process since they do it on the fly… but i wouldn’t think it would be enough to effect your setup, but who knows.

But while resistors aren’t always necessary with LEDs, it’s usually best to use them as a safety precaution. all you would need is a voltage spike of a couple volts, and POP, they’re done.

Are your LED’s a single 10W LED? or are they like a 10W consolidated LED made up of multiple smaller LED’s that equal 10W?

The IRF520 is indeed the wrong choice of MOSFET. IRL520 or IRL540 will work much better for that part.

Then the LEDs: you need current limiting, and for these high power LEDs the best way is some kind of constant current source. If you get an LED bulb (they should exist in 20W) such circuits are built in already. The switching frequency of that circuit should be much higher than your typical 500 Hz PWM allowing dimming, but you have to test this.

I don't know, well, obviously the PSU won't be going into current limit based on what you have said. I am still very concerned about the lack of current limit resistors and, as jremington points out, the IRF520 is not a logic level MOSFET. In my general experience, when you discover something about what you are doing is wrong you fix that first regardless of whether you think it could be the cause of you main problem. In this case that mean swapping the FETs for logic level FETs and putting a resistor in series with each LED lamp. Do that, see if it helps, if not make more tests and come back for advice.

Maybe that MOSFET happens to provide the needed resistance - by not opening up properly.

It's got to be getting pretty hot!

Maybe that MOSFET happens to provide the needed resistance - by not opening up properly.

It's got to be getting pretty hot!

At this point that's sounding like the best hypothesis...

It wouldn't hurt to measure the voltage-drop across the MOSFET.

I don't have much experience with MOSFETs but apparently MOSFETs can suffer from [u]thermal runaway[/u] and that might cause it to temporarily latch-on.

I've seen regular transistors (BJTs) short-out ("latch-on") permanently but I've never seen temporary thermal-runaway where the transistor latches-on and then recovers when "reset".

But if you switch to a proper logic-level MOSFET, the next problem is... What happens when there's no current limiting? Does the new MOSFET burn-up? Does the LED burn-up? Do you get away with it?

and putting a resistor in series with each LED lamp

A couple of issues -

You need to allow for the voltage drop across the resistor. If there's more voltage drop than you're getting across the "wrong" MOSFET, the LED will be dimmer and possibly noticeably dimmer. For example, with "regular LEDs" we usually have 3V across the resistor and 2V across the LED. That gives you pretty-good current regulation. The higher percentage of the voltage that's dropped across the resistor, the closer you get to a constant-current source. If you only drop a volt or two across the resistor with 10 or 11V across the LED you don't have very good current control/regulation (although it's better than nothing).

And with high-power LEDs you have to consider the power dissipated by the resistor. For example, if you switch to a 24V power supply and drop about half the voltage across the resistor (like with a regular-little LED) the resistor has to dissipate the same power as the LED. With 10W LEDs you'd need 10W (or more) resistors, and you have a less-efficient design with half the power just heating-up resistors. It should be more efficient than an incandescent lamp but current-limiting resistors with high-power LEDs is still an "amateur design".