Advice as to why my time inputs stopped working

Looking for some help with my project. I had the time inputs working but now the relays arnt triggered at the set times and the leds do some strange things. like when you move the slider for the brightness, the leds brighten and dim several times on the was to max (a value of 100). its almost like the leds only dim from say 1 to 20 then starts back at 2 again. It was my understanding this was the correct way to go with multiple time inputs but its not working.

Could anyone give me and pointers and some understanding as to where i have gone wrong?
Should i add some check flags on each timer as i feel that would make it a little more stable and help to not miss a activation?

thanks in advance
Adam.

#include <Nextion.h>  // Include the nextion library (the official one) https://github.com/itead/ITEADLIB_Arduino_Nextion
                      // Make sure you edit the NexConfig.h file on the library folder to set the correct serial port for the display.
                      // By default it's set to Serial1, which most arduino boards don't have.
                      // Change "#define nexSerial Serial1" to "#define nexSerial Serial" if you are using arduino uno, nano, etc.

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h> // This part is for Ethernet stuff
#define W5100_CS  10
#define SDCARD_CS 4
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <SimpleTimer.h>
char auth[] = "d27bf6f0a098498a81a5c65dab79b851"; // Put your Auth Token here.
BlynkTimer timer;
WidgetRTC rtc;
//Temperature 
#include <OneWire.h> // Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
//Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS 48// DS18B20 on arduino pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
// This function will run every time Blynk connection is established
DeviceAddress Probe01 = { 0x28, 0xFF, 0x2D, 0x5A, 0xC4, 0x17, 0x05, 0xEF  }; 
DeviceAddress Probe02 = { 0x28, 0x1F, 0x12, 0x77, 0x91, 0x0A, 0x02, 0x68 };
float tanktemp;
float sumptemp;

BLYNK_CONNECTED() {
 rtc.begin();
 // Request Blynk server to re-send latest values for all pins
Blynk.syncAll();
}

//ATO switches and relay 
byte lowWaterPin = 6;    // Goes LOW when water below switch
byte highWaterPin = 7;   // Goes LOW when water below switch
byte pumpPin = 8;        // Relay to control the water pump
unsigned long maxRunTime = 60 * 1000L;   // pump on for max of one minute
unsigned long minOffTime = 60 * 60 * 1000L;  // pump must be off for at least one hour
unsigned long switchDebounceTime = 3 * 1000L;  // Switch must be activated for at least 3 seconds.
unsigned long lastPumpTime = 0;
unsigned long lastLowWaterDetectTime = 0;
unsigned long currentMillis;
boolean lastLowWaterState = HIGH;
boolean pumpRunning = false;
////////////////////////////////////////////////////////////////////////////////////
int relayPin = 49;// Heater on ssr1
int relay2Pin = 28;// Cooling to 16ch relay board relay 7 on the board
int relay3Pin = 22;// return pump on relay 1 on the board
int relay4Pin = 23;// Skimmer on relay 2 on the board
int relay5Pin = 24;// Reactor on relay 3 on the board
int relay6Pin = 25;// t5s on relay 4 on the board
int relay7Pin = 26;//
int relay8Pin = 27;//
int wave1Pin = 47;// Wave maker on ssr2 
int wave2Pin = 46;// Wavemaker 2 on ssr3
///////////////////////////////////////////////////////////////////////////////////
float desiredTemp = 26;// Set this to your desired temp
float tempDiff = 1;// This variable provides a small +/- temp differential that will prevent constant relay switching.
bool      tempAlarmFlag    = false;      //flag to alarm, and avoid multiple Notification
bool      faultyProbeFlag  = false;      //flag to alarm, and avoid multiple Notification
float lowAlarm     = NAN;
float highAlarm    = NAN;
int onsec =3;                // Global variable used in Slider widget and runEveryMinute()
int offsec=3;                // Global variable used in Slider widget and runEveryMinute()
int x;
int y;
int CounterOn = 0;
int CounterOff = 0;
int ledStatus = 0;
int wavesw = 1;// Wave maker Onoff Button
int heatersw = 1;// Heater Onoff Button
int coolingsw = 1;// Cooling switch
int CurrentPage = 0;  // Create a variable to store which page is currently loaded
char Date[16];
char Time[16];
long startseconds = 0;         // start time in seconds
long stopseconds = 0;          // stop  time in seconds
long nowseconds = 0;           // time  now  in seconds
int fadetime = 0;
long fadetimeseconds = 0;
long fadetimemillis = 0;
int minPWM = 1;// variable for min PWM value. keep at 1 to avoid crashing the ledFade()
byte fadeIncrement = 1; //How smooth to fade? Uses all 4095 steps available.

