16-way valve with 2x 8-relais module + arduino mega... instable... help needed

I am in the process of creating my automated watering system for my vegetable garden based on a 12V solar panel + batterij.

Idea is that there are 4 'stations' in my vegetable garden. Every station is 16-way valve which, once powered, starts cycling through the valves one by one. Basically turning 1 valve open, waiting for 1 minute, closing the valve and switching to the next one. For this i've created in the past months these 4 boxes. It is made out of a Arduino MEGA, 2x 8-relais module and 16 12V valves. Simple scheme attached.

The code is really simple:

<void loop() {
//Serial.begin(9600);
digitalWrite(poort1, LOW);
delay(time1);
digitalWrite(poort1, HIGH);

delay(1000);
digitalWrite(poort2, LOW);
delay(time2);
digitalWrite(poort2, HIGH);
}>

If i am running the system it is really unstable, randomly resetting after a few relais have been activated. I've tried many things to solve the issue (like adding diodes, snubbers, capacitors, an additional arduino as powersupply for the relais to opto-couple the relais module) but i failed so far. (i am a noob in electronics).
Can someone help me out what is necessary to have a stable system?

If it is difficult to add a separate supply for the arduino, then I would start by re-routing the ground wire from the Relay Module to the battery as shown and also add a ferrite core with at least 5+ turns through the hole.

Note that this scheme does not enable the opto isolation, but it does improve the grounding and dampen any spikes in the ground line. May need to run the +12V wire through the hole (multiple turns) or use a separate ferrite core for this.

Have You tried adding diodes at the valve side, as near the valve as possible?
Relay modules surely have that protection for its own coil but likely not for the relay output because switching AC loads would be impossible.

For testing purposes the Arduino can be powered from USB, separately from the other components.

Whoops ... I just realized that the only power source you're showing to the relay module is the Arduino 5V which is OK for the control logic, but if the part number on the blue relays is SRD-5VDC-SL-C

then you'll need a powerful (separate) 5V battery for the relay modules or you'll need to purchase 12V relay modules that have part number SRD-12VDC-SL-C on the relays. Well, a at least a separate battery will also let you use the opto-isolation feature.

What relay modules do you have?

EDIT: I zoomed in and it appears to be SRD-5VDC-SL-C. If so, this is the main problem because there's no way the Arduino can power these.

Here's a connection diagram I've already had made up to connect the 12V version for opto isolation
p5UBRLY.png

dlloyd:
or you'll need to purchase 12V relay modules that have part number SRD-12VDC-SL-C on the relays. Well,

I've tested a few 5 volt relay modules. The consume like 50 - 150 mA. Buying 12 volt relay modules brings trouble operating them. The 5 volt level from Arduinos is not enough to operate them.
There's no problem powering an Arduino from USB and operate at least 2 modules at the same time.

Thanks for the quick response people! really appreciated. Let me answer all of you one by one:

Quote from: Railroader Fri Mar 19 2021 19:44:38 GMT+0100 (Midden-Europese standaardtijd)

Have You tried adding diodes at the valve side, as near the valve as possible?
Relay modules surely have that protection for its own coil but likely not for the relay output because switching AC loads would be impossible.

