I'm working on a project with an end goal of controlling a power outlet with a Java program. Currently, I have the relay wired to outlets, a 3 prong 120 VAC plug, and my Arduino. Everything works as intended: my Java program can trigger the relay/outlets on and off.
The problem:
When I have a load hooked up to the controlled outlets, my Java program will crash after a few cycles of on/off (changes depending on the load plugged in). If I unplug all loads from the outlet- it cycles on/off seemingly forever. How do I change my system so that Java will not crash, irregardless of load? What is causing a difference in the Arduino from a load being connected?
My attempts:
I have tried using an external power source to power the relay and only using the Arduino to pull pins to a common ground. Same result.
I have tried to debug my Java program extensively. The error occurs trying to write data to the serial port. Keep in mind, however, the program will successfully write data a couple times (number depending on the load) before it fails.
I have tried all outlets (both relays) and have had the same results on all.
Additional Information:
A 12 W rated alarm clock causes the error much quicker than a 14 W rated hot glue gun.
Both outlets are GFCIs.
Please let me know if there is any other information that would help solve this problem.
Edit 1: Just realized that I don't have true optical isolation (that I thought I had) because the jumper was left on Vcc and JD-Vcc. I will try later this evening with and external power source to control the coil (JD-Vcc) and the Arduino to control the 'switches' (Vcc). Will report back to share results.
Edit 2: Pulling the coupler and feeding JD-Vcc from a separate power supply (common ground) did not work. I've put 330 Ohm resistors between Arduino pins and relays; didn't solve the problem (might have given me more on/off cycles before failure, but not a fix). Switched the wiring so the outlet is normally off (was my intended configuration). Working on a wiring diagram, brb.
Edit 3: Circuit Diagram. Yes, its ugly. The switches on the Sain Smart are closed when IN1/IN2 are pulled low. And now I see there is a built in schematic function here. Good to know for next time.
Edit 4: I haven't managed to figure out why it is acting like this. Anyone have any ideas? At this point, a work-around may be acceptable. Capacitors, resistors, opto-couplers? What would be best/cheapest?
Edit 5: Would a snubber (Red Lion, SNUB0000) across each outlet be of any benefit? I finally found a related post (#101815, I can't add another link) but am not sure if I can apply any of the potential solutions. Its been recommended putting a small ceramic capacity across the Vin of the Arduino; is putting it between the 5V arduino pin and ground what was meant by this?