int maxPWM0 = 0; // variable for max PWM value attached to BLYNK Virtual pin.
int maxPWM1 = 0; // variable for max PWM value attached to BLYNK Virtual pin.

int currentFadePosition0 = 0;// don't change this!
int currentFadePosition1 = 0;// don't change this!

unsigned long previousFadeMillis0;// millis() timing Variable, just for fading
unsigned long previousFadeMillis1;// millis() timing Variable, just for fading

long stepWaitTime0 = 0;  //How long to watch the clock before incrementing to the next step. (time in milliseconds)
long stepWaitTime1 = 0;  //How long to watch the clock before incrementing to the next step. (time in milliseconds)

int desiredledLevel0 = 0;
int desiredledLevel1 = 0;
int desiredledLevel2 = 0;
int desiredledLevel3 = 0;
int desiredledLevel4 = 0;
int desiredledLevel5 = 0;
int desiredledLevel6 = 0;
int desiredledLevel7 = 0;

#define led0  2 // white leds on pin... 
#define led1  3 // blue leds on pin...


// LED light control
void setLed() {

  stepWaitTime0 = (fadetimemillis / maxPWM0);
  stepWaitTime1 = (fadetimemillis / maxPWM1);


}

void ledFade0(unsigned long thisMillis0) {
  if (nowseconds < startseconds) {
    currentFadePosition0 = minPWM;
  }
  if (nowseconds > startseconds && nowseconds < stopseconds) {
    // is it time to start the Sunrise?
    // if not, nothing happens
    if (thisMillis0 - previousFadeMillis0 >= stepWaitTime0) {
      currentFadePosition0 = currentFadePosition0 + fadeIncrement;
      if (currentFadePosition0 >= maxPWM0) {
        // At max limit stop the fade
        currentFadePosition0 = maxPWM0;
      }
      // put actionable () here.
      analogWrite(led0, currentFadePosition0);
      // reset millis for the next iteration (fade timer only)
      previousFadeMillis0 = thisMillis0;
    }
  }
  if (nowseconds > stopseconds) {
    // is it time to start the Sunset yet?
    // if not, nothing happens
    if (thisMillis0 - previousFadeMillis0 >= stepWaitTime0) {
      currentFadePosition0 = currentFadePosition0 - fadeIncrement;
      if (currentFadePosition0 <= minPWM) {
        // At min limit stop the fade
        currentFadePosition0 = minPWM;
      }
      // put actionable () here
      analogWrite(led0, currentFadePosition0);
      // reset millis for the next iteration (fade timer only)
      previousFadeMillis0 = thisMillis0;
    }
  }
}
void ledFade1(unsigned long thisMillis1) {
  if (nowseconds < startseconds) {
    currentFadePosition1 = minPWM;
  }
  if (nowseconds > startseconds && nowseconds < stopseconds) {
    // is it time to start the Sunrise?
    // if not, nothing happens
    if (thisMillis1 - previousFadeMillis1 >= stepWaitTime1) {
      currentFadePosition1 = currentFadePosition1 + fadeIncrement;
      if (currentFadePosition1 >= maxPWM1) {
        // At max limit stop the fade
        currentFadePosition1 = maxPWM1;
      }
      // put actionable () here.
      analogWrite(led1, currentFadePosition1);
      // reset millis for the next iteration (fade timer only)
      previousFadeMillis1 = thisMillis1;
    }
  }
  if (nowseconds > stopseconds) {
    // is it time to start the Sunset yet?
    // if not, nothing happens
    if (thisMillis1 - previousFadeMillis1 >= stepWaitTime1) {
      currentFadePosition1 = currentFadePosition1 - fadeIncrement;
      if (currentFadePosition1 <= minPWM) {
        // At min limit stop the fade
        currentFadePosition1 = minPWM;
      }
      // put actionable () here
      analogWrite(led1, currentFadePosition1);
      // reset millis for the next iteration (fade timer only)
      previousFadeMillis1 = thisMillis1;
    }
  }
}



// Digital clock display of the time
void clockDisplay(){
  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  nowseconds = ((hour() * 3600) + (minute() * 60) + second());
  Serial.print("Time =");
  Serial.println(currentTime);
 // Serial.println(currentDate);
  Serial.print("Nowseconds =");
  Serial.println(nowseconds);
 // Serial.print("Start = ");
 // Serial.println(startseconds);
  //Serial.print("Stop = ");
 // Serial.println(stopseconds);
 // Serial.print("fade position0 =");
 // Serial.println(currentFadePosition0);
 // Serial.println();
  // Send time to the App
  Blynk.virtualWrite(V0, currentTime);
  // Send date to the App
  //Blynk.virtualWrite(V2, currentDate);
}

BLYNK_WRITE(V10) {// slider widget to set the maximum led level from the Blynk App.
  desiredledLevel0 = param.asInt();// channel 1
  maxPWM0 = map(desiredledLevel0, 0, 100, minPWM, 1023);
}
BLYNK_WRITE(V13) {// slider widget to set the maximum led level from the Blynk App.
  desiredledLevel1 = param.asInt();// channel 2
  maxPWM1 = map(desiredledLevel1, 0, 100, minPWM, 1023);
}

BLYNK_WRITE(V14) {// slider widget to set the led fade duration up tp 3 hours.
  fadetime = param.asInt();
  fadetimeseconds = map(fadetime, 0, 180, 1, 10800);// 3 hour fade duration is max
  fadetimemillis  = map(fadetime, 0, 180, 1, 10800000);// 3 hour fade duration is max
 // Serial.print("Fade Time in seconds =");
 // Serial.println(fadetimeseconds);
}

void activetoday() {       // check if schedule should run today
  if (year() != 1970) {
    Blynk.syncVirtual(V15); // sync led timeinput widget
    Blynk.syncVirtual(V16);// sync T5s timeinput widget
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
  }
}
BLYNK_WRITE(V58){ //leds relay buton
   int ledr = param.asInt(); // Get State of Virtual Button, heater
  if (ledr == 1) {
     digitalWrite(relay7Pin,LOW);
  }
  else
  {
    digitalWrite(relay7Pin,HIGH);
  }
}

BLYNK_WRITE(V57){ //leds relay buton
   int ledr = param.asInt(); // Get State of Virtual Button, heater
  if (ledr == 1) {
     digitalWrite(relay8Pin,LOW);
  }
  else
  {
    digitalWrite(relay8Pin,HIGH);
  }
}

BLYNK_WRITE(V17){  // t5s button off 
 int tubes = param.asInt(); // Get State of Virtual Button, Return pump
  if (tubes == 1) {  // button ON
    // Turn as many pins/relays ON as you need
    digitalWrite(relay6Pin, LOW);
  } else {  // button OFF
    // Turn as many pins/relays OFF as you need
    digitalWrite(relay6Pin, HIGH);
  }
}

BLYNK_WRITE(V16) {   // T5s
  TimeInputParam t(param);
int startsecond = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);  
int stopsecond = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
  Serial.print("Start = ");
  Serial.println(startsecond);
  Serial.print("Stop = ");
  Serial.println(stopsecond);
  Serial.println();
  int dayadjustment = -1;  
  if(weekday() == 1){
    dayadjustment = 6; // needed for Sunday Time library is day 1 and Blynk is day 7
  }
  if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday  
    //Schedule is ACTIVE today 
    if(nowseconds >= startsecond - 31 && nowseconds <= startsecond + 31 ){    // 62s on 60s timer ensures 1 trigger command is sent
      Blynk.virtualWrite(V17, 1);  // turn on virtual button t5s
      Serial.println("Schedule 1 started");
      digitalWrite(25, HIGH);// turn t5s relay on 
    }                  
    if(nowseconds >= stopsecond - 31 && nowseconds <= stopsecond + 31 ){   // 62s on 60s timer ensures 1 trigger command is sent
      Blynk.virtualWrite(V17, 0);   // turn OFF virtual vutton t5s 
      Serial.println("Schedule 1 finished");
     digitalWrite(25, LOW);// turn t5s relay off
    }               
  }
}

BLYNK_WRITE(V15) {// set time for leds 

  TimeInputParam t(param);
  Serial.print("Checked schedule at: ");
  Serial.println(Time);
  int dayadjustment = -1;
  if (weekday() == 1) {
    dayadjustment =  6; // needed for Sunday, Time library is day 1 and Blynk is day 7
  }
  if (t.isWeekdaySelected((weekday() + dayadjustment))) { //Time library starts week on Sunday, Blynk on Monday
    Serial.println("Schedule ACTIVE today");
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    if (nowseconds >= startseconds) {

      if (nowseconds <= startseconds + 90) {  // 90s on 60s timer ensures 1 trigger command is sent
        // code here
         Blynk.virtualWrite(V57, LOW);// turns LED relay on
         Blynk.virtualWrite(V58, HIGH);// turns fuge light off
      }
    }
    else {
      Serial.println("Relay not on");// nothing more to do here, waiting for relay to be turned on later today
    }
    stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    if (nowseconds >= stopseconds) {
      // 90s on 60s timer ensures 1 trigger command is sent
      if (nowseconds <= stopseconds + 90) {
        // code here
        Blynk.virtualWrite(V58, LOW);// turns fuge light on
        Blynk.virtualWrite(V57, HIGH);// turns LED relay off
      }
    }
    else {
      if (nowseconds >= startseconds) { // only show if motor has already started today
        Serial.println("Relay is still ON");
        // nothing more to do here, waiting for motor to be turned off later today
      }
    }
  }
  else {
    Serial.println("Schedule INACTIVE today");
    // nothing to do today, check again in 1 minutes time
  }
  Serial.println();
}

void reconnectBlynk() {
  if (!Blynk.connected()) {
    if (Blynk.connect()) {
      BLYNK_LOG("Reconnected");
    }
    else {
      BLYNK_LOG("Not reconnected");
    }
  }
}

//WAVEMAKERS CONTROLE

BLYNK_WRITE(V4){   // wave on time slider
  x = param.asInt();
  onsec = x;   
}
BLYNK_WRITE(V7){  // wave Off time slider
  y = param.asInt();  // set variable as Slider value 
  offsec = y;  
  }

  void wavecontrol()
{
  if(wavesw == 1)
  

  if ((CounterOn > 0) && (ledStatus == 0) && (wavesw == 1))
  {
      digitalWrite(wave1Pin,HIGH);   //write to pin to turn the LED on.
      digitalWrite(wave2Pin,LOW);
      Serial.print(": LED on\n");
      ledStatus = 1;
      CounterOff = 0;
  }

  if ((CounterOn > 0) && (ledStatus == 1))
      {
      CounterOn = (CounterOn - 1);
      }
      
  if ((CounterOff == 0) && (CounterOn == 0) && (ledStatus == 1)  && (wavesw == 1))
    {
      CounterOff = onsec;
    }

  if ((CounterOff > 0) && (ledStatus == 1))
  {
      digitalWrite(wave1Pin,LOW);   //write to pin to turn wave1 off
      digitalWrite(wave2Pin,HIGH);//write to pin to turn wave2 on
      ledStatus = 0;
      CounterOn = 0;
   }
   
  if ((CounterOff > 0) && (ledStatus == 0))
      {
      CounterOff = (CounterOff - 1);
      }
      
  if ((CounterOff == 0) && (CounterOn == 0) && (ledStatus == 0))
    {
      CounterOn = offsec+1;
    }

}
  BLYNK_WRITE(V6) // wavemakers
  { 
  int wavesw = param.asInt(); // Get State of Virtual Button, wave makers
   if (wavesw == 1) {
     wavecontrol();
  }
  else
  {
    Blynk.virtualWrite(V4,0);
    Blynk.virtualWrite(V7,0);
    digitalWrite(wave1Pin,LOW);
    digitalWrite(wave2Pin,LOW);

  }
}

