if continues for 1 minute.

Hello, there is an error in the irrigation system code I wrote. Command running high for 1 minute. Can you help me?
example “if trig == s1” section.

#include <Wire.h>
#include <DS1307.h>
DS1307 clock;
// trigger times
unsigned long x;
unsigned long y;
unsigned long trig;
// grass
unsigned long s1 = 10;
unsigned long s2 = 11;
// tree
unsigned long s3 = 13;
unsigned long s4 = 14;
// night grass
unsigned long a1 = 16;
unsigned long a2 = 17;
// night tree
unsigned long a3 = 19;
unsigned long a4 = 20;

// selenoid controls
const int lw = 7;
const int lend = 6;
const int rw = 5;
const int rend = 4;

// selenoid buttons
const int lsw = 2;
const int lew = 8;
const int rsw = 9;
const int rew = 10;
const int offtime = 13;

//button states
int lwbutton = 0;
int lendbutton = 0;
int rwbutton = 0;
int rendbutton = 0;
int offtimebutton = 0;

//status leds
const int sled = 12;
const int eled = 11;

//bools
bool RightWaterValveOpen = false;
bool LeftWaterValveOpen = false;


void setup() {
  Serial.begin(9600);
  clock.begin();

  // Selenoid Setup
  pinMode(lw, OUTPUT);
  pinMode(lend, OUTPUT);
  pinMode(rw, OUTPUT);
  pinMode(rend, OUTPUT);

  // Selenoid Button Setup
  pinMode(lsw, INPUT);
  pinMode(lew, INPUT);
  pinMode(rsw, INPUT);
  pinMode(rew, INPUT);
  pinMode(offtime, INPUT);

  //failsafe
  rwclose();
  lwclose();
  //status leds
  pinMode(sled, OUTPUT);
  pinMode(eled, OUTPUT);


}

void loop() {
  lwbutton = digitalRead(lsw);
  lendbutton = digitalRead(lew);
  rwbutton = digitalRead(rsw);
  rendbutton = digitalRead(rew);
  offtimebutton = digitalRead(offtime);
  clock.getTime();
  x = (clock.hour) * 60;
  y = (clock.minute) + x;
  trig = y;
  Serial.println(trig);

  if (trig == s1) {
    if (offtimebutton == HIGH) {
      lclose();
    } else {
      lwopen();
    }
  }


  if (trig ==  s2) {
    if (offtimebutton == HIGH) {
      lclose();
    } else {
      lwclose();
      }
  }

  if (trig == a1) {
    if (offtimebutton == HIGH) {
      lclose();
    } else {
      lwopen();
    }
  }
  if (trig == a2) {
    if (offtimebutton == HIGH) {
      lclose();
    } else {
      lwclose();
    }
  }


  if (trig == s3) { //tree
    if (offtimebutton == HIGH) {
      rclose();
    } else {
      rwopen();
    }
  }

  if (trig == s4) {//tree
    if (offtimebutton == HIGH) {
      rclose();
    } else {
      rwclose();
    }
  }

  if (trig == a3) {
    if (offtimebutton == HIGH) {
      rclose();
    } else {
      rwopen();
    }
  }

  if (trig == a4) {
    if (offtimebutton == HIGH) {
      rclose();

    } else {
      rwclose();
    }
  }




  if (lwbutton == HIGH) {
    if (LeftWaterValveOpen) {
      lwclose();
    } else {
      lwopen();
    }
  }

  if (rwbutton == HIGH) {
    if (RightWaterValveOpen) {
      rwclose();
    } else {
      rwopen();
    }
  }
}




void lwopen()
{
  digitalWrite(lend, LOW);
  digitalWrite(lw, HIGH);
  delay(300);
  digitalWrite(lw, LOW);
  LeftWaterValveOpen = true;
}
void lwclose()
{
  digitalWrite(lw, LOW);
  digitalWrite(lend, HIGH);
  delay(350);
  digitalWrite(lend, LOW);
  LeftWaterValveOpen = false;
}
void rwopen()
{
  digitalWrite(rend, LOW);
  digitalWrite(rw, HIGH);
  delay(350);
  digitalWrite(rw, LOW);
  RightWaterValveOpen = true;
}
void rwclose()
{
  digitalWrite(rw, LOW);
  digitalWrite(rend, HIGH);
  delay(350);
  digitalWrite(rend, LOW);
  RightWaterValveOpen = false;
}
void lclose()
{
  digitalWrite(lw, LOW);
  digitalWrite(lend, LOW);
}
void rclose()
{
  digitalWrite(rw, LOW);
  digitalWrite(rend, LOW);
}
void timeoverled()
{
  digitalWrite(sled, HIGH);
  delay(1000);
  digitalWrite(sled, LOW);
}

Command running high for 1 minute. Can you help me?

You need to detect when the values become equal rather than when they are equal

See the StateChangeDetection example in the IDE

Ok, thanks.

A far as I can see your variable trig increments in steps of 1 minute. Consequently the test

 if (trig == s1) {

will be true every time it is checked during that minute.

If you want something to happen only once then you need to check for when the time first matches s1. Something like

if (trig == s1 and previousTrig < s1) {
   previousTrig = trig;

If that does not help please explain the problem in more detail.

…R

Unfortunately I had to go out right now and as soon as I get the experience I will share it; thank you so much.

We need to see your code

Now I had the opportunity to try it

Where in your code are you testing when trig becomes equal to a value rather than when trig is currently equal to a value ?

You are not setting previousTrig anywhere.
So of course previousTrig < s1, except when s1 is zero.
Set previousTrig at the end of loop.

Edit: you are also probably testing the wrong variable and the use of < won’t cut it if one of your times is midnight (0)…

 if (trig == s1 and previousTrig != trig) {

Think about how this works (to stop the if executing every time around loop during the entire matching minute, instead of just the first time the match is encountered like you want) and where and what you need to set previousTrig to.

Can you show me then i don’t know how to do this

Thanks for all your help now works as it should.