Relay module boards causing reset

I'm using an arduino nano with 5 relay outputs and 3 analog inputs. The code is a sequencer that is initiated with a button input. If the analog inputs are disconnected, everything works fine, but if they are connected, then when the relays deactivate, the arduino resets.

I have attached a wiring diagram. I have separate power supplies for the Arduino and the relay boards.

I have also attached pictures of the wiring... kind of a mess right now because I have been trying to diagnose this issue.

Here are the components:
4 Channel Relay Board

2 Channel Relay Board

Current Sensor

Here is the code:

#define RELAY_ON LOW
#define RELAY_OFF HIGH
#define button_ON LOW
#define button_OFF HIGH

//Input Variables
const int buttonPin = 3;
const int pressureSensorPin = A5;
const int torqueSensorLeftPin = A1;
const int torqueSensorRightPin = A2;

//Output Variables
const int motorRelayLeftPin = 9;
const int motorRelayRightPin = 8;
const int actuatorPin = 7;
const int pumpPin = 5;
const int valvePin = 4;

int seqStep = 0;

void setup() {
  pinMode (buttonPin, INPUT_PULLUP);
  pinMode (motorRelayLeftPin, OUTPUT);
  pinMode (motorRelayRightPin, OUTPUT);
  pinMode (actuatorPin, OUTPUT);
  pinMode (pumpPin, OUTPUT);
  pinMode (valvePin, OUTPUT);
  digitalWrite(pumpPin, RELAY_OFF);
  digitalWrite(valvePin, RELAY_OFF);
  digitalWrite(motorRelayLeftPin, RELAY_OFF);
  digitalWrite(motorRelayRightPin, RELAY_OFF);
  digitalWrite(actuatorPin, RELAY_OFF);

}

void loop() {
  int seqTime = 2000;
  int buttonState = digitalRead(buttonPin);
  
switch (seqStep)
  {
    case 0:       //Start sequence on button push
  
      if (buttonState == button_ON)
      {

        seqStep = 1;
        
      }
      break;

    case 1:
      digitalWrite(pumpPin, RELAY_OFF);
      digitalWrite(valvePin, RELAY_OFF);
      digitalWrite(motorRelayLeftPin, RELAY_ON);
      digitalWrite(motorRelayRightPin, RELAY_OFF);
      digitalWrite(actuatorPin, RELAY_OFF);
      delay (seqTime);
      seqStep = 2;
      
      break;

    case 2:
      digitalWrite(pumpPin, RELAY_OFF);
      digitalWrite(valvePin, RELAY_OFF);
      digitalWrite(motorRelayLeftPin, RELAY_OFF);
      digitalWrite(motorRelayRightPin, RELAY_ON);
      digitalWrite(actuatorPin, RELAY_OFF);
      delay (seqTime);
      seqStep = 3;

      break;

    case 3:
      digitalWrite(pumpPin, RELAY_OFF);
      digitalWrite(valvePin, RELAY_OFF);
      digitalWrite(motorRelayLeftPin, RELAY_OFF);
      digitalWrite(motorRelayRightPin, RELAY_OFF);
      digitalWrite(actuatorPin, RELAY_ON);
      delay (seqTime);
      seqStep = 4;
      break;

    case 4:
      digitalWrite(pumpPin, RELAY_ON);
      digitalWrite(valvePin, RELAY_OFF);
      digitalWrite(motorRelayLeftPin, RELAY_OFF);
      digitalWrite(motorRelayRightPin, RELAY_OFF);
      digitalWrite(actuatorPin, RELAY_OFF);
      delay (seqTime);
      seqStep = 5;
      break;

    case 5:
      digitalWrite(pumpPin, RELAY_OFF);
      digitalWrite(motorRelayLeftPin, RELAY_OFF);
      digitalWrite(motorRelayRightPin, RELAY_OFF);
      digitalWrite(actuatorPin, RELAY_OFF);
      digitalWrite(valvePin, RELAY_ON);
      delay (seqTime);
      seqStep = 6;
      break;
    
    case 6:
      digitalWrite(pumpPin, RELAY_OFF);
      digitalWrite(valvePin, RELAY_OFF);
      digitalWrite(motorRelayLeftPin, RELAY_OFF);
      digitalWrite(motorRelayRightPin, RELAY_OFF);
      digitalWrite(actuatorPin, RELAY_OFF);
      seqStep = 0;
   
      break;

    default:
      //something went wrong
      break;
  }


}