//TEMPERATURE CONTROL

BLYNK_WRITE(V8){  
   int heatersw = param.asInt(); // Get State of Virtual Button, heater
  if (heatersw == 1) {
     Heater();
  }
  else
  {
    digitalWrite(relayPin,LOW);
  }
}
BLYNK_WRITE(V9){  
  int coolingsw = param.asInt(); // Get State of Virtual Button, cooling
  if (coolingsw == 1) {
     Cooler();
  }
  else
  {
    digitalWrite(relay2Pin,HIGH);
  }
}
BLYNK_WRITE(V11)
{
  //reads the setppoint
  desiredTemp = param.asFloat();
}
BLYNK_WRITE(V12)
{
  //reads the differential
  tempDiff = param.asFloat();
}
BLYNK_WRITE(V32){
  //reads low alarm
  lowAlarm = param.asFloat();
}
BLYNK_WRITE(V33){
  //reads high alarm
  highAlarm = param.asFloat();
}
void relaysOn()
{
    digitalWrite(relay4Pin, LOW);
    Blynk.virtualWrite(V2, HIGH);
    digitalWrite(relay5Pin, LOW);
    Blynk.virtualWrite(V3, HIGH);
    Blynk.virtualWrite(V6,HIGH);// wavemakers
    Blynk.syncVirtual(V6);  // Trigger the associated function for V6 as if you had touched the widget in the App
}

void take_temp_readings() {
  //Serial.print("Number of Devices found on bus = ");  
  //Serial.println(DS18B20.getDeviceCount());   
  //Serial.print("Getting temperatures... ");  
  //Serial.println();   
 

   
  DS18B20.requestTemperatures();  // Command all devices on bus to read temperature  
  
tanktemp = DS18B20.getTempCByIndex(0);
sumptemp = DS18B20.getTempCByIndex(1);

 
   if (tanktemp == -127.00) 
   {
    Serial.println("Error getting temperature  ");
   } 
  }

    
void send_data_to_blynk()
{
  Blynk.virtualWrite(5, tanktemp); // send tank temp to virtual pin 5
  Blynk.virtualWrite(56, sumptemp);// send sump temp to virtual pin 56
  Serial.println("Data sent to Blynk");
  
   //check alarms;
  if (isnan(tanktemp)){
    if (Blynk.connected() && !faultyProbeFlag)
    {
      Blynk.notify("Probe disconnected");
      Blynk.email("A.bundy1995@hotmail.co.uk", "Aquaruim Controler Alert", "Probe disconnected");
      faultyProbeFlag = true;
    }
  }
  else if (tanktemp < lowAlarm && !tempAlarmFlag){
    Blynk.notify(String(tanktemp) + "ºC Low temp alarm");
    Blynk.email("A.bundy1995@hotmail.co.uk", "Aquaruim Controler Alert", (String(tanktemp) + "ºC Low temp alarm"));
    tempAlarmFlag = true;
  }
  else if (tanktemp > highAlarm && !tempAlarmFlag){
    Blynk.notify(String(tanktemp) + "ºC High temp alarm");
    Blynk.email("A.bundy1995@hotmail.co.uk", "Aquaruim Controler Alert", (String(tanktemp) + "ºC High temp alarm"));
    tempAlarmFlag = true;
  }
  else if (tanktemp > lowAlarm && tanktemp < highAlarm)
  {
    tempAlarmFlag = false;
  }
  else faultyProbeFlag = false;
}

void ATOcontrol()
{
 

  boolean lowWaterState = digitalRead(lowWaterPin);
  boolean highWaterState = digitalRead(highWaterPin);

  if(lowWaterState != lastLowWaterState){
    lastLowWaterDetectTime = currentMillis;
  }


  if (pumpRunning) {  // if the pump is on then let's see if we should turn it off yet

    if ((highWaterState == HIGH) || (currentMillis - lastPumpTime >= maxRunTime)){
      digitalWrite(pumpPin, LOW);
      pumpRunning = false;
      lastPumpTime = currentMillis;
    }
  }
  else {   // pump is not running, see if we need to turn it on

      if((lowWaterState == LOW)  &&  (currentMillis - lastLowWaterDetectTime >= switchDebounceTime) && (currentMillis - lastPumpTime > minOffTime)){   // switch is low and has been for at least 3 seconds
        digitalWrite(pumpPin, HIGH);
        pumpRunning = true;
        lastPumpTime = currentMillis;
      }
  }

  lastLowWaterState = lowWaterState;
}
void Heater()
{
   //if sensor not sending temperature turn relay OFF for safety
  if (isnan(tanktemp)) {
   digitalWrite(relayPin, LOW);
  }
  if ((tanktemp  < desiredTemp - tempDiff ) && (heatersw == 1))
  {
    digitalWrite(relayPin, HIGH);
  }
 
  if (tanktemp > desiredTemp )
  {
    digitalWrite(relayPin, LOW);
  }
}//--(end Heater )---

void Cooler()
{
  if ((tanktemp > desiredTemp - tempDiff ) && (coolingsw == 1))
  {
    digitalWrite(relay2Pin, LOW);
  }
  if (tanktemp < desiredTemp )
  {
    digitalWrite(relay2Pin, HIGH);
  }
  if (tanktemp == -127.00)
  digitalWrite(relay2Pin, HIGH);
}//--(end Cooler )---

// BUTTON INPUTS


BLYNK_WRITE(V3){  // Reactor button off 
 int reactor = param.asInt(); // Get State of Virtual Button, Return pump
  if (reactor == 1) {  // button ON
    // Turn as many pins/relays ON as you need
    digitalWrite(relay5Pin, LOW);
  } else {  // button OFF
    // Turn as many pins/relays OFF as you need
    digitalWrite(relay5Pin, HIGH);
  }
}

BLYNK_WRITE(V2){  // Skimmer button off 
 int skimmer = param.asInt(); // Get State of Virtual Button, Return pump
  if (skimmer == 1) {  // button ON
    // Turn as many pins/relays ON as you need
    digitalWrite(relay4Pin, LOW);
  } else {  // button OFF
    // Turn as many pins/relays OFF as you need
    digitalWrite(relay4Pin, HIGH);
  }
}

BLYNK_WRITE(V1){  // Return pump button off 
 int value = param.asInt(); // Get State of Virtual Button, Return pump
  if (value == 1) {  // button ON
    // Turn as many pins/relays ON as you need
    digitalWrite(relay3Pin, LOW);
    // bt0.setValue(&number5);
    timer.setTimeout(30000, relaysOn);
  } else {  // button OFF
    // Turn as many pins/relays OFF as you need
    digitalWrite(relay3Pin, HIGH);
    digitalWrite(relay4Pin, HIGH);
    Blynk.virtualWrite(V2, LOW);// Skimmer 
    digitalWrite(relay5Pin, HIGH);
    Blynk.virtualWrite(V3, LOW);// Reactor
    Blynk.virtualWrite(V6, LOW);// Wavemakers 
    Blynk.syncVirtual(V6);  // Trigger the associated function for V6 as if you had touched the widget in the App
    Blynk.virtualWrite(V8, LOW);// Heating
    digitalWrite(relayPin, LOW);
    Blynk.virtualWrite(V9, LOW);// Cooling
    Blynk.syncVirtual(V9);
  }
}

BLYNK_WRITE(V38){  // feed button to turn relays off for set time then back on again
 int value = param.asInt(); // Get State of Virtual Button, Return pump
  if (value == 1) {  // button Pressed
    // Turn as many pins/relays OFF as you need
    digitalWrite(relay3Pin, HIGH);
    digitalWrite(relay4Pin, HIGH);
    Blynk.virtualWrite(V2, LOW);// Skimmer 
    digitalWrite(relay5Pin, HIGH);
    Blynk.virtualWrite(V3, LOW);// Reactor
    Blynk.virtualWrite(V6, LOW);// Wavemakers 
    Blynk.syncVirtual(V6);  // Trigger the associated function for V6 as if you had touched the widget in the App
    Blynk.virtualWrite(V8, LOW);// Heating
    digitalWrite(relayPin, LOW);
    Blynk.virtualWrite(V9, LOW);// Cooling
    Blynk.syncVirtual(V9);
    timer.setTimeout(420000L, relaysOn);// wait for 7 mins before turning everything back on.
    Blynk.virtualWrite(V1, HIGH);
    Blynk.syncVirtual(V1);
  }
}
void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);  // start serial port to show results
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
  // run timer every minute to check for led On/Off action
  DS18B20.begin(); // Initialize the Temperature measurement library
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  DS18B20.setResolution(Probe01, 12);
  DS18B20.setResolution(Probe02,12);
pinMode(relayPin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
pinMode(relay3Pin, OUTPUT);
pinMode(relay4Pin, OUTPUT);
pinMode(relay5Pin, OUTPUT);
pinMode(wave1Pin, OUTPUT);
pinMode(wave2Pin, OUTPUT);
pinMode(relay6Pin, OUTPUT);// t5s declaired
pinMode(relay7Pin, OUTPUT);
pinMode(relay8Pin, OUTPUT);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  pinMode(lowWaterPin, INPUT_PULLUP);// ATO
  pinMode(highWaterPin, INPUT_PULLUP);//ATO
  pinMode(pumpPin, OUTPUT);// ATO

///////////////////////////////////////////////////////////////////////////////
  
  Blynk.begin(auth);  // Here your Arduino connects to the Blynk Cloud.  
  timer.setInterval(1000L, take_temp_readings);  // Setup a function to be called every second
  timer.setInterval(5000L, send_data_to_blynk);
  timer.setInterval(1500L, Heater);
  timer.setInterval(1300L, Cooler);
  timer.setInterval(1000L, setLed);
  timer.setInterval(1000L, clockDisplay);     // digital time displayed every second
  timer.setInterval(60000L, activetoday);     // check every minute if schedule should run today
  timer.setInterval(60000L, reconnectBlynk);  // check every 60s if still connected to server
  timer.setInterval(1000L, wavecontrol);
  timer.setInterval(1000L, ATOcontrol);


}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  Blynk.run(); // All the Blynk Magic happens here...
  timer.run(); // Initiates BlynkTimer   
// get the current time, for this time around loop
  // all millis() timer checks will use this time stamp
 unsigned long currentMillis = millis();
 unsigned long currentMillis0 = millis();
  ledFade0(currentMillis0);
  unsigned long currentMillis1 = millis();
  ledFade1(currentMillis1);
}//--(end main loop )---
//*********( THE END )***********

Update, upon testing some more, still have the light dimming issue but I have discovered pin 25 isn’t doing anything. I can control all other 16 relays on the board just by setting a button up directly to a digital pin but pin 25 simply won’t budge :confused: any clues on this is it software of it the arduino toast, I’m starting to think arduino is cooked

You haven’t mentioned the hardware… but I am guessing Arduino Mega, due having a pin 25 :stuck_out_tongue_winking_eye: Only you can determine if the pin is OK by testing with a different sketch.

You are running SimpleTimer but should be running it’s variant BlynkTimer as that is built into the Blynk library.

Your timers are running many simultaneous functions every second, or at varying converging times. They need to be better staggered - search this forum for more on that keyword.

Other than that… we don’t really exist here to read through others really long code to the degree necessary to troubleshoot vague issues as described.

Eg. Library Version? App version, Local or Cloud Server, Are you referring to the Time Input Widget or something else, which vPin if so… and so on… Yes we can probably find out much of this with further digging into your code, but even I have more to life’s goals than that :smiley:

I’m surprised that it ever worked with Blynk. Calling the ledFade1 function from the void loop isn’t the way to do it.

Pete.

Ahh ok but I don’t think it’ll work if I put a time interval on the function. Could you point me in the right direction as to what I should be looking at. I’m still learning but feel I’m close to nailing it. Many thanks
Adam

im really getting myself in a muddle with this, if i put a time funtion to it, the current millis wont work. all sketches i have seen have the current millis in the loop so imstuck as to where i should go with this :confused:

Little update on pin 25. It seems to have killed the relay that was connected to it, the relay dosnt latch any more. But if I plug in another relay in, it triggers it permanently high

Most people use a millis() function to tell if a set period of time has elapsed. The same task can be performed by using a timer library such as Blynk timer. Using the two types of timer together may not work effectively, but it depends on how you code it.
Personally, I can’t think of a situation where both types of timer would be needed together, especially if you use all of the functions available within Blynk timer.

Looking at your code (on a phone, so I’m not getting the full story very easily) you seem to be trying to turn lights on or off st sunrise and sunset, you also have the current time available within your sketch. I’d have expected to see an API call to a service that returns the sunrise/sunset times for your location (updated with a timer every day) then a test every minute or so to see if the sunrise/sunset time has arrived yet.

Pete.

The idea of the sunrise and sunset is at what time to start sunrise and sunset ie dim lights from minimum pwm to value set on slider say 50% brightness. I also have a slider to set the duration, I’m using a time input widget to get a start and stop time and comparing it to nowseconds. Hense the use of Millis

Why not use a Blynk timeout timer instead?

Pete.

The dimming side was taken from a project on here called something like 8 channel led. It was proven to work so I thought I could implement it into my sketch and maybe add to it. I thought I understood what it was doing like I explained above but it’s just not behaving the way it should.

Well following on from pin 25 being stuck high. I discovered I had wired my relays the wrong way round, ie to normally closed instead of normally open. After switching them over, pin now works but 3 others and stuck high -.- this is really strange and now very frustrating, could it be a dead relay board?

I have shared my auth token on here so is it possible someone’s messing me around? How do I change it?

In the App, click through the devices and refresh the Auth, then email it again.

brilliant cheers, iv switched t timerinterval and changed the auth token and everythings running again :smiley: apart from my chart, it only displays one temperature value and not the second data stream set to another virtual pin. Very strange as i have the display of both temperatures on a value widget.

Is Superchart showing live data for both pins?
If it is it means you are sending a string value to the pin that’s not working. Change to a float value.

both temps are set as floats on the mega and im sending the temperater to those pins every 2 seconds. This is why im a little confused.

the chart only shows one datastream but the two value widgets show both temperatures
many thanks.
Adam

No live data for bad pin?

Try removing the bad pin in Superchart and add back a second time.

It works, must have been a glitch or something. Thank you so much :slight_smile:

Could anyone help with my project. I have 2 temperatures displayed using 2 vaule widgets one on V5 and one on V56. if i add these as data streams into a superchart, only they first ine added (V5) is displayed in the chart and not the second one as well. The temperatue values are sent to blynk every 2 seconds.

any adivce would be brilliant.

You’ve now found a solution to this issue in your original topic, but haven’t come back here to opdate this one with that information and mark the topic as closed.
A classic example of why it’s not good to have multiple topics about the same issue!

Pete.