Java/Arduino Controlled 120VAC Power Outlet

arduinojavaloadoutletrelay

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.
Circuit Diagram for Problem

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?

Best Answer

That sounds like your Arduino is getting corrupted from noise spikes on switching the AC load on and off. The reason a glue gun affects it less, is that as a pure resistive load, it doesn't generate very much noise, but the alarm clock probably has a switching power supply in it that is dumping higher frequency noise back on the line. Even an older motor driven clock can put spikes back on the line depending on the motor and how it is controlled. Have you tried using an AC filter between the relay(s) and the load (Not a surge suppressor, but an actual LC filter)?

It is also possible, though from the description, unlikely that the relay coils themselves are generating enough of a spike to corrupt your processor. Industrially, for just that reason, we use RC snubber networks across the coils of just about every relay/solenoid driven by an electronic output.

Also the above advice is 100% correct, do NOT switch the neutral of your AC load. Very bad business there from a safety (and at least US Code) standpoint. If the neutral must be switched, to be code compliant, you would need to use special safety relays with force-guided contacts in series.

Related Topic