# Alternating LEDs through n-MOSFETs

I'm poking around different LED drivers, and one of the things I'm trying to put together is a PWM-driven dimmer circuit that alternates two LEDs off a single PWM wave. I put together a version of this circuit:

with an Arduino providing the V2 PWM signal. My understanding of this circuit is:

When V2 is at 0, R3 pulls the gate of M2 down, turning it off. R2 pulls the gate of M4 up, turning it on, which should light D1. When V2 goes high, that turns M2 on, which pulls the gate of M4 low, turning D2 on and D1 off.

What actually happens is that D1 turns on and stays on. What am I missing?

EDIT

I updated the schematic as recommended:

simulate this circuit – Schematic created using CircuitLab

(note the corrected mosfet part number - FQP30N6L)

It works... somewhat. What I'm seeing now is that when V1 is at about 5V, the behavior is as expected - steady current consumption from my benchtop PSU, and alternating LEDs. When V1 gets to 9V (which is where it's supposed to be), D1 gets stuck on, and that's it. I assume the issue is with the properties of the mosfet I'm using, but I'm not sure where to look.

• why did you include a screenshot instead of the circuit lab schematic itself? – jsotola Dec 21 '17 at 5:54
• leave out R2 and put D1 on high side of M4 – jsotola Dec 21 '17 at 5:58
• @jsotola because I drew the schematic before getting stuck, and there's no way that I can find to embed an existing schematic. – kolosy Dec 21 '17 at 6:01
• When you use the CircuitLab button on the editor toolbar the editable schematics are can be saved inline using the "Save and Insert" button. – Transistor Dec 21 '17 at 7:01
• What they said. But it translates to: Move D1 to M4 drain. | Add series resistors for D1 and D2 (R ~= 7000 / mA or say 680 Ohm for 10 mA. | Remove R2. | IRF520 datasheet - Vgsmax is 20V so OK with 9V swing. |Vgs threshold is 4V max so available swing OK. – Russell McMahon Dec 21 '17 at 11:19

You should not have the load in the source side of an N-MOSFET transistor switch like that. Especially not a diode.

Even if it were simply a resistor, the act of turning on the MOSFET would change the Vgs voltage and tend to pinch it back of or into a current regulating type characteristic.

With a diode, once the capacitance Cgs is charged up, there is no way for it to discharge, and the MOSFET will just stay on.

Your schematic should be more like this.

simulate this circuit – Schematic created using CircuitLab

• "never" is wrong, there are some cases where you might want to make a source follower, but this isn't one of them. – immibis Dec 22 '17 at 4:58
• @immibis ya never may be a bit strong. hence the "switch like that" part. – Trevor_G Dec 22 '17 at 13:59

When V2 goes high it turns M2 on.Then drain of M2 becomes ground and 9v actually divide across R2 and R1,so gate of M4 is now 4.5 volt which is greater than threshold voltage.so M4 turns on and D1 glows.To solve try a voltage divider like R1=220,R2=22k.

• Thanks. However, removing R1 entirely doesn't seem to help. Any other ideas? – kolosy Dec 21 '17 at 5:53

I will not explain why D1 is always on because Zarzisur has explained it very well.

In addition to his/her answer, if you want to alternate between the two LEDs then you need two cascade-connedted NOT-gates. Thus, D1 should be the the load of M4 and there's no need to keep R2 there.

Notet that you should also put series resistor to LEDs so that 9V supply do not harm them.

If the forward voltages (Vf) of the two LEDs are similar (less than 0.4 V difference), then there is another way that uses only one transistor, one resistor, and one small diode. This works well for standard 3 mm and 5 mm red and green LEDs, such as getting a dual-color LED on an instrument front panel to be red, green, or pseudo-yellow with only one control wire from the system.

simulate this circuit – Schematic created using CircuitLab

Due to the added voltage drop of D3, D1 "shorts out" D2/D3 when M1 is on. (First time using the editor, don't know why the image is so large.)

• Put some useless bit of wire in the far right of the schematic. It maxes the width of the schematic to just barely include everything. Edited it as an example. – Spehro Pefhany Dec 22 '17 at 14:04
• Thanks for the tip. This isn't my first cad system, so I understand lying to an auto-sizing "feature". Is there a way to force a specific output size manually, without the flying net? – AnalogKid Dec 22 '17 at 14:20
• There's no guarantee that the LEDs are the same. At least the OP has not mentioned it. If LEDs are the same then okay, the circuit will work as you think; but if $V_{F-D1}$ is greater than $V_{F-D2} + V_{F-D3}$ (e.g. if D1 is blue [3.2V] and D2 is red [2V]) then it will not. I'll cancel my down-vote if the OP says that the LEDs are the same. – Rohat Kılıç Dec 22 '17 at 14:38
• @AnalogKid Not that I know of, but wouldn't mind being shown to be wrong. – Spehro Pefhany Dec 22 '17 at 14:40
• @SpehroPefhany: You can use the imgur 'l', 'm' and 's' (large, medium, small) prefixes to the '.png' in the schematic name to resize the images. I put a little green 't' on the bottom right of mine though to scale them properly. It helps me recognise them when I go back through old questions! The prefixes work for .jpg too. – Transistor Dec 22 '17 at 18:40