The function of R1 is to protect the LED in the optocoupler. Like R5, R1 also limits the current, so that a ‘hard’ voltage can be applied safely. Optocoupler, the CNY65, provides class-II isolation. (Class-II or double insulated electrical appliance is the one which has been designed in such a way that it does not require a safety connection to electrical earth). This is good enough to ensure safety to the regulator.
Now we need the conduction in the MOSFET as quickly as possible. For this, we connect the transistor in the optocoupler to the positive power supply. We have to make a compromise between the switching loss and the inductive voltages as we keep the rating of R2 a bit high, i.e., 22 K-ohm. This is done so as to reduce the switching spikes as a consequence of parasitic inductances.
One additional advantage of the MOSFET is that it helps in the conduction. It conducts for a longer duration than a PWM would do single headedly. Now some interesting information is that when the voltage across the MOSFET reduces, the voltage across D1 remains equal to 10V upon a duty cycle of 88%.
A duty cycle is the percentage of one period up to which a signal is active. A period is the time it takes to complete an on-and-off cycle. The expression for the duty cycle is:
D = (T/P)*100%
Where, D is the duty cycle
T is the time the signal is active
P is the total period of the signal.
A higher duty cycle results in lowering of the voltage. For an instance, at 94% duty cycle, the voltage of 4.8A proved to be just enough to cause the MOSFET to conduct sufficiently. This value is therefore considered as the maximum duty cycle. Also, at this value, the transistor conducts just about cent percent. Measuring with a 100W bulb, the voltage across a 230V mains supply is just 2.5V lower.
Note: We should note that this circuit should not be used to control inductive loads. MOSFET is switched asynchronously and this can cause the DC current to flow.
Now some tips regarding the whole arduino project. Starting off with, we must know that the electronic lamps, such as the PL types, cannot be dimmed with this circuit. This is because these lamps use a rectifier and internally they operate off DC. A few remarks about the value of R3 and R4. This is a compromise between the lowest possible current we consume (when the lamp is off) and the highest possible duty cycle that is allowed. Now as mentioned earlier, the more the duty cycle the less is the voltage. So, we look at a case where the duty cycle is 0%. This results in maximum voltage across the resistors, around 128V across a supply of 230V. Because (depending on the actual resistor) the voltage rating of the resistor may be less than 300 V, two resistors are connected in series. The power that each resistor dissipates amounts to a maximum of 0.5 W. With an eye on the life expectancy, it would be wise to use two 1-W rated resistors here.