I did try putting some diodes on the valves but at these positions.... So not as close to SINGLE valves as possible but basically 2 diodes on all valves at once. This did not seem to make a difference. Would it make a bigger difference to put them really close to every single valve? (this is a challenging option to implement since i am lacking some space in my setup for this

dlloyd:
If it is difficult to add a separate supply for the arduino, then I would start by re-routing the ground wire from the Relay Module to the battery as shown and also add a ferrite core with at least 5+ turns through the hole.

Note that this scheme does not enable the opto isolation, but it does improve the grounding and dampen any spikes in the ground line. May need to run the +12V wire through the hole (multiple turns) or use a separate ferrite core for this.

Great tip of the Ferrite Core! I just bought a few to give it a try. Can you explain in a bit more detail about the +12V through the hole?

Quoting: "2 diodes on all valves at once". That makes no sense. I'm afraid it was not done the right way.
Electronic noise does not care if You space or not. Not negotiable... Follow my suggestion. Do it on. let's say w few valves and only run those valves in the code.
Code..... Is it a secret and You can't post it?

What is the purpose of that toroid looking component in the picture?

dlloyd:
Whoops ... I just realized that the only power source you're showing to the relay module is the Arduino 5V which is OK for the control logic, but if the part number on the blue relays is SRD-5VDC-SL-C

then you'll need a powerful (separate) 5V battery for the relay modules or you'll need to purchase 12V relay modules that have part number SRD-12VDC-SL-C on the relays. Well, a at least a separate battery will also let you use the opto-isolation feature.

What relay modules do you have?

EDIT: I zoomed in and it appears to be SRD-5VDC-SL-C. If so, this is the main problem because there's no way the Arduino can power these.

Here's a connection diagram I've already had made up to connect the 12V version for opto isolation
p5UBRLY.png

I am using a SRD-05VDC-SL-C on these 'stations' right now but i also have a couple of 8-relais modules with JQC3F-12VDC-C lying around. Is there a difference of the SRD-12VDC-SL-C and the one i have lying around? I was already in the proces of rebuilding one station with 12v relais but i was not sure if that would make a difference for my problem. I know with the 5v relais module directly coupled that the relais are able to open en close the valve. (i've tested it running with the water splashing out.) Or do i miss something when you say that the arduino can't power these?
Worth mentioning is that for a long testing period i was running attached setup. Where i did make use of opto-uncoupling, but as a more separated 5volt power source i connected an Arduino UNO to the JC-VCC and GND. I did NOT connect the GND to the main Arduino MEGA. (so in principle i should have connected it correctly). My thought here was that i had no direct powerdrainage from the Arduino MEGA this way hoping that if it was due to a limitation in the amperage that the Arduino MEGA can supply that i would circumvent this. Unfortunately i did not see any major differences. Would you suggest to give the 12V relais boards a try with opto-coupling?

Railroader:
Quoting: "2 diodes on all valves at once". That makes no sense. I'm afraid it was not done the right way.
Electronic noise does not care if You space or not. Not negotiable... Follow my suggestion. Do it on. let's say w few valves and only run those valves in the code.
Code..... Is it a secret and You can't post it?

:wink: totally not a secret but i wanted to spare you some boring code :wink: Anyways... below on your request..
I would say that nothing can go wrong here... :stuck_out_tongue:

#define poort1 30
#define poort2 31
#define poort3 32
#define poort4 33
#define poort5 34
#define poort6 35
#define poort7 36
#define poort8 37
#define poort9 30
#define poort10 31
#define poort11 32
#define poort12 33
#define poort13 34
#define poort14 35
#define poort15 36
#define poort16 37

#define time1 2000
#define time2 2000
#define time3 2000
#define time4 2000
#define time5 2000
#define time6 2000
#define time7 2000
#define time8 2000
#define time9 2000
#define time10 2000
#define time11 2000
#define time12 2000
#define time13 2000
#define time14 2000
#define time15 2000
#define time16 2000

void setup() {
  // put your setup code here, to run once:
  pinMode(poort1, OUTPUT);
  pinMode(poort2, OUTPUT);
  pinMode(poort3, OUTPUT);
  pinMode(poort4, OUTPUT);
  pinMode(poort5, OUTPUT);
  pinMode(poort6, OUTPUT);
  pinMode(poort7, OUTPUT);
  pinMode(poort8, OUTPUT);
  pinMode(poort9, OUTPUT);
  pinMode(poort10, OUTPUT);
  pinMode(poort11, OUTPUT);
  pinMode(poort12, OUTPUT);
  pinMode(poort13, OUTPUT);
  pinMode(poort14, OUTPUT);
  pinMode(poort15, OUTPUT);
  pinMode(poort16, OUTPUT);

  digitalWrite(poort1, HIGH);
  digitalWrite(poort2, HIGH);                                
  digitalWrite(poort3, HIGH);  
  digitalWrite(poort4, HIGH);
  digitalWrite(poort5, HIGH);
  digitalWrite(poort6, HIGH);
  digitalWrite(poort7, HIGH);
  digitalWrite(poort8, HIGH);
  digitalWrite(poort9, HIGH);
  digitalWrite(poort10, HIGH);
  digitalWrite(poort11, HIGH);
  digitalWrite(poort12, HIGH);
  digitalWrite(poort13, HIGH);
  digitalWrite(poort14, HIGH);
  digitalWrite(poort15, HIGH);
  digitalWrite(poort16, HIGH);
}

void loop() {
  //Serial.begin(9600);  
  // put your main code here, to run repeatedly:
  digitalWrite(poort1, LOW);
  delay(time1);
  digitalWrite(poort1, HIGH);

  delay(1000);
  digitalWrite(poort2, LOW);
  delay(time2);
  digitalWrite(poort2, HIGH);

  
  delay(1000);
  digitalWrite(poort3, LOW);
  delay(time3);
  digitalWrite(poort3, HIGH);

  
  delay(1000);
  digitalWrite(poort4, LOW);
  delay(time4);
  digitalWrite(poort4, HIGH);

  
  delay(1000);
  digitalWrite(poort5, LOW);
  delay(time5);
  digitalWrite(poort5, HIGH);

  
  delay(1000);
  digitalWrite(poort6, LOW);
  delay(time6);
  digitalWrite(poort6, HIGH);

  
  delay(1000);
  digitalWrite(poort7, LOW);
  delay(time7);
  digitalWrite(poort7, HIGH);

  
  delay(1000);
  digitalWrite(poort8, LOW);
  delay(time8);
  digitalWrite(poort8, HIGH);

  
  delay(1000);
  digitalWrite(poort9, LOW);
  delay(time9);
  digitalWrite(poort9, HIGH);

  
  delay(1000);
  digitalWrite(poort10, LOW);
  delay(time10);
  digitalWrite(poort10, HIGH);

  
  delay(1000);
  digitalWrite(poort11, LOW);
  delay(time11);
  digitalWrite(poort11, HIGH);

  
  delay(1000);
  digitalWrite(poort12, LOW);
  delay(time12);
  digitalWrite(poort12, HIGH);

  
  delay(1000);
  digitalWrite(poort13, LOW);
  delay(time13);
  digitalWrite(poort13, HIGH);

  
  delay(1000);
  digitalWrite(poort14, LOW);
  delay(time14);
  digitalWrite(poort14, HIGH);

  
  delay(1000);
  digitalWrite(poort15, LOW);
  delay(time15);
  digitalWrite(poort15, HIGH);

  
  delay(1000);
  digitalWrite(poort16, LOW);
  delay(time16);
  digitalWrite(poort16, HIGH);
}

Boring? Never! :wink: Anyway, I managed to find 2 small errors, and I rewrote your code to simplify it just a little bit...

#define time 2000
byte poort[16];

void setup() {
  // Serial.begin(9600);
  for (byte i = 0; i < 8; i++) {
    poort[i] = i + 30;
    poort[i + 8] = i + 30;
  }
  for (byte i = 0; i < 16; i++) {
    digitalWrite(poort[i], HIGH);
    pinMode(poort[i], OUTPUT);
  }
}

void loop() {
  for (byte i = 0; i < 16; i++) {
    digitalWrite(poort[i], LOW);
    delay(time);
    digitalWrite(poort[i], HIGH);
    delay(1000);
  }
}

Question:

#define poort1 30
#define poort9 30

#define poort2 31
#define poort10 31

etc..

Why did you use the same pin numbers (?) for poort1 and 9, poort 2 and 10, etc. ?

Seeing you may have the parts, this might be enough. There's no opto-isolation, but it saves a spare battery as a power source. If the solenoid coils are 1A or less, then the diodes can be 1N4007 or similar. Alternatively, they can be connected Anode to Relay-NO, Cathode to 12V (Relay-COM).

IMPORTANT: The JD-VCC jumper must be removed.


The +12V and GND wires are wrapped separately through the hole of the same ferrite core.

Erik_Baas:
Boring? Never! :wink: Anyway, I managed to find 2 small errors, and I rewrote your code to simplify it just a little bit...

#define time 2000

byte poort[16];

void setup() {
 // Serial.begin(9600);
 for (byte i = 0; i < 8; i++) {
   poort[i] = i + 30;
   poort[i + 8] = i + 30;
 }
 for (byte i = 0; i < 16; i++) {
   digitalWrite(poort[i], HIGH);
   pinMode(poort[i], OUTPUT);
 }
}

void loop() {
 for (byte i = 0; i < 16; i++) {
   digitalWrite(poort[i], LOW);
   delay(time);
   digitalWrite(poort[i], HIGH);
   delay(1000);
 }
}




Question:


#define poort1 30
#define poort9 30

#define poort2 31
#define poort10 31

etc..



Why did you use the same pin numbers (?) for poort1 and 9, poort 2 and 10, etc. ?

Thanks Erik,
Since i was in the testing phase i tried to simplify my setup and therefore i was initially testing on just 1 8-relais module. Therefore the easiest option was to repeat pin 30-37 on the additional pins. Final setup will be pin 30-45
Since your optimizing my code Erik (really appreciated), do you have a suggestion for the following practical problem? I know that if i am running the station with water pressure, the pressure is lower on the physical higher ports and the ports more close to the inled of the station. Also afterwards there is a diverse amount of nozzles attached in series. (ranging from 10 to 20) Because of this i am considering to vary the time of every port to make the amount of watering more optimal. (some of the nozzles water a tree, others just 15 lettuce plants).
Do you have a elegant way to fill the byte[poort] with varying numbers? (ranging from 60 sec to 5 minutes)
BTW, do i have to expect difficulties if i split the 5v exit of arduino mega to 2 8-relais module instead of 1?

Hi,
Can I suggest you change the layout of your project.
At the moment the switched solenoid wiring is over and around the controller.
The signal wiring from the controller to the relay assembly input will have to snake around this wiring.

If you turn the relay assemblies around so their input pins are facing the controller, then the wiring to switch the solenoids will be as far away from the controller as possible, as the signal wires will be as short as possible and away from the solenoid wiring.

Tom... :slight_smile:

TomGeorge:
Hi,
Can I suggest you change the layout of your project.
At the moment the switched solenoid wiring is over and around the controller.
The signal wiring from the controller to the relay assembly input will have to snake around this wiring.

If you turn the relay assemblies around so their input pins are facing the controller, then the wiring to switch the solenoids will be as far away from the controller as possible, as the signal wires will be as short as possible and away from the solenoid wiring.

Tom... :slight_smile:

Thanks for the suggestion Tom! A challenging one :stuck_out_tongue: since i do not have a lot of space to work with but i will take it into consideration for sure! If i put diodes directly over the valves, do you think there is still a lot of inductive current going on that this step is necessary?

Where i did make use of opto-uncoupling, but as a more separated 5volt power source i connected an Arduino UNO to the JC-VCC and GND. I did NOT connect the GND to the main Arduino MEGA. (so in principle i should have connected it correctly). My thought here was that i had no direct powerdrainage from the Arduino MEGA this way hoping that if it was due to a limitation in the amperage that the Arduino MEGA can supply that i would circumvent this. Unfortunately i did not see any major differences. Would you suggest to give the 12V relais boards a try with opto-coupling?

Note that no power signals can cross the opto barrier. That's why the JD-VCC jumper needs to be removed (also to prevent shorting 12V to MEGA 5V). This also means that the Relay Module ground needs to be totally different (isolated) from the MEGA ground. The only way to achieve opto-isolation is by using 2 separate and isolated power supplies.

It might be possible to resolve the problems without opto-isolation ... just improve your system step by step.

EDIT: You'll save the cost of an extra battery ... the isolation you get from the relay coil to contacts should be enough after paying attention to details (adding diodes, star-point wiring for ground, ferrite core, part placement and wiring strategy as per @TomGeorge, etc.

I urge You to install diodes across the valves. I'm sure they are inductive and are causing sparks inside the relay. Sparks also generate Rf that is picked up by the sensitive controller circuitry.

beukwood:
Thanks for the suggestion Tom! A challenging one :stuck_out_tongue: since i do not have a lot of space to work with but i will take it into consideration for sure! If i put diodes directly over the valves, do you think there is still a lot of inductive current going on that this step is necessary?

Just turning the relay PCBs around should not take up extra space and the mounting holes for the PCB should still line up.
Keeping the control wiring away from the switched power wiring is essential and common practice.
Even though you should fit protection diodes, there are still inductive currents and it is theses currents that induce unwanted currents in your control wiring.
Tom... :slight_smile: