AC Wall Switch as GPIO Input

I’ve created a thread in the Arduino forum but I thought I’d post here as well.

I have a wall switch that toggles an AC power socket. I want to send a trigger as a GPIO input when the wall switch is toggled on/off. I’ve used a phone charger and some resistors to bring the 5V down to 3.6V and the “on” is very responsive, but because the 5V converter has capacitors inside, the GPIO stays HIGH for a few seconds after I switch the socket “off”. I’m trying to come up with a way for "on"and “off” to be nearly instantaneous.

You want galvanic isolation here. Trust me, you do. Use an optocoupler. With a pullup on the GPIO side.

Thanks. I’ll give it a shot.

Solution:

The 5V converter was the main cause of the problem; probably too high-quality, actually. I swapped it out for one of those little white cubes like what is commonly used for iPhones. It cuts out as soon as the wall-switch is toggled off. I used a couple of resistors to bring the voltage down to 3V, which is just enough to power my optocoupler. The on/off is perfect now.