I have LED lamps that I tried to dim it through WiFi using an esp8826 with this circuit:

dimming circuit

The LED lamp draws 450mA at 40V.

My problem is that it can turn the led on and off, but when I try to dim it, the light starts flickering a 1-2 times a second.

So the next thing I tried is to use a single chunk of a 12V LED strip with 3 leds on it, and I measured the voltage between the drain and the 12V rail. I noticed that the square wave is fine when it is fully on, but when I reduce the duty cycle to around 80%, there is a huge negative spike when turning the mosfet off, and it cannot fully turn it off. The problem seemed to be solved when I put a 10K resistor between the drain and the source, but then it could not be fully powered off of course.

The scope showed something really interesting when the pwm is fully off. It started to have very huge voltage oscillation, that seemed to me like picking up noise from the mains voltage as it had a frequency of 50 Hz. Then I turned it back on, and I noticed that when I lower the duty cicle, the negative voltage spikes when turning off the gate are actually oscillating with this same frequency.

I started thinking that I may have picked the wrong BJTs for driving this mosfet, but I have no idea what parts should I use if not this. I had 2n2222s already, and I chose the PNP by comparing it to the 2n2222.

I tried to research mosfet driving topics, but I could not find any solution. Could you help me understand what am I not seeing? Thank you!


I have tried the following modifications according to the answers. I tried different resistor values before the gate from 100 ohm up to 1 kOhm, it did not change the situation at all.

This still picks up a huge negative spike that seems to be mains voltage noise.



2 Answers 2


The gate-source capacitance \$C_{GS}\$ of the MOSFET is resonating with the source inductance. Whether switching on or off there is no series resistance to damp the oscillations. Put a resistor in series with the gate of the MOSFET. Start with 10 ohms. If there is still ringing voltage then increase it until it stops.

Put bypass capacitors from all the supply connections to ground. For the 40V use 100 uF or greater in parallel with a 100nF ceramic. Place close to the LEDs For the 2N2222 collector use at least a 100nF ceramic capacitor. Place close to the 2N2222.

  • \$\begingroup\$ Thank you for your answer! I have tried the corrections you suggested, and edited the question according to it. I have also replaced the PNP and the mosfet, and triple checked my circuit to make sure that I actually made the circuit that I have drawn with no luck. \$\endgroup\$
    – tvili999
    Dec 3, 2022 at 12:52
  • \$\begingroup\$ The complement to the 2N2222 is the 2N2907. These should be ok. \$\endgroup\$
    – RussellH
    Dec 3, 2022 at 18:49
  • \$\begingroup\$ The problem is elsewhere. Does the spike go negative or just to zero? \$\endgroup\$
    – RussellH
    Dec 3, 2022 at 18:51
  • \$\begingroup\$ It goes negative by a lot, so many that my cheapish scope shows overvoltage(or under?) that is -50 V. First I thought that maybe something has a big inductance, but this effect is present even with that piece of LED strip at 12V. I will try to take a shot of it but it is hard to show because the spike is not constant, it changes seemingly with the frequency of the mains voltage. \$\endgroup\$
    – tvili999
    Dec 3, 2022 at 21:05

It turned out that the pull down resistor was missing from the transistor that pulls down the two transistors. I added one and it all seemed to be solved, it did not pick up the noise.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.