Controlling 2 Relays Based on Input of 2 Current Sensors

Hello,
With a Nano I am trying to control two separate pumps, each with a relay and current sensor monitoring each, to prevent both pumps running at the same time. I did a breadboard replacing the pump with a LED and current sensors with NC push buttons and everything worked as expected but once I actually wire everything both relays are turning on at the same time. Only difference with the breadboard is I didn't have the 10 second delay; this is to allow the pump enough time to run.

I checked there aren't any shorts between the relay outputs and the sensor inputs at the Nano. I also removed the senors and shorted the wires manually, like a push button, but still the same issue.

This is my first real project and hoping it's something simple I am missing with the code that you can help fix. Really appreciate you taking a look.

Schematic below also.

Edit: Schematic re-uploaded with legend for R1, R2, S1, S1; added O1, O2, 110V AC label for COM into Relays, labeled Nano.
Currently I have the Arduino connected to a PC via USB.
Current Sensor/Switch NO: https://www.amazon.com/gp/product/B07N1P6TWL/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
Relays are single channel: https://www.amazon.com/gp/product/B09G6H7JDT/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

/*
Sense current at two different outlets and control with 
relays to avoid both outlets being on at the same time.

Hardware is 2 current sensing relays and two power relays.
Both current sense relays are NO.  Power relays are connected NC 
and configured for a HIGH trigger.
*/

//Constants

const int currentsense1 = 2; // @ pump1
const int currentsense2 = 3; // @ pump2
int relay1 = 13; // @ pump2
int relay2 = 12; // @ pump1


void setup() 
{
  // Set the sensing relays to be inputs
  pinMode (currentsense1, INPUT_PULLUP);
  pinMode (currentsense2, INPUT_PULLUP);
  
  // Set the power relays to be outputs
  pinMode (relay1, OUTPUT);
  pinMode (relay2, OUTPUT);

}

void loop() {
  // read the state of currentsense1, currentsense2, relay1, relay2
  int senseState1 = digitalRead(currentsense1);
  int senseState2 = digitalRead(currentsense2);
  int relayState1 = digitalRead(relay1);
  int relayState2 = digitalRead(relay2);
 
  //State pulled HIGH with internal PULLUP, current sense will pull it LOW.
  if (digitalRead(currentsense1) == LOW)
  {
    digitalWrite(relay1, HIGH); // Open relay1
    delay(10000);
  } 
  else
  {
    digitalWrite(relay1, LOW); // Close relay1

  }
  
  delay(500);
  
  if (digitalRead(currentsense2) == LOW)
  {
    digitalWrite(relay2, HIGH); // Open relay2
    delay(10000);
  }
  else
  {
  digitalWrite(relay2, LOW);  // Close relay2
  }
  delay(500);

}

  • You need to label the blocks in schematics.

  • Leaving signal nets hanging in mid air does not tell us how you have things connected.

  • If that's an Arduino, where is it's GND connection ?

  • Supply us with the the data sheet for the current sensors.

  • Always give us links to the components that are in your projects. example, the modules that are connected tot he Arduino.

2 Likes
  1. coils need burden resistor and offset voltage

  2. Arduino and relay module connecting 5V. if module can be triggered by HIGH level, then GND is shared.

Thanks for the prompt responses. The controlled side of the relay is 110V AC common with the NC output connected to a standard 15 amp wall outlet.
Currently the Arduino is connected to a PC by USB and the 5V supply to the relays is separate.
@kolaha I added an amazon link to the current sensing switch. I get the need for the burden resistor if there's an input voltage but since this is NO and then goes low to ground is that still needed?
Could not having a common ground cause issues?

if you have such device you need no arduino .
are you maybe have NC version?
grafik

look this over

  • i see no need for delays. more sophisticated logic is needed if you only want the pump to run for a specific time and ignore the current sensor adter that period
  • only need to check the 2nd pump if the 1st current sensor is not active, but need to make sure the 2nd pump off when turning the 1st one on
