Change the Pwm frequency according to delay on time of the mosfet ?

wvmarle:
Where is the resistor in the path 3.3V - optocoupler - optocoupler - GND?

You need 3.3V - optocoupler - resistor - (link to IO pin without resistor) - optocoupler - resistor - GND.

But even when you have that, strange things may still happen when your Arduino switches on with pins in INPUT mode, and both optos are (partly) on.

The schematic on the left is how you should wire the current limiting resistors. The schematic on the right is a vastly improved version, only one optocoupler. Load is off when pin is LOW or INPUT.

This really make sense more then julian's circuit
But why he didn't use them?

septillion:
Why do you need 3,3V when the Mega is going to output 5V anyway?
Yes, but you're not following that circuit, are you?

Than again, it's massively over complicated.

R3 IS the load aka your bulb
Values of R1 and R2 are not strict.
But with a massive down side to it... If the input is floating both opto's are on which turns on both transistors (in the opto) aka shorting the supply through the opto burning the opto / making it nice and toasty.

My arduino works on 3.3v is not 5

Sorry but i didn't understand what it has to do with that circuit you mentioned