I'm trying to make a simple circuit that tests if the main house water pump is running. There is a light connected to the main 120v power that turns on whenever the pump is running, so I decided to wire a photoresistor next to the light and then cover the light up with a pill bottle covered in black tape so that whenever the light is on, the photoresistor would trigger the input pin on my ESP8266.
As for the circuit. I have VCC 3.3v (ESP82266 dev board) ---> Photoresistor --- > 2k ohm resistor --- > Ground (ESP8266 dev board). In between the photoresister and the 2k ohm resistor, i have a lead going to input pin 6 of the ESP8266.
This makes it so that when the light turns on, the voltage goes up to 3.27v and when the light is off, it's pulled down to somewhere between 0.0v and 0.20v.
At first I was getting a lot of bouncing. I could see that my MQTT function was sending two or three 'on' and 'off' states each time a switch the power. So i implemented some software debouncing and now it only sends one off and one on per signal.
Everything seems to work ok when I test it with a outlet strip, flipping the power on and off to make the light go on and off and in turn send the "on" and "off" states to my Home Assistant setup. BUT, when I go plug the light back into the pump, it will work sporadically and it will reverse itself randomly and sometimes it will go to ON, but then never turn off.
Also, something else I noticed that was really strange and I hope someone can figure it out. When I open my microwave door in the house, it triggers the ESP input state! I know the house wiring it not the best, but how does this happen and is there a way to fix it? None of this makes much sense to me. Keep in mind, I am not very experienced in this and am just learning.