const int currentsense1 = 2; // @ pump1
const int currentsense2 = 3; // @ pump2
int relay1 = 13; // @ pump2
int relay2 = 12; // @ pump1

enum { Off = LOW, On = HIGH };

void loop()
{
    //State pulled HIGH with internal PULLUP, current sense will pull it LOW.
    if (digitalRead(currentsense1) == LOW) {
        digitalWrite(relay1, On);   // close, relay1 on
        digitalWrite(relay2, Off);  // open relay2
    }
    else {
        digitalWrite(relay1, Off); // open, relay1 off

        if (digitalRead(currentsense2) == LOW)
            digitalWrite(relay2, On);   // close relay2
        else
            digitalWrite(relay2, Off);  // open relay2
    }
}

void setup()
{
    // Set the sensing relays to be inputs
    pinMode (currentsense1, INPUT_PULLUP);
    pinMode (currentsense2, INPUT_PULLUP);

    // Set the power relays to be outputs
    pinMode (relay1, OUTPUT);
    pinMode (relay2, OUTPUT);
}

Yes, it won't work.
You need to connect the Arduino GND to the Blk wire in your schematic

The switch;
image
Doesn't need a resistor.

Tom.. :smiley: :+1: :coffee: :australia:

because it is not a coil, that is why i wrote after:

Thank you everyone for the prompt help. Not having the Nano GND common with the relays was the problem.
@jim-p Pretty frustrated with myself for overlooking that.
@gcjr Thank you for the revised code; much cleaner and the delays aren't necessary.
@kolaha I did try just connecting the current sense relay directly as you sketched it but the relay has a max of 0.5 amps. So I fried that one during initial tests with a light bulb.

Last question is can I use the 5V pin on the Nano for input power or is that only an output? I have found mixed answers.

if USB connected 5V is output for small needs.
when no other power connected 5V is input
but as i said you need no arduino, even if you have only NO sense switches. use relay. should i draw diagram for you?

Understood on the 5V pin.
I think I follow on not needing an arduino. I just need the 5V supply, relays and current sense relays. I need to switch the relay from a HIGH to a LOW trigger. Schematic below.

yes

1 Like

Thank you.

confused by your schematic which suggests that each pump depends on the other pump being on. Both need to be on. Not sure how either could be on from a starting state of both being off

thought you wanted to prevent both pumps being on.

outside the above confusion, what might trigger either pump being on? assumed that would also be controlled by the Nano

I should have just stated outlets because that is what is what I need to control. Each outlet has a pump plugged into it, and each pump has a float switch to turn it on/off.

If I connect the relays as NC and the sensing relay is NO then for example if outlet 1 has a power draw, that would close the sensing relay there, switching the relay2 at outlet 2 OPEN. When the power draw ends on outlet 1, the sensing relay would open and relay2 at outlet 2 would close. I am going to keep this as a backup since the nano is already wired in but will breadboard the concept.

the NC and NO pins of the relay don't control the relay, they are the contacts of the relay controlled by the coil.

when there is no power to the coil, the NO contact is connected to the Common and when the coil is powered, the relay closes, the NO contact is disconnected from Common and NC is connected to Common. (hence it's name)

"sensing relay"? I thought you have a "current sensor" that is connected to a relay to turn it on when there is current through the current sensor?

i don't understand why you have your current sensors controlling the other relay.

ok, now i kinda understand.

and i'm wrong that the NC contact is conected to Common when the relay is closed.

because the outlet is connected to NC contact, a pump will get power as long as the relay is unpowered, open.

And since current to on outlet "opens" the relay for the other outlet, only one outlet can be powered at a time.

guess it doesn't matter how a pump is otherwise turned on

Correct. I plan to us the relay NC connected to AC Common so that the outlet is powered as long as the relay is open. That way if anything fails (open), the outlet would still be powered.

so why do you need an Arduino ????