I'm not an electrical engineer... I'm wondering if there is EMF causing interference? Things too close?

Your wiring needs to be rerouted.

Keep all load wires away from your Arduino wires, ideally at a 90° angle.

All on/off inductive loads should have kickback diodes.

How does the Vac sensor work?

Cross posting just p*sses people off, don’t do it any more.

The vac sensor is powered by 24 VDC and outputs 0-5 volts.

I tried moving things around... unmounting the two black relays and holding them ~6 inches away from the board... unmounting the arduino and holding it away... disconnecting 24 V lines one at a time.

The only thing that makes a difference is if any of the analog input lines are connected... it doesn't matter which one

Hi,
How do you know the Nano reset?
Have you got the gnd of the relay module connected to the gnd of the Nano.

Also join the two gnd terminals on the current sensors.

Tom... :slight_smile:

Gnd relay modules to Nano

NO, that disables the isolation provided by the opto-couplers.
Post a link to that current sensor and vac sensor, wiring don't look right to me.
You need a connection from 24V - to Nano GND, you have no signal return path.
Also you should have a 24 ~ 27k resistor between those 24V sensors and the Nano input pins, a failure in one of the modules could allow 24V to be applied to an input pin, disastrous.

Hi,
Can I suggest you do a complete rewire, taking into account.
Keep all 24V switched and power wires together and keep them away from any input to the relays and the wiring between them and the Nano.
Keep all wiring between the relays and the Nano together.
Keep all wiring between the sensors and the Nano away from other wiring.

The relays circled in red and blue, turn them 180degrees, so their 24V wiring does not crossover input wiring as in the red circle, and away from the Nano in the blue circle.


How have you got the Nano terminal board fixed the the cabinet backplane?

Thanks.. Tom.. :slight_smile:

Outsider, Here are the sensors:
Current Sensor

Vacuum Sensor

TomGeorge, I think you may be right... I was hoping not to have to rewire everything, but that may be what I need to do... The only thing I don't understand is why it works when the analog signals are disconnected. Also, I have unscrewed the relays in the red and blue circles and moved them further from the nano board and still had the same issue.

The nano is attached to this screw terminal adapter. Then that terminal adapter is mounted to the aluminum back panel with screws, but held off the back panel with polyurethane tubing as spacers.

why it works when the analog signals are disconnected.

Maybe because noise is coming in on those lines.

May also be wise to add .1uf caps on analog inputs to GND.

Hi,
Do you have a DMM?

If so can you measure the voltage at the analog inputs with respect to the Nano gnd, with the sensors connected and disconnected, please?

Thanks.. Tom.. :slight_smile:

You show the 5 V supply connected to "Vin" of the Nano. That is obviously wrong.

You have not shown the ground wire on the "Vac" sensor. If it must be powered with a 24 V supply, then the Arduino ground must be connected to that 24 V supply negative. So if you are using the same supply as the upper part of your circuit, that means the negatives of both supplies - 5 and 24 v - must be connected together which negates any isolation.

Most important is your wiring "dress". As you illustrate it, it is practically guaranteed not to work in the very manner you describe. This is because switching currents in one part - the relays - are inductively coupled by all those loops of wire from one part of the circuit to another.

When wiring circuits, there must be no such loops. Every supply wire must travel tightly together with its respective ground wire, and every control wire with its ground also - or in the case of the "in" wires from the Nano, those wires must travel bound to the corresponding "Vcc" wire. The relay supply ground as a matter of neatness, should connect to the "GND" pin adjacent to the "JD-VCC" pin, not that - though it is the same connection - next to the "IN" pins.

Yes, this means you will have to re-wire it all properly.

Tom, with the analog disconnected, I am measuring 0.10V with respect to Nano gnd. Connected, I measure 0.00V. When I cycle through, there is a voltage of about 0.07 that will pop up.

