Timer Logic

Hello everyone,

I have a little project on the go where I have an rtc, relay switch, buttons and display connected to an arduino.

The user is required to set an "On" time and "Off" time that will cause the relay switch to turn on and off at these times.

I have used a number of if statements to try to achieve this but have not had the best results.

Any help would be appreciated

Thanks in advance

How about your post your sketch - that would REALLY help people help you. If only you can see the code, only you can know what it is doing.

And before you just paste it into a reply, read the sticky post at the top of the forum about how to properly post your code using code tags. It helps people help you.

blh64:
How about your post your sketch - that would REALLY help people help you. If only you can see the code, only you can know what it is doing.

And before you just paste it into a reply, read the sticky post at the top of the forum about how to properly post your code using code tags. It helps people help you.

    if (currentHR > onTimeH && currentHR < offTimeH && relayStatus == 0) {
      relayStatus = 1;
      currentDay += 1;
      if (growStage == 1) {
        lcd.print(" ON");
        digitalWrite(relay1, LOW);
        digitalWrite(relay2, LOW);
        digitalWrite(relayLED1, HIGH);
        digitalWrite(relayLED2, HIGH);
        lcd.display();
      } else {
        digitalWrite(relay1, LOW);
        digitalWrite(relay2, HIGH);
        digitalWrite(relayLED1, HIGH);
        lcd.setCursor(17, 2);
        lcd.print(" ON");
        lcd.display();
      }
    } else if (currentHR > offTimeH && currentHR < onTimeH && relayStatus == 1) {
      relayStatus = 0;
      Serial.print("relays off");
      Serial.print("\n");
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, HIGH);
      digitalWrite(relayLED1, LOW);
      digitalWrite(relayLED2, LOW);
      lcd.setCursor(17, 2);
      lcd.print("OFF");
      lcd.noDisplay();
    }

There is still a lot of code we can't see. Please post a complete sketch, as suggested in the links provided.

So the sketch is too big to actually post so I have attached it

GroBox_v1.1(1).ino (14.4 KB)

With a program of such size, you must have a previous version that works, perhaps with fewer features. Perhaps you can identify the problem from that, since at some point you had a program that worked, added a line or two and then it failed?

"have not had the best results" is too vague a problem description to help. We need much more detail about the actual behaviour.