The circuit diagram below shows two possible options for a circuit:
The difference between both circuits is the use of the optocoupler, the first one has a common ground between the controller circuit and the mains supply. The second one however has both supplies isolated, they don't share the same ground. Instead they are indirectly connected via an optocoupler. So the question is whether or not is it really necessary to use an optocoupler?
I'm aware that option B is a lot more safer should there be a fault, but that doesn't mean that option A doesn't function correctly, right? The reason I'm asking this is due to the amount of circuits that I've seen that isolate high voltages (such as mains) from controller circuits. I've come to the conclusion that it is just a safety precaution in the event of an accident, such as a live wire touching the controller, albeit not something that is required assuming that everything goes according to plan.