Sketch works until pumps start. Seperate power supply for arduino

I’m using an UNO with a 9V 1A wall wart plugged into the barrel jack. I am powering six 5V optocoupler relays with the 5V and ground from the UNO.

On the NO NC side of the relays, I am using a 12V 5A power supply for peristaltic pumps.

When the pumps are powered up, Mag, StirKalk and Kalk work but the sketch jumps back to the beginning-it won’t dose Kalk 24 times with an hour or so between doses.

When the pumps are not powered up, the sketch runs as it should. I can tell from the lights on the optocoupler relays. The weird thing is, I had the same arrangement and same sketch with smaller peristaltic pumps and a NANO and it worked.

The UNO is very close to one of the pump motors. Could that be the problem?

Also, I have a RTC hooked up because eventually I’ll need to time things accurately when I start dosing food. For now it doesn’t matter.

Any ideas what the problem is?

   unsigned long hoursInMs(int h)  
{  
  return h*3600000UL;         //values will be expressed in hours 
 
}

  long minutesInMs(int m) 
{  return m*60000L;           //values will be expressed in minutes 
 
} 

  long secondsInMs(int s) 
{ return s*1000L;            //values will be expressed in seconds
} 
 
int StirKalk = 5;
int Kalk = 3;
int Mag = 2;   
int futurePump = 4; 
 
 void setup() 
{   
  Serial.begin(115200);
  
  pinMode(StirKalk, INPUT_PULLUP);   
  pinMode(StirKalk, OUTPUT);      
  pinMode(Kalk, INPUT_PULLUP);
  pinMode(Kalk, OUTPUT);      
  pinMode(Mag, INPUT_PULLUP);
  pinMode(Mag, OUTPUT);         
  pinMode(futurePump, INPUT_PULLUP);
  pinMode(futurePump, OUTPUT);  
  
}
  void loop() 
{
   
{ 
  digitalWrite(StirKalk, HIGH);     // turn kalk stirrer off
  digitalWrite(futurePump, HIGH);     // turn future pump off
  digitalWrite(Kalk, HIGH);      // turn kalk dosing pump off
  digitalWrite(Mag, LOW);        // turn mag dosing pump on 
  Serial.println("Mag on");
  delay(secondsInMs(8));             // dose mag   
  digitalWrite(Mag, HIGH);      // turn mag dosing pump off 
  Serial.println("Mag off");
  delay(500);                          //short delay      
} 

  for(int x = 0; x < 24; ++x)    //dose kalk slurry 24 times, then a single dose of mag 
                                 //kalk is dosed every hour while mag is dosed once a day. The exact time of mag dose will drift and that's OK 

{
   
  digitalWrite(StirKalk, LOW);           // turn kalk stirrer on using a NO relay
  Serial.println("start stirring kalk");
  delay(secondsInMs(15));                 // let kalk stirrer run long enough to create kalk slurry    
  digitalWrite(StirKalk, HIGH);         // turn kalk stirrer off
  Serial.println("stop stirring kalk");
  delay(500);                           // short delay
  digitalWrite(Kalk, LOW);              // turn kalk dosing pump on using a second NO relay      
  delay(secondsInMs(4));                // let kalk dosing pump run only briefly to prevent a precipitation event
  digitalWrite(Kalk, HIGH);            // turn kalk dosing pump off 
  delay(500); 
  digitalWrite(StirKalk, LOW);           // turn kalk stirrer on using a NO relay
  Serial.println("start stirring kalk");
  delay(secondsInMs(15));                 // let kalk stirrer run long enough to create kalk slurry    
  digitalWrite(StirKalk, HIGH);         // turn kalk stirrer off
  Serial.println("stop stirring kalk");
  delay(minutesInMs(60));             // wait an hour between doses of kalk

Hi,
This sounds like a classic ElectroMagnetic Interference situation.

See THIS PAGE for help in planning this type of project, grounding, isolation etc.

Your relays are not isolated if running from Arduino 5V. You need a separate 5V 1 Amp or so supply. And you must separate the grounds... See THIS PAGE which shows how to do that.

Let us know how it goes...

Basically two things are needed, as explained on Terry’s page in greater detail.

  1. power the relay COILS with a separate 5volt supply and don’t join grounds, so you have opto isolation.

  2. use diodes across the pumps, to eleminate kickback spikes when the pumps turn off.

Also keep the Arduino<> relay wiring separated from the relay<>pump wiring.
Leo…

Thanks a ton terryking and Wawa!

I wired things up as shown in the second link and it fixed things up right now. I have some 3A diodes to solder across the pump leads.

I really appreciate the help. (:

Just in case this turns out to be a double post my excuse is, I had it typed out but when I hit the like buttons, the text was gone. Similar thing happened on another site and it was a double post. Anyway....THANKS!