I'm looking for a little help because I cant figure out what is going wrong with my build.
Overall:
The project is a IR motion sensor attached to (and powered by) a Raspberry pi 2. When the PIR is triggered it causes an interrupt in a python script which responds by opening a relay and consequently cutting the 110v ac line to the outlet a dehumidifier is attached to.
The Build:
I'm using this PIR: https://www.amazon.com/gp/product/B008A ... UTF8&psc=1
and this relay: https://www.amazon.com/gp/product/B00E0 ... UTF8&psc=1
The main build is a extra deep outlet box. Inside the box is the relay, a 5v power supply scavenged from an old usb charger and an outlet. The 110v ac line enters the box and divides to the 5v power supply and the common pole of the relay. The 110 neutral connects to the outlet and the ground of the 5v power supply. Another line runs from the normally closed pole of the relay to the hot side of the outlet.
The relay is optically isolated: 5v from the usb power supply runs to the ry-vcc of the relay, the jumper is removed and the neutral of the power supply runs to the GND on the same header as the ry-vcc. The relay is triggered by a low on the IN1
The only connections to the Pi is one line from 3.3v to the VCC and one line from a GPIO to IN1.
The problem:
The python script works great as long as there is nothing attached to the load of the outlet. When motion is detected the pi sets the relay GPIO low and the hot line to the outlet is cut. After the delay set by the script the pi sets the GPIO for the relay back high and it re-closes and restores power to the outlet.
The problem is as soon as any load (even my voltmeter) is attached to the outlet. The pi will cut the power just fine. However, the instant (literally no delay at all) it recloses the outlet the pi senses an interrupt on the completely separate pin the PIR is attached to and switches the relay back open.
I cant figure out what is causing a changing load (or any load at all) on an outlet on the other side of an optically isolated relay to cause the Pi to sense an interrupt on a GPIO pin that is in no way associated with the relay. Do I have a bad relay board or bad pi? I'm driving a dehumidifier so there could be some EMI but I thought the opto relay should take care of that. I would think it was a bug in my script except for the fact that it works flawlessly when there is no load on the outlet.
Thanks for any help!