Blynk app button gets disabled

I setup a push button (D40) on the app to turn on a vent fan in my greenhouse. When I push the button the fan comes on for just a sec and then turns off. I am assuming it is because of the if statements in my void loop that turns the fan on based on temp. Im guessing when the temp is below 75 it turns off the button. I am brand new to arduino and still trying to wrap my head around how if statements work . Im sure this is simple to do but I cant seen to figure it out.

this is the part of the code I think is turning off the button

   //***********Cooling Code***************

 if (fahrenheit >= 85)
     { digitalWrite (Relay_1, RELAY_ON);}//Greenhouse Temp Control Fan ON Above 85 Degrees
 
 if  (fahrenheit <= 75) 
     { digitalWrite (Relay_1, RELAY_OFF);}  //Greenhouse Temp Control  coolingFan OFF Below 75 Degrees

 if (fahrenheit >= 95)
     {Blynk.notify("GREENHOUSE OVERHEATING!!!");}

Original Code


/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - Arduino Ethernet board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display


OneWire  ds(7);  // on pin 7 (a 4.7K resistor is necessary) make sure you change this from the original pin 10 to an unused pin.


RTC_DS3231 rtc;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***************";

#define W5100_CS  10
#define SDCARD_CS 4

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};






/*-----( Declare Constants )-----*/
#define RELAY_ON 0
#define RELAY_OFF 1
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#define Relay_1  40  // Arduino Digital I/O pin number
#define Relay_2  41
//#define Relay_3  0
//#define Relay_4  1



int sensorPin = 0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor



void setup()
{
  //lcd.init(); //initialize the lcd
  //lcd.backlight(); //open the backlight
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  //Blynk.begin(auth);
  // You can also specify server:
  Blynk.begin(auth, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,10,222), 8442);

  // Send e-mail when your hardware gets connected to Blynk Server
  // Just put the recepient's "e-mail address", "Subject" and the "message body"
  Blynk.email("***************", "Subject", "Greenhouse is online.");
  
  //#ifndef ESP8266
  //while (!Serial); // for Leonardo/Micro/Zero
//#endif

  
  Serial.begin(9600);

     lcd.init();      // initialize the lcd 
     lcd.backlight(); // Turn on LCD Backlight
     
   // Uncomment to set time to PC time
  //rtc.begin();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    //Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust (DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // Adjust Time on line Below 
    //rtc.adjust(DateTime(2017, 8, 23, 10, 36, 0));
  }

  Serial.begin(9600);

    
    //---( THEN set pins as outputs )----  
  pinMode(Relay_1, OUTPUT);   
  pinMode(Relay_2, OUTPUT);  
  //pinMode(Relay_3, OUTPUT);  
  //pinMode(Relay_4, OUTPUT);    
  //delay(1000); //Check that all relays are inactive at Reset
    
    
    //-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, RELAY_OFF);
  digitalWrite(Relay_2, RELAY_OFF);
  //digitalWrite(Relay_3, RELAY_OFF);
  //digitalWrite(Relay_4, RELAY_OFF);  


  }



void loop()
{
  
    Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!


   DateTime now = rtc.now();

   char dateBuffer[12];

   sprintf(dateBuffer,"%02u-%02u-%04u ",now.month(),now.day(),now.year());
   Serial.print(dateBuffer);

   sprintf(dateBuffer,"%02u:%02u:%02u ",now.hour(),now.minute(),now.second());
   Serial.println(dateBuffer);
      
      // Watering Schedule

       if (now.hour() == 8 & now.minute() == 30 & now.second() <= 10)
  
  { Blynk.notify("Plants Just Wattered!");
    Blynk.email("***************", "Subject: Greenhouse", "Plants Just Watered!");
    lcd.clear ();
    lcd.print("   Arduino is" );
    lcd.setCursor(0, 1);
    lcd.print("Watering Plants" );
    digitalWrite(Relay_2, RELAY_ON);// Turn the Watering Relay ON
    delay(300000);              // Water for 5 Minutes
    digitalWrite(Relay_2, RELAY_OFF);// Turn the Watering Relay OFF
 
  }
  
    if (now.hour() == 17 & now.minute() == 30 & now.second() <= 10 )
 { Blynk.notify("Plants Just Watered!");
    Blynk.email("***************", "Subject: Greenhouse", "Plants Just Watered!");
    
    lcd.clear ();
    lcd.print("   Arduino is" );
    lcd.setCursor(0, 1);
    lcd.print("Watering Plants" );
    
    digitalWrite(Relay_2, RELAY_ON);// Turn the Watering Relay ON
    delay(150000);              // Water for 5 Minutes
    digitalWrite(Relay_2, RELAY_OFF);// Turn the Watering Relay OFF
 }
    //Serial.print(now.month(), DEC);
    //Serial.print('/');
    //Serial.print(now.day(), DEC);
    //Serial.print('/');
    //Serial.print(now.year(), DEC);
    //Serial.print(" (");
    //Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    //Serial.print(") ");
    //Serial.print (now.hour(), DEC);
    //Serial.print(':');
    //Serial.print(now.minute(), DEC);
    //Serial.print(':');
    //Serial.print(now.second(), DEC);
    //Serial.println();
    
 
    
   //Remember to avoid delay() function!
  
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;

  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }

  Serial.print("ROM =");
  for ( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
    Serial.println("CRC is not valid!");
    return;
  }
  Serial.println();

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");
  Blynk.virtualWrite(V5, fahrenheit);


     //***********Cooling Code***************

  if (fahrenheit >= 85)
     { digitalWrite (Relay_1, RELAY_ON);}//Greenhouse Temp Control Fan ON Above 85 Degrees
 
     
    
     
     
     if  (fahrenheit <= 75) 
     { digitalWrite (Relay_1, RELAY_OFF);}  //Greenhouse Temp Control  coolingFan OFF Below 75 Degrees

     
  
   
   if (fahrenheit >= 95)
     {Blynk.notify("GREENHOUSE OVERHEATING!!!");}
  
  
    
      //*************Heating Code****************
    
  //if (fahrenheit  >= 55.00)  
  //{ digitalWrite (Relay_2, RELAY_OFF);}    //Greenhouse Temp Control Heater Fan ON Above 85 Degrees

  //if (fahrenheit  <= 45.00) 
  //{ digitalWrite (Relay_2, RELAY_ON);}  //Greenhouse Temp Control Heater Fan OFF Below 80 Degrees

 // read the value from the sensor:
  sensorValue = analogRead(sensorPin);    
  delay(1000);          
  Serial.print("sensor = " );                       
  Serial.println(sensorValue);      
  

   // set up the LCD's number of columns and rows:
  // Print a message to the LCD.
    lcd.clear ();
    lcd.setCursor(0, 0);
    lcd.print ("Windy Ridge Farm");
    delay(3000);
 
  
  lcd.clear ();
  lcd.print("Greenhouse Temp:" );
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  lcd.print(fahrenheit );
  lcd.print((char)223);
  lcd.print ("F");
  delay (3000);
 
//Print Second Line
    lcd.clear ();
    lcd.setCursor(0, 0);
    lcd.print ("Eastern Time:");
    lcd.setCursor(0, 1);
    sprintf(dateBuffer,"%02u:%02u ",now.hour(),now.minute());
    lcd.print(dateBuffer);
    //lcd.print(now.hour(), DEC);
    //lcd.print(':');
    //lcd.print(now.minute(), DEC);
    //lcd.print(':');
    //lcd.print(now.second(), DEC);
    Serial.println();
  //delay (3000);
   
   Blynk.virtualWrite(V1, dateBuffer);

  }

Updated Code


/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - Arduino Ethernet board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
#define ONE_WIRE_BUS 7          //Arduino Mega Digital Pin 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
BlynkTimer timer;

RTC_DS3231 rtc;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***************";

#define W5100_CS  10
#define SDCARD_CS 4

/*-----( Declare Constants )-----*/
#define RELAY_ON 0
#define RELAY_OFF 1
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#define Relay_1  40  // Arduino Digital I/O pin number
#define Relay_2  41
#define Relay_3  42
#define Relay_4  43

int displayState = 0; 



int GreenhouseTemp;            // Greenhouse temperature in F

unsigned long previousMillis1 = 0;        // will store last time Display was updated
long interval = 3000; // m

//int timeState = LOW;

unsigned long previousMillis2 = 0;       // will store last time Time was updated
long OnTime = 100;           // milliseconds of on-time
long OffTime = 200;          // milliseconds of off-time

int sensorPin = 0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor

BLYNK_WRITE(V2)
{
  int CFanBttn = param[1].asInt(); // assigning incoming value from pin V2 to a variable
  if (CFanBttn == 0)
  {
    digitalWrite(Relay_1, CFanBttn);
    }
    else
  {
    digitalWrite(Relay_1, HIGH);
  }
  }

BLYNK_WRITE(V3)
{
  int WtrBttn = param[2].asInt(); // assigning incoming value from pin V3 to a variable
  
  if (WtrBttn == 0)
  {
    digitalWrite(Relay_2, WtrBttn);
    }
    else
  {
    digitalWrite (Relay_2, HIGH);
  }
}
BLYNK_WRITE(V4)
{
  int HFanBttn = param[3].asInt(); // assigning incoming value from pin V4 to a variable
  if (HFanBttn == 0)
  {
    digitalWrite(Relay_3, HFanBttn);
    }
    else
  {
    digitalWrite(Relay_3, HIGH);
  }



void setup()
{
  
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  //Blynk.begin(auth);
  // You can also specify server:
  Blynk.begin(auth, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,10,222), 8442);

  // Send e-mail when your hardware gets connected to Blynk Server
  // Just put the recepient's "e-mail address", "Subject" and the "message body"
  Blynk.email("***************", "Subject", "Greenhouse is online.");
  

     lcd.init();      // initialize the lcd 
     lcd.backlight(); // Turn on LCD Backlight
     
   // Uncomment to set time to PC time
  //rtc.begin();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    //Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust (DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // Adjust Time on line Below 
    //rtc.adjust(DateTime(2017, 8, 23, 10, 36, 0));
  }

  Serial.begin(9600);

      //---( THEN set pins as outputs )----  
  pinMode(Relay_1, OUTPUT);   
  pinMode(Relay_2, OUTPUT);  
  pinMode(Relay_3, OUTPUT);  
  pinMode(Relay_4, OUTPUT);    
  //delay(1000); //Check that all relays are inactive at Reset
    
    
    //-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, RELAY_OFF);
  digitalWrite(Relay_2, RELAY_OFF);
  digitalWrite(Relay_3, RELAY_OFF);
  digitalWrite(Relay_4, RELAY_OFF); 



 timer.setInterval(1000L, Date_Time );
 timer.setInterval(1000L, sendTemps );
 timer.setInterval(3000L, LCDdisplay );
 timer.setInterval(1000L, Temp );  
 timer.setInterval(1000L, sendTime );
}


void loop()
{
    Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!

    timer.run();
}
  
   
   void sendTemps()
{
  sensors.requestTemperatures();                  // Polls the sensors.
  GreenhouseTemp = sensors.getTempFByIndex(0);   // Stores temperature. Change to getTempCByIndex(0) for celcius.
  Blynk.virtualWrite(V5, GreenhouseTemp);         // Send temperature to Blynk app virtual pin 1.
}

   void sendTime()
 {
  DateTime now = rtc.now();

   char dateBuffer[12];

   sprintf(dateBuffer,"%02u:%02u ",now.hour(),now.minute());
   Serial.println(dateBuffer);

   Blynk.virtualWrite(V1,dateBuffer);   

 }
   
   void LCDdisplay()
{

 // check to see if it's time to change the state of the LED
  unsigned long currentMillis = millis();
 
  if((displayState  == 0) && (currentMillis - previousMillis1 >= interval))
  {
    displayState = 1;  // Turn it off
    // set up the LCD's number of columns and rows:
  // Print a message to the LCD.
    lcd.clear ();
    lcd.setCursor(0, 0);
    lcd.print ("Windy Ridge Farm");
  }
  
     else if ((displayState == 1) && (currentMillis - previousMillis1 >= interval))
  {
    displayState = 2;  // turn it on
    previousMillis1 = currentMillis;   // Remember the time
    lcd.clear ();
    lcd.print("Greenhouse Temp:" );
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    lcd.print(GreenhouseTemp);
    lcd.print((char)223);
    lcd.print ("F");
  }
  
  else if((displayState  == 2) && (currentMillis - previousMillis1 >= interval))
  {
    displayState = 0;  // Turn it off
     DateTime now = rtc.now();
      char dateBuffer[12];
      
      //Print Second Line
    lcd.clear ();
    lcd.setCursor(0, 0);
    lcd.print ("Eastern Time:");
    lcd.setCursor(0, 1);
    sprintf(dateBuffer,"%02u:%02u ",now.hour(),now.minute());
    lcd.print(dateBuffer);
    
  }

}


   void Date_Time ()
{
  DateTime now = rtc.now();

   char dateBuffer[12];

   sprintf(dateBuffer,"%02u-%02u-%04u ",now.month(),now.day(),now.year());
   Serial.print(dateBuffer);

   sprintf(dateBuffer,"%02u:%02u:%02u ",now.hour(),now.minute(),now.second());
   Serial.println(dateBuffer);
  

      
      // ********Watering Schedule***********

  int SchOn1 = (now.hour() == 8 & now.minute() == 30 & now.second() <= 10);
  int SchOff1= (now.hour() == 8 & now.minute() == 33 & now.second() <= 10);     
  int SchOn2 = (now.hour() == 17 & now.minute() == 30 & now.second() <= 10);
  int SchOff2= (now.hour() == 17 & now.minute() == 33 & now.second() <= 10);   
         
         
         
     unsigned long currentMillis = millis();
 
    if((SchOn1) && (currentMillis - previousMillis2 >= OnTime))
  {
    Blynk.notify("Plants Just Watered!");
    Blynk.email("***************", "Subject: Greenhouse", "Plants Just Watered!");
    digitalWrite(Relay_2, RELAY_ON);// Turn the Watering Relay ON
    Blynk.virtualWrite(V3, RELAY_ON);
  }
    
    else if ((SchOff1) && (currentMillis - previousMillis2 >= OffTime))
  {
    previousMillis2 = currentMillis;   // Remember the time
    digitalWrite(Relay_2, RELAY_OFF);// Turn the Watering Relay OFF
    Blynk.virtualWrite(V3, RELAY_OFF);
}

    if((SchOn2) && (currentMillis - previousMillis2 >= OnTime))
  {
    Blynk.notify("Plants Just Watered!");
    Blynk.email("***************", "Subject: Greenhouse", "Plants Just Watered!");
    digitalWrite(Relay_2, RELAY_ON);// Turn the Watering Relay ON
  Blynk.virtualWrite(V3, RELAY_ON);
}
  
   else if ((SchOff2) && (currentMillis - previousMillis1 >= OffTime))
  {
    previousMillis2 = currentMillis;   // Remember the time
    digitalWrite(Relay_2, RELAY_OFF);// Turn the Watering Relay OFF
    Blynk.virtualWrite(V3, RELAY_OFF);
 }
  
 }

 void Temp()
{
     //***********Cooling Code***************

  if (GreenhouseTemp >= 85)
     { digitalWrite (Relay_1, RELAY_ON);//Greenhouse Temp Control Fan ON Above 85 Degrees
       Blynk.virtualWrite(V2, RELAY_ON);}
  else if  ((GreenhouseTemp > 73)  && (GreenhouseTemp< 75))

     { digitalWrite (Relay_1, RELAY_OFF);  //Greenhouse Temp Control  coolingFan OFF Below 75 Degrees
       Blynk.virtualWrite(V2, RELAY_OFF);
}

    bool tempflag = true;  
   
   if ((GreenhouseTemp >= 95)  && (tempflag == true))
  {
   Blynk.notify("GREENHOUSE OVERHEATING!!!");
   tempflag = false;
  }

if (GreenhouseTemp < 95)
{
  tempflag = true;
}



    //*************Heating Code****************
    
  if  ((GreenhouseTemp > 55)  && (GreenhouseTemp< 57))  
  { digitalWrite (Relay_3, RELAY_OFF);    //Greenhouse Temp Control Heater Fan OFF Above 55 Degrees F
    Blynk.virtualWrite(V4, RELAY_OFF);
}
  if (GreenhouseTemp  <= 45) 
  { digitalWrite (Relay_3, RELAY_ON);  //Greenhouse Temp Control Heater Fan ON Below 45 Degrees F
    Blynk.virtualWrite(V4, RELAY_ON);
}

}

First make sure you have set the right working mode of the button in APP. (Push or switch) If in doubts- check docs.blynk.cc (I think)

It is most likely that congested void loop.

You need to read through the DOCs and check out a couple of examples (sketch builder or Gunners {C++ Blynk - Code Examples for Basic Tasks (Work in Progress)}). You need to use timers.

It is set to Push button

I would say that the if statement is what is turning off the button because the button works at 76 degrees but not sure how to correct this

if (fahrenheit <= 75)
{ digitalWrite (Relay_1, RELAY_OFF);} //Greenhouse Temp Control coolingFan OFF Below 75 Degrees

So it work that way!
You are not using Virtual Pins. OK, you don’t have to. Then you probably “wired” hardware pin 40 to button in “push” mode. In that mode Blynk sends “1” (or 255? I don’t remember) as long, as button is pressed. After release, it sends “0” as it is programmed.
Have not checked Your conditional checks, but in comments you have statement “avoid delays”, but then you are using a lot of delays in loop () function. Blynk will most probably refuse to work that way.

One more note: The If (t<=75) then OFF is self-explanatory. If you wish to turn it off below 75 then it does it for you.

@Toro_Blanco, loop() works with long sequences very fine, but it cannot steal too much time, as other tasks will simply “jump off” that train. In other words it needs to be properly written. This one is NOT properly written. That is why it is safe for all to keep it as empty as possible :upside_down_face:

Yes, loop() can work with sequences if you know what you are doing with respect to BLYNK. If someone is having trouble just getting an IF statement and a button to work correctly, I doubt they are able to understand how to avoid disconnections from BLYNK when putting sequences in the loop().

The loop() as it is above, will never work properly with BLYNK.

Yup, can’t argue with that :rofl:

Yikes, that is a busy loop. Must move it to timer triggered action. What is the point in printing on serial monitor for every loop run?

I can never thank this group enough for pointing me to the direction of timers very early on. We must just think timers for repetitive tasks and have just
void loop{
blynk.run();
timer.run();
}

1 Like

Actually it does work just a slight delay in the buttons. It gives correct time and temp to the app and sends notifications when watering and overheating. I fixed the issue by making a 1/2 degree temp range to turn off the fan so fan button works now. I know my code isn’t perfect doubt yours was either when you first started coding thats why im on this forum to get help so could do with out your criticizing comments. forums are to help people solve problems not cut them down on what they don’t know!!

Thanks for the info i will look into how to create timers

Good for you, but I wonder what is MCU (and it’s tasks) doing when program is in 30sec loop??

Well, I guess it depends… I was never allowed to write code that way. Probably that is the reason I’m considering your as “not valid” (even though it somehow works)

Sure! That is why this forum exists! But that is not a kindergarten and a criticism is a part of an answer too! We all still learning, trying, correcting, trying again, sometimes asking for help others. If someone is telling you: “what you did is wrong- it might not work, learn how to schedule tasks”… Isn’t it an answer?
Regards, Marcin.

1 Like

FYI im self taught have never had a programming class just a farmer trying to automate his greenhouse. All the code is copied and pasted from other sketches. For me thats a foundation to start from

And that is the beauty of today’s world! Everyone can do (build) something to ease the life. But then there is the trick: It takes a lot of time to learn, and often we hit the wall. (I’m not a pro either).

Then look at all the Doc’s and Blynk examples. They are really easy and helpful. Look at the sketch builder- although not perfect, helps to create a starting point.
Some members of this forum spent a lot of time (I guess) creating helpful tutorials and templates- just look around on this forum. Good luck!

Here is how I fixed the button problem. I created a range ((GreenhouseTemp > 73) && (GreenhouseTemp< 75))
instead of just saying else if (GreenhouseTemp< 75)

void Temp()
{
     //***********Cooling ***************

  if (GreenhouseTemp >= 85)
     { digitalWrite (Relay_1, RELAY_ON);}//Greenhouse Temp Control Fan ON Above 85 Degrees
   
  else if  ((GreenhouseTemp > 73)  && (GreenhouseTemp< 75))

     { digitalWrite (Relay_1, RELAY_OFF);}  //Greenhouse Temp Control  coolingFan OFF Below 75 Degrees

@bcomer, glad to see you got everything out of the loop() and called with timers. This will make your connection to BLYNK much more reliable.

A few things to consider:

  • You might want to move bool tempflag = true; to the top where you declare your other variables. The way it is now, every time Temp() is executed it will reset tempflag back to true. You don’t want the flag changed back to true until GreenhouseTemp is below 95.

  • You can probably do away with the (GreenhouseTemp > 73) && and the && (GreenhouseTemp< 57) as you have a large enough gap between when they turn on and off. Basically the fan turns on when temp is at or above 85, and turns off when it falls below 75. The heater will turn on if temp falls below 45 and turn off when temp gets above 55.

I moved the bool tempflag = true; to the top with the other variables. The reason it was that way is because I copied it from another sketch and just added my variables. As for the (GreenhouseTemp > 73) && (GreenhouseTemp< 75) I had to do it that way because if the temp dropped below 75 because the timer checked it every second it would turn the fan off when if I turned it on with the widget button. Is there a better way to do this? Just having(GreenhouseTemp< 75) wouldn’t work if the temp was below 75 but would work if temp was between 75& 85

You are trying to add/have a button in the APP that overrides/works with the IF statement?

yes, If Im working in there and its 73 and humid its nice to be able to turn on the fan to circulate the air via the app button