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:
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:
- In one case the LED has been burnt after working for a while;
- 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