I have a wall switch that toggles one outlet on an AC receptacle located on one side of the room. i want it to trigger an automation to turn on a lamp on the other side of the room via a 5V DC converter (phone charger) and an ESP32 gpio input.
I've used some resistors to bring the 5V down to around 3.6V and the "on" trigger is very responsive; however, when I flip the wall switch "off" there is about a five-second delay before the gpio input reads low. I presume this is because of capacitors in the 5V converter. I'd like the "on" and "off" to be as responsive as possible.
I know very little about electronic components but I do like to learn, so if you'd like to paste some links, feel free.
I have an optocoupler module that I am thinking of trying next. I don't have any diodes but I suspect they could be part of the optimal solution. I'm hoping some expert advice will steer me in the right direction here.
Power supplies are deliberately and specifically designed not to turn off instantly. The fastest you will get is if you put a load across the power supply equivalent to 80% of its full current rating.
The smallest "night light" you can get with a LDR glued to it might be easiest.
@Paul_B that's a great idea. I have an LED light with an LDR built in. Perhaps I could just take the LDR out, solder a wire in its place, and use it as you suggest.
Regarding a schematic, I have two resistors where the green box is, to bring the voltage down to 3.6V. ...but I'm hoping someone has a better idea that will allow for a more responsive return to LOW for the GPIO when the wall switch is toggled off.
Or, maybe the solution would involve using a floating pin and activating the internal pull-up resistor, then sending a LOW signal when the wall switch is on. Perhaps if a very low voltage transistor were to send a low signal to the pin when powered (and resistors were applied before the transistor accordingly). ...assuming there would be benefit from running such low voltage such that, as the capacitor depletes and the voltage drops below 5V, the volts hitting the transistor would be too little to operate it; thus the pin would float soon after the wall switch is turned off and be pulled back to HIGH.
Again, I'm an absolute noob. I'm just throwing ideas at the wall. So far I think it'll be Paul_B's 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.