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 () {

  pinMode(relayPin, OUTPUT);
  pinMode(startPin, OUTPUT);
  pinMode(stopPin, OUTPUT);

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

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


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);

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.