Paul, thank you for your advice... I may need a bigger box. Haha.

Hi,

You have some complex issues there... and some good suggestions.

It looks like you do have the relay boards optically isolated.

Paul said

Most important is your wiring "dress". As you illustrate it, it is practically guaranteed not to work in the very manner you describe. This is because switching currents in one part - the relays - are inductively coupled by all those loops of wire from one part of the circuit to another.

and

All on/off inductive loads should have kickback diodes.

Has this been done? There's a lot of energy stored in the motor windings. It WILL go somewhere.

Many industrial systems mount the optically-isolated relays in a separate metal box right next to the motors and grounded to the main device case/enclosure. That might be a major change you would have to do.

Take a look at This Page for overall suggestions on handling all of this.

What is really happening here?
You have lots of wires running around close to each other. Electrical Reality says that you have created lots of Little Resistors in these wires. And you've created lots of Little Capacitors that couple the wires together when the voltage on a wire changes. And you've created lots of Little Transformers that couple the wires together when the current flowing in a wire changes.

Please keep us up to date on what you do and your results; this is an excellent example of the problems in designing equipment like this and later readers will learn from it. (I have this image of lying in bed when they bring in all the Med Students to look at "Your Case"). :slight_smile: but also :frowning:

The 24volt supplies should not have the ground tied to the other supplies. It is a separate circuit. I believe that part is wired correctly. Edit: Looking further at that current sensor it sounds like all the grounds need to be tied together for the current sensor to work properly. I need to find a data sheet on that chip.

The relay modules do have diodes on the coil side. I don't really know if he needs kickback diodes on the motor side of things, but that wiring should be physically separate from the "low power" circuits.

The two five volt supplies should have their grounds connected.

Oh, and as someone else pointed out your five volt supply to the Nano should be connected to the 5 volt pin, not Vin. Vin should be about 7 to 9 volts if you really wanted to use that. I think using the external five volts is a good idea, provided it is well regulated and that the supply is quite close to the Nano. As it is your Nano is actually running on about 4.3 volts and the signals coming from the current sensors could go higher than that and you risk blowing the Nano.

First, move your 5v supply to the 5volt pin (not Vin). Next make sure the two 5volt supplies have their grounds connected together.

Check out this guide: http://henrysbench.capnfatz.com/henrys-bench/arduino-current-measurements/arduino-max471-current-sensor-module-tutorial/

I never heard of this current sensor. I may have to pick one up to play with, could come in handy for something.

Congratulations on providing almost everything needed to understand what you are doing. Pictures, wiring diagram, code, and links to the parts you are using. Your presentation is excellent and is what some others need to learn to do. I know it takes sometime to assemble all that information. Sometimes just pulling all the info together helps you solve the problem yourself.

rjd1234:
The only thing I don't understand is why it works when the analog signals are disconnected.

Specifically because you have the Vac sensor fouled up with the 24 V wiring. That will need to be sorted out.

amdkt7:
The two five volt supplies should have their grounds connected.
...
First, move your 5v supply to the 5volt pin (not Vin). Next make sure the two 5volt supplies have their grounds connected together.

No, that would partially or completely defeat the isolation arrangements. If you want them to have a common ground, then you might just as well use a single supply.

Why else did you say this?

amdkt7:
The 24volt supplies should not have the ground tied to the other supplies. It is a separate circuit.

Yes, the "Vac" sensor is the problem. It is not evident from the negligible data provided on that Aliexpress listing as to what voltage it actually requires to operate, but if you can figure this out, it would be most appropriate to power it from a boost regulator using the same supply as the logic circuits to which it is connected and have no connection at all with the 24 V system.

There in no connection between Arduino GND and 24V ground, the vac sensor's output is referenced against 12V ground, reply #5.

outsider:
There in no connection between Arduino GND and 24V ground, the vac sensor's output is referenced against 12V ground, reply #5.

If your vac sensor is powered by the 24V supply, the output 0-5V is referenced to the 24V supply.
To make it work you need to connect 24V gnd to Arduino gnd, then the 0 -5V will be referenced to the Arduino gnd.
Tom... :slight_smile: