Relay trigger interference

Hello all. What is the best way to stop interference. EMI? My nano works great on the bench with power from the USB when I power it from an outlet the relays go haywire. Thanks in advance I am a newbie.

Photo

467B52B3-9F85-4280-9E32-157ECB72D63E.png

467B52B3-9F85-4280-9E32-157ECB72D63E.png

  1. What kind of "outlet" power supply you are using? Looks like you are powering relay module form Arduino. It should be powered directly from power supply.
  2. Use a ferrite beads on arduino powering wires and wires going to relay module,

Looks like you might have this relay module

Are you sure these are 5V relays? (your image is blurry)

If 5V relays, each relay is labeled SRD-5VDC-SL-C (this needs a separate 5V DC power supply)
If 12V relays, each relay is labeled SRD-12VDC-SL-C (this needs a separate 12V DC power supply)

120 volt. I am powering from the Nano as the power supply is 12v. I took the ground directly from power supply. I will switch to a 5v.
They are 5v. I have 5v and 12v relays in single and double.
How many windings on the magnet? Does it matter?
So I will be switching to my 5v supplies and using ferrite.
Thank you so much for your help! I’m will post an update. Really thank you!

For my own learning so a ferrite on the DC powers will do? How why would this work? I’m learning

So the interference is coming from DC power? Causing the nano to fluctuate the voltage on the output pin?
A separate power for relay and nano? Two?
Would you switch to two separate relays?
Thanks again.

Just to be clear, when you get interference, is the relay switching a 120v appliance and otherwise there is no interference ?
Which pins on the Nano are you using for power when the 12 volt supply is connected ?

It is switching a 120v outlet. The interference is always present. I have two of these units running in the same room about 10 feet apart and when one starts switching it causes the other one to switch. Even when just one unit is running alone it randomly switches the relay.
I am using the 5v pin to power the relay. The float switches are connected to pins 4 and 8 and the other wire of the switch is connected to ground with 10k resister. When switch is triggered it sends a signal (after a delay) on pins 6 and 10 to the relay. I cannot write code so I have a buddy who wrote it for me.
Thanks! I ordered ferrite core bead chokes. You all have been a great help. I feel I have to explain why I just don’t google, I am losing my vision and it is very difficult for me to read to much. So I apologize if this looks lazy on my part.

Have you used pullup or pull down resistors on the float pins.
Failure to do this could cause erratic behaviour as you have described.

Can you post your code here ?

I have a resistor on the ground wire of the float switches, is that correct? I will post the code shortly. TY

  • Desc : This sketch oscillates between flipping certain switches on and off
  • at a defined time interval to regulate a control box.
    */

// pin definitions
const int fillSwitchInput = 4; // fill switch input pin (top switch)
const int fillSwitchRelay = 6; // fill switch relay pin (top switch signal)
const int drainSwitchInput = 8; // drain switch input pin (bottom switch)
const int drainSwitchRelay = 10; // drain switch relay pin (bottom switch signal)

// timer thresholds
const unsigned long fillLoopTimeMS = 1800000; // how many milliseconds for fill loop (default 1hr or 3600000)
const unsigned long drainLoopTimeMS = 7200000; // how many milliseconds for drain loop (default 5hr or 18000000)
const unsigned long fillWaitTimeMS = 5000; // how many milliseconds to disable fill switch for when flipped (default 3min or 180000)
const unsigned long drainWaitTimeMS = 20000; // how many milliseconds to disable drain switch for when flipped (default 3min or 180000)

// timer variables
unsigned long prevWait = 0;
unsigned long prevMillis = 0;

// switch states
int fillSwitchState = HIGH;
int drainSwitchState = HIGH;

// overall bucket states
bool waiting = false;
bool filling = true;
bool draining = false;

void setup() {
// fill switch
pinMode(fillSwitchInput, INPUT_PULLUP);
pinMode(fillSwitchRelay, OUTPUT);

// drain switch
pinMode(drainSwitchInput, INPUT_PULLUP);
pinMode(drainSwitchRelay, OUTPUT);

// initial states (fill on, drain off)
digitalWrite(fillSwitchRelay, HIGH);
digitalWrite(drainSwitchRelay, LOW);
}

