Gardenpump problem - problem solved! Sorry - logic mistake: need to use long int or unsigned int

I try to activate a garden-waterpump for a fountain in short intervals, i.e. 10sec ON, 50sec OFF. The code is very simple, and it works on my desktop with a lamp connected - as I want it to.
When installing it in my gardenhouse (dry environment ) it stops working - sometimes right away -sometimes after a while.
I use a standard water pump 220V from "Bauhaus". I tried to connect it through a double relay (for both N and P), and have grounded it as prescribed.
The relay is powered by an external power supply, so there shouldn´t be any galvanic connection between the 220V circuit and the Arduino. (I used a double identical setup - one with an Arduino Nano, the other with an Arduino Uno). Exactly same result...

I guess there must be some kind of an interference from the switching in the relay with the Arduino... Any ideas???

#include <Wire.h>


int relayPin = 6; //pin 6 går til LED som test eller senere til relais vor 220V
int startPin=7;
int stopPin=8;


//indstilling af antal cykler per time - og vandingstid per gang i sec.
int antalCyklerT =600; // number of cycles per hour ... her gives antal perioder som der vandes her time - fra 1-30 per time
int vandingTidSec = 1; //on-time in seconds ... her indstilles hvor mange sekunder pumpen skal køre ad gangen.
int vandingPauseSec = ((3600 / antalCyklerT) - vandingTidSec);//break between ON times (calculated value)

int n=1;

void setup () {

  Serial.begin(9600);
  delay(3000);
  pinMode(relayPin, OUTPUT);
  pinMode(startPin, OUTPUT);
  pinMode(stopPin, OUTPUT);
  Wire.begin();


  Serial.print("Number of cycles: " );
  Serial.print(antalCyklerT);
  Serial.print(" - per hour");
  Serial.println();
  Serial.println();
  Serial.print("ON time in seconds: " );
  Serial.println(vandingTidSec);
  Serial.print("OFF time in secondes: " );
  Serial.println(vandingPauseSec);
  Serial.println();


    digitalWrite(startPin, LOW);
    digitalWrite(stopPin, HIGH);
    digitalWrite(relayPin, HIGH);

n=1;
Serial.print("N:=");
Serial.println(n);
delay(1000);
}

void loop () {
while (n>=1){ //the loop is running indefinitly - for testing purpose

    digitalWrite(relayPin, LOW);
    digitalWrite(startPin, HIGH); 
    digitalWrite(stopPin, LOW);



    delay (vandingTidSec * 1000); //delay for antal sekunder

    digitalWrite(startPin, LOW);
    digitalWrite(stopPin, HIGH);
    digitalWrite(relayPin, HIGH);

 
    
    delay(vandingPauseSec * 1000);
    n=n+1;
    Serial.print("N:=");
    Serial.println(n);
}
  }

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.