Electronic – arduino – Using optocoupler with MOSFET for dimming a LED

arduinodimmingledmosfetopto-isolator

I have a blue LED which I want to dim using an Arduino, an optocoupler and an N-MOSFET.

For achieving this I assembled the circuit on a breadboard as shown in the pictures, using a YwRobot breadboard power supply to provide power to the optocoupler's transistor, and the MOSFET. I used the Fading example sketch from the Arduino IDE.

When I try to dim the LED in this basic configuration: \$(PWM_{out} → Resistor → LED → Ground)\$
The LED slowly lights up, reaches its maximum, then slowly dims, then the cycle repeats as it should in this case.

But in the circuit it behaves weirdly.
It doesn't dim, it's on full brightness, but when the cycle reaches again zero voltage, it's turned off. No sign of any change in the brightness.
I tried modifying the delay of the cycle and I used a multimeter to measure the LED's voltage. As soon as the cycle moved from turned off state \$(0V)\$ to a slightly higher voltage (I used 1 unit increments in analogWrite and 4 second delay) the LED was on full brightness \$(2,8V)\$.

I don't know what's going on. Maybe I don't need one of the resistors on the optocoupler's BJT side? I tried taking the \$R_3\$ resistor out but then the LED was always on, didn't even bother to turn off so I put it back.

Questions:

  • What should I change in the circuit to make the LED dim like in the
    basic configuration?
  • Do I need current limiting resistors for the BJT both on the emitter
    and the collector side \$(R_2, R_4)\$ in this case? I know that in
    the case of FETS, the \$I_D=I_S\$, so one resistor \$(R_6)\$ is
    enough.

Here are the schematic and the Fritzing project:
Arduino_YwRobot_Optocoupler_MOSFET_LED_EAGLE
Arduino_YwRobot_Optocoupler_MOSFET_LED_FRITZING


Datasheets:
4N35M optocoupler datasheet
IRLZ34N n-mosfet datasheet

Best Answer

power mosfets have significant gate capacitance and your gate drive is significantly unbalanced.500 ohms to charge and 600K to discharge that's about 100:1 no wonder the PWM osn't showing results.

replace R3 with 1K replace R2 with a wire, that will give a stronger disharge drive and should work better.