void loop() {
unsigned long currMillis = millis(); // number of milliseconds since power on

if(filling) {

// if done filling
if(currMillis - prevMillis > fillLoopTimeMS){
prevMillis = currMillis;
filling = false;
draining = true;
digitalWrite(fillSwitchRelay, LOW);
fillSwitchState = LOW;
digitalWrite(drainSwitchRelay, HIGH);
drainSwitchState = LOW;
waiting = false;
return; // done filling so start draining
}

if (!waiting) {
int curFillSwitchState = digitalRead(fillSwitchInput);

if (fillSwitchState == LOW && curFillSwitchState == HIGH) {
digitalWrite(fillSwitchRelay, HIGH);
fillSwitchState = HIGH;
}
else if (fillSwitchState == HIGH && curFillSwitchState == LOW){
// switch was flipped so start waiting
prevWait = currMillis;
fillSwitchState = LOW;
waiting = true;
return;
}
}
else {
if(currMillis - prevWait > fillWaitTimeMS){
digitalWrite(fillSwitchRelay, LOW);
waiting = false;
return;
}
}
}
else if(draining) {

// if done draining
if(currMillis - prevMillis > drainLoopTimeMS){
prevMillis = currMillis;
filling = true;
draining = false;
digitalWrite(drainSwitchRelay, LOW);
drainSwitchState = LOW;
digitalWrite(fillSwitchRelay, HIGH);
fillSwitchState = LOW;
waiting = false;
return; // done draining so start filling
}

if (!waiting) {
int curDrainSwitchState = digitalRead(drainSwitchInput);

if(drainSwitchState == LOW && curDrainSwitchState == HIGH){
digitalWrite(drainSwitchRelay, HIGH);
drainSwitchState = HIGH;
}
else if (drainSwitchState == HIGH && curDrainSwitchState == LOW){
// switch was flipped so start waiting
prevWait = currMillis;
drainSwitchState = LOW;
waiting = true;
return;
}
}
else {
if(currMillis - prevWait > drainWaitTimeMS){
digitalWrite(drainSwitchRelay, LOW);
waiting = false;
return;
}
}
}
}

vender:
I have a resistor on the ground wire of the float switches, is that correct? I will post the code shortly. TY

That doesn't sound right to me because the pullup resistors on pins 4 and 8 have been activated in software so there should not be an external resistor to ground on either of those two pins.

pinMode(fillSwitchInput, INPUT_PULLUP);
. . .
pinMode(drainSwitchInput, INPUT_PULLUP);

Can you also include a wiring diagram / schematic. A picture of a hand drawn one should be OK. Don't bother creating a Fritzing diagram.

I can not thank you enough. None of my friends do electronics and being a hobbyist this has been driving me crazy. This is a drawing of the parts I am going to assemble. Does relays set to HI sound right?

So DO NOT add the resistors?

WIN_20201209_11_17_56_Pro.jpg

WIN_20201209_11_20_28_Pro.jpg

WIN_20201209_11_17_56_Pro.jpg

WIN_20201209_11_20_28_Pro.jpg

OK. The drawing is probably quite good, but the picture is not. What about putting the drawing on the floor and taking a direct picture instead of one at an oblique angle (and in focus would also be good)

Can you provide a link to the relay modules and float valves you are using (ebay supplier web page etc.) ?
It is not yet clear if these are active high or active low.

Sorry I was trying to take a picture with my laptop.

The relays are
R REIFENG 6pcs/lot 1 Channel 12V Relay Module Board Shield with Optocoupler Isolation Support High/Low Level Trigger

and the switches are
Liyafy 5 Pcs Right Angle White Plastic PP Float Switch Fish Tank Liquid Water Level Control Sensor XSL-PH2

From Amazon. It won't let me link. I guess the store is gone??

The relay modules (12 volt) have a yellow jumper which you set to position H for high trigger:

The float switches should be connected between the Arduino pins and ground as you have, but no external resistor should be used to ground.

Can you also make a drawing of just the high voltage (mains) part of the circuit. Include the relay (show their NO, COM and NC terminals) and the duplex power sockets and the mains side of the 12 volt power supply and the mains power to the whole circuit. You appear to be using a NO contact on one relay and an NC contact on the other which seams odd.

What is that 12 volt power supply? Can you show a picture of it ?

Both are NC. Cheap power supply. 11.83v

I've just redrawn your diagram so it is a bit clearer. Do you find any errors ?

  1. That 12 volt power supply appears, from the picture, to have 3 terminals on the low voltage side. Have you worked out what these are all for ?

  2. Does your duplex mains socket separate the Live (Hot) connections for each of the individual sockets ? From your diagram, it appears so.

  3. What length of wires are you using between the Nano and the relays, and from the Nano to the float switches ?

  1. Yes, I have learned to check and recheck parts from China. Seems they are mislabeled a lot.
  2. Yes, duplex outlets have a breakaway tab to separate them. However the appliance that is plugged into the outlet is ungrounded so I did not bother to ground the outlet?
  3. I wanted to put all of this in a small project box. So the trigger wires are 2” and the switch wires are about 18”.
    I am thinking I need to ground the high side? I am just guessing but why wouldn’t I place a ferrite on the trigger wires? I built it and the relays still click like crazy. The environment it is in has a lot of EMI.

Do not make any connections between the low voltage and high voltage side.
Do not ground the +12 volt side.
Try the ferrite beads to see if these help.

Try disconnecting the 2 wires from the Nano that go to the 2 float switches, then experiment with
(a) leaving pins 4 and 8 disconnected
(b) connecting pin 4 to 5V and pin 8 to 5V on the Nano (not Vin !!)
(c) connecting pin 4 to ground and pin 8 to ground.

To see if the chattering relay problem still occurs when the Nano is powered by that 12 volt supply.