I have a product with a non isolated power supply which has 220 VAC live line as the GND reference:
My MCU receives 3.3 VDC from the same circuit.
I want to detect the presence of 220 VAC (same phase which powers up the device) using GPIO. (you might be wondering why bother because device will switch off if the 220 VAC is not present. However this is not the case. Phase is same but power line is connected directly to the 220 VAC live line and the GPIO sensing is required on a switch. When switch is closed, I will get 220 VAC, if switch is open, I will get nothing. This is what I intend to sense using GPIO.)
This is what I am planning to do:
There are two ways to do this:
1) Opto coupler way where I use an intermediate opto coupler to protect my GPIO as shown below:
2) Direct connection to GPIO as shown below:
I want to use the second circuit because of these reasons:
1) Cost is lower
3) First circuit is voltage dependent. If I am designing for 220 VAC and line voltage drops down to 110 VAC, the circuit won't work because optocoupler will not turn ON. If I design for 110 VAC and use it in 220 VAC, it will get damaged due to excessive heating/current.
My questions are as follows:
1) Since I am using non-isolated power supply circuit, does it even make sense to use opto couplers?
2) Since my GND is referenced to 220 VAC, do I need to bother about voltage spikes on phase line?
3) What protection should I put in place for my IO lines against voltage spikes (if it's a concern)?