Can anyone help me please?

I'm working on my project on automation using pump and 2 programmable gate valves with RTC, pH sensor, temp sensor and LCD. I have a problem when myRTC.hours reaches 9 A.M. It doesn't execute the command I programmed. I need your help please.

Here is my sketch:

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include<virtuabotixRTC.h>
#define SensorPin 0
#define TempPin 1

#define I2C_ADDR    0x27  // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

LiquidCrystal_I2C       lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

int pump = 11;                                                      
int drain = 12;                                                       
int reservoir = 13;                                                
int fstank = 14;                                                     

virtuabotixRTC myRTC(8, 9, 10);                                        

float sensorValue = 0;                      
float pH;

float tempValue = 0;
int temp;
  

void setup()
{
  Serial.begin(9600);                                      
  Serial.println("Ready to take pH!");                                    
  
  myRTC.setDS1302Time(00,55,21,5,25,9,2014);                           
  
  lcd.begin (20, 4, LCD_5x8DOTS);                                     
  
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);                      
  
  pinMode(pump, OUTPUT);                                                    
  pinMode(drain, OUTPUT);
  pinMode(reservoir, OUTPUT);
  pinMode(fstank, INPUT);
  
  lcd.setBacklight(HIGH);

}

void loop()
{
  myRTC.updateTime();                                                    
  sensorValue = analogRead(SensorPin);
  pH = (0.0178 * sensorValue); 
  tempValue = analogRead(TempPin);
  temp = (tempValue * 0.48828125);                                   
  print_date_time_ph(); 
  
  
if (myRTC.hours >= 6 || myRTC.hours < 9)                                
     {
        pH_regulate();                                                  
     }
  
else if (myRTC.hours == 9)                     //I can't work on this one.. my relay is active LOW.. but it shows no response or whatsoever                                                                       
     {                                                              //it only shows all OUTPUT in HIGH.
       if (myRTC.minutes == 30)                                           
        {
            digitalWrite(pump, LOW);
            digitalWrite(reservoir, HIGH);
            digitalWrite(drain, HIGH);
         }
       if (myRTC.minutes == 59)                                          
        {  
            digitalWrite(pump, HIGH);
            digitalWrite(reservoir, HIGH);                      
            digitalWrite(drain, HIGH);
        }
        else                                                           
        {
          pH_regulate();                                               
        }
                                         
     }
     
else if (myRTC.hours >= 10 || myRTC.hours < 13)                       
       {
          pH_regulate();                                                
       }
       
else if (myRTC.hours == 13)
     {
       if (myRTC.minutes == 30)
        {
            digitalWrite(pump, LOW);
            digitalWrite(reservoir, HIGH);
            digitalWrite(drain, HIGH);
         }
       if (myRTC.minutes == 59)
        {  
            digitalWrite(pump, HIGH);
            digitalWrite(reservoir, HIGH);
            digitalWrite(drain, HIGH);
        }
        else
        {
          pH_regulate();
        }
     }
     
else if (myRTC.hours >= 14 || myRTC.hours < 17)
      {
         pH_regulate();
      }
      
     
else if (myRTC.hours == 17)
      {
       if (myRTC.minutes == 0)
        {
            digitalWrite(pump, LOW);
            digitalWrite(reservoir, HIGH);
            digitalWrite(drain, HIGH);
         }
       if (myRTC.minutes == 2)
        {  
            digitalWrite(pump, HIGH);
            digitalWrite(reservoir, HIGH);
            digitalWrite(drain, HIGH);
        }
        else
        {
          pH_regulate();
        }
      }

}


void print_date_time_ph()                                                     
{                                                                              
lcd.setCursor(6,0);
lcd.print(myRTC.dayofmonth);
lcd.setCursor(8,0);
lcd.print("/");
lcd.setCursor(9,0);
lcd.print(myRTC.month);
lcd.setCursor(11,0);
lcd.print("/");
lcd.setCursor(12,0);
lcd.print(myRTC.year);
lcd.setCursor(11,1);
lcd.print(myRTC.hours);
lcd.setCursor(13,1);
lcd.print(":");
lcd.setCursor(14,1);
lcd.print(myRTC.minutes);
lcd.setCursor(0,1);
lcd.print("pH:");
lcd.setCursor(3,1);
lcd.print(pH);
lcd.setCursor(0,0);
lcd.print(temp);
lcd.setCursor(2,0);
lcd.print((char)223);
lcd.setCursor(3,0);
lcd.print("C");
delay(1000);
}

void pH_regulate()                                                            
{
  myRTC.updateTime();
  
  if (pH <= 6.5)                                                                 
{
  if (digitalRead(fstank) == HIGH)                                             
            {                                                                   
              digitalWrite(drain, LOW);
              digitalWrite(pump, HIGH);
              digitalWrite(reservoir, HIGH);
              
            }
  if (digitalRead(fstank) == LOW)                                              
            {                                                                  
              digitalWrite(reservoir, LOW);                                  
              digitalWrite(pump, HIGH);                                      
              digitalWrite(drain, HIGH);
              
            }
}
        
else if (pH >= 7.5)                                                          
         {                                                                   
	      digitalWrite(LED, HIGH);
	      delay(500);                                                  
         }
 
else if (pH > 6.5 || pH < 7.5)                                 
         {                                                    
           if (digitalRead(fstank) == LOW)
               {
                   digitalWrite(reservoir, LOW);
                   digitalWrite(drain, HIGH);
                   digitalWrite(pump, HIGH);
               }
           else                                               
           
               {
                   digitalWrite(drain, HIGH);
                   digitalWrite(reservoir, HIGH);
                   digitalWrite(pump, HIGH);
               }
           
         }
}

Can anyone help me please? Thanks.

moderator edit: added code tags ==> # button above smileys

if (myRTC.hours == 9)  //I can't work on this one.. my relay is active LOW.. but it shows no response or whatsoever                                                                       
     {                     //it only shows all OUTPUT in HIGH.
       if (myRTC.minutes == 30)

You need to wait another half hour. It's not due to go off until minutes reach 30.

You need to wait another half hour. It's not due to go off until minutes reach 30.

I set my clock to 9:29:50 but when it reaches 9:30:00 it does nothing. It should turn the pump on. :confused:

Here is the problem:

if (myRTC.hours >= 6 || myRTC.hours < 9)                                
     {
        pH_regulate();                                                  
     }
  
else if (myRTC.hours == 9)                     //I can't work on this one.. my relay is active LOW.. but it shows no response or

If hour is 9, it's greater than six, so it will execute PH_Regulate - your else clause will never be executed.

Try using && instead of ||

Well spotted wildbill- I looked at that a few times and didn't notice, which is ironic since I had that exact logic error in some code of my own recently and did spot it....

If hour is 9, it's greater than six, so it will execute PH_Regulate - your else clause will never be executed.

Try using && instead of ||

Aw. Didn't see that one. So I'll just change || to &&. Ok sir. I'll try that one. Thanks. :slight_smile:

brenterz:
Aw. Didn't see that one. So I'll just change || to &&. Ok sir. I'll try that one. Thanks. :slight_smile:

Do the test for the large number first.

...R

Do the test for the large number first.

Or just remove the word "else"

KenF:

Do the test for the large number first.

Or just remove the word "else"

Doing the large number test first AND using else avoids the need for the double test in

if (myRTC.hours >= 6 && myRTC.hours < 9)

because it will already have disposed of the case where it is > 9

...R