Electrical – Raspberry Pi driving a LED through a MOSFET

ledmosfetraspberry pi

I need to control a LED with a Raspberry Pi!

The LED is a white one and it has to be PWM driven, in order to make it show a sort of "breathing effect".

Unfortunately I don't have the LED datasheet so I've empirically (using my bench power supply) found that the LED forward voltage is 3V approx. and that the brightness I want is obtained with 50mA approx.

So I can't drive the LED attaching it directly to a GPIO pin: Raspberry Pi is a 3.3V logic and I've read indeed that a GPIO pin can give a maximum of 16mA to them 🙁
I had to find another way.

I eventually come up with a circuit like the following one:

circuit image

I'm using an IRL540N MOSFET (link) to drive the LED through the Raspberry 5V power supply pin.

The MOSFET gate is attached to the GPIO pin through a resistor to reduce the (theoretically minimal already) current required from the GPIO.

I've also added a pull-down resistor in order for the gate charge to discharge to ground when GPIO is LOW.

Resistor R1 and R2 have respectively 10k and 100k Ohm values (I put them empirically).

I chose a 2.2 Ohm R3 resistor for the LED, this way I've found current values are pretty near to the one I want.

MISURA CORRENI E TENSIONI

Now I have created 4 copies of the circuit mounted on a Raspberry Pi Adafruit Perma-Proto HATs (link).

Now I'm experiencing different behaviours for each of them. While two of them are working the way I wanted to be, the others are not.

Indeed:

  1. In one case the LED has been burnt after working for a while;
  2. The other last one showed a strange flickering pattern (not related to the PWM). It worked like that for a day then stopped working at all.

I'm supposing that in the first case, maybe the current through the LED was much higher than expected (maybe because of resistors, transistors tolerances?)

In the second situation, I'm not able to figure out what the problem can be. It seems a transistor problem but I not sure (I have only a limited knowledge of electronics).

What am I doing wrong?

Has someone already some experience in setups like that?

Any help will be much appreciated

Thanks

Best Answer

So many things wrong.

For one, the led probably isn't suited to 50mA unless it's not a standard 5mm led. Typical led forward current is 20mA. Or even if your type of led is suited to 50mA, it requires heat sinking or you got a counterfeit that won't last at 50mA like a real one.

Second, at a Vf of 3V with an If at 0.05A, and a source voltage of 5V, you have I = (Vs - Vf) / R, or ( 5 - 3 ) / 2.2 = 2 V / 2.2 ohms = 0.9 Amps. Or almost 20 times the current going through that resistor, and such the led.