Advice as to why my time inputs stopped working

Appologies for that been super busy. The solution for me was to delete the second data stream and readd it. Also make the chart larger so you can see the change on the chart and add a range for the chart.

Topics have been merged.

back agai with another small issue, i belive the relay that pin25 was connected to had go stuck for some reason. but nowsomething reallly strange is happening, i noticed my temperature was displaying -127 every now and then.

I have narrowed the cause down to pin26. When that pin is set low to trigger the relay, i get the -127 reading but when its set high everything functions as normal.

Iv even turned on every relay execpt the one on pin 26 and the temperature still reads normal. Is there any connection between pin 25, 26 and 48 that my be causing this?

Ok so I swapped out the relay board for a new one. I still get the same result when I set pin 26 low but I don’t seem to get the -127 reading as often. The relay board is a 16ch board but I’m only using one side of it. Relays 1-8. Havnt got round to tested 9-10 yet. The relay connected to pin 26 is relay 5.

Is there anything in the onewire library that effects pin 26? I can’t get my head round why this pin is causing me issues.

Many thanks
Adam

Further investigation shows these new relays are acting the same as they did with the ones. Relay 4 triggers but led is weak, and relay 5 is still giving me the strange reading when set low to activate the relay.

I have 5v and ground connected to the arduino and the 12v supply hooked up. The board has octocoupers and stated it can be used direct with arduino. The previous relay board was the 5v type. Close to giving up with this :confused:

are you using relays to try and dim lights ? That wont work.

Relays are OK for switching AC current on or off but not for dimming, they are not built for rapid switching on and off.

To dim 12V lights with any sizable load, you need to use MOSFETs instead of relays. Depending on the amount of current being switched, you may have to drive the MOSFETs with MOSFET drivers because MOSFETs can only switch small amounts of current with low voltage inputs.

See https://cabin-layout.mixmox.com/2019/01/room-lighting-with-remotesign.html for how I wired 12V lights so that they could be dimmed (and also on/off). The code to do the dimming is exactly the same as test LEDs in a simple blink sketch.

No I’m just switching the power to the leds on. I’m doing the dimming with pwm once the relays are on.

Cheers Adam.

iv tried putting relay 5 in another pin without declairing the pin, this dosnt effect the temperature reading but as soon as i change it in the code, i get -127 again every 2 or 3 readings.

Bleow is my up to date program with the updated dimming which seems to work.


#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[] = "******************************************"; // Put your Auth Token here.
BlynkTimer timer;
WidgetRTC rtc;
WidgetTerminal terminal(V59);
//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 8// 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 = 30;// fuge light
int relay8Pin = 27;// UV
int relay9Pin = 29;// leds relay
int wave1Pin = 47;// Wave maker on ssr2 
int wave2Pin = 46;// Wavemaker 2 on ssr3
///////////////////////////////////////////////////////////////////////////////////
float desiredTemp = 25;// 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
long fadetimemillis = 0;
int minPWM = 0;// variable for min PWM value. keep at 1 to avoid crashing the ledFade()
int leddimming;
int ledbrighten;
int leddimming1;
int ledbrighten1;
byte fadeIncrement = 1; //How smooth to fade? Uses all 4095 steps available.
int fadetime = 0;

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;


#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);
terminal.print("current fade position =");
terminal.println(currentFadePosition0);
terminal.print("current fade position1 =");
terminal.println(currentFadePosition1);


}

void ledbright(){
  
  if (nowseconds > startseconds && nowseconds < stopseconds) {
      currentFadePosition0 = currentFadePosition0 + fadeIncrement;

      if (currentFadePosition0 >= maxPWM0) {
        // At max limit stop the fade
        currentFadePosition0 = maxPWM0;
      }
      // put actionable () here.
      analogWrite(led0, currentFadePosition0);
   
    }
  }

 void leddim(){
  if (nowseconds > stopseconds) 
      currentFadePosition0 = currentFadePosition0 - fadeIncrement;
      if (currentFadePosition0 <= minPWM) {
        // At min limit stop the fade
        currentFadePosition0 = minPWM;
      }
      // put actionable () here
      analogWrite(led0, currentFadePosition0);
    }
void ledbright1(){
  
  if (nowseconds > startseconds && nowseconds < stopseconds) {
      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)
    }
  }

 void leddim1(){
  if (nowseconds > stopseconds) 
      currentFadePosition1 = currentFadePosition1 - fadeIncrement;
      if (currentFadePosition1 <= minPWM) {
        // At min limit stop the fade
        currentFadePosition1 = minPWM;
       Blynk.virtualWrite(V57, LOW);// turns LED relay on
       Blynk.virtualWrite(V58, HIGH);// turns fuge light off
       Blynk.syncVirtual(V58, V57);
      }
      // put actionable () here
      analogWrite(led1, currentFadePosition1);
    }
  

// 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, 255);
}
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, 255);
}

BLYNK_WRITE(V14) {// slider widget to set the led fade duration up tp 3 hours.
  fadetime = param.asInt();
  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){ //fuge relay buton
   int fuge = param.asInt(); // Get State of Virtual Button, fuge
  if (fuge == 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(relay9Pin,LOW);
  }
  else
  {
    digitalWrite(relay9Pin,HIGH);
  }
}

BLYNK_WRITE(V17){ //T5's relay buton
   int tube = param.asInt(); // Get State of Virtual Button, t5s
  if (tube == 1) {
     digitalWrite(relay6Pin,LOW);
  }
  else
  {
    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
      Serial.println("Schedule 1 started");
     Blynk.virtualWrite(V17, HIGH);  // turn on virtual button t5s
     Blynk.syncVirtual(V17);
    }                  
    if(nowseconds >= stopsecond - 31 && nowseconds <= stopsecond + 31 ){   // 62s on 60s timer ensures 1 trigger command is sent
      Serial.println("Schedule 1 finished");
     Blynk.virtualWrite(V17, LOW);   // turn OFF virtual vutton t5s 
     Blynk.syncVirtual(V17);
    }               
  }
}

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
            Serial.println("Schedule 2 started");
           ledbrighten = timer.setTimer(stepWaitTime0, ledbright, maxPWM0);
       ledbrighten1 = timer.setTimer(stepWaitTime1, ledbright1, maxPWM1);
         Blynk.virtualWrite(V57, HIGH);// turns LED relay on
         Blynk.virtualWrite(V58, LOW);// turns fuge light off
           Blynk.syncVirtual(V58, V57);
      
      }
    }
    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
          leddimming = timer.setTimer(stepWaitTime0, leddim, maxPWM0);
            leddimming1 = timer.setTimer(stepWaitTime1, leddim1, maxPWM1);

    }
    }
    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);
      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(); 

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

    
void send_data_to_blynk()
{  tanktemp = DS18B20.getTempCByIndex(0);
  sumptemp = DS18B20.getTempCByIndex(1);
  Blynk.virtualWrite(V5, tanktemp); // send tank temp to virtual pin 5
  Blynk.virtualWrite(V56, 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(V62){  // Skimmer button off 
 int uv = param.asInt(); // Get State of Virtual Button, Return pump
  if (uv == 1) {  // button ON
    // Turn as many pins/relays ON as you need
    digitalWrite(relay8Pin, LOW);
  } else {  // button OFF
    // Turn as many pins/relays OFF as you need
    digitalWrite(relay8Pin, 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
  // 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, 11);
  DS18B20.setResolution(Probe02, 11);    
  DS18B20.setWaitForConversion(false); // make reading NON blocking    
pinMode(relayPin, OUTPUT);
pinMode(relay2Pin, OUTPUT);// Cooling
pinMode(relay3Pin, OUTPUT);//return pump
pinMode(relay4Pin, OUTPUT);// skimmer
pinMode(relay5Pin, OUTPUT);// reactor
pinMode(wave1Pin, OUTPUT);
pinMode(wave2Pin, OUTPUT);
pinMode(relay6Pin, OUTPUT);// t5s declaired
pinMode(relay7Pin, OUTPUT);// Fuge light
pinMode(relay8Pin, OUTPUT);// UV
pinMode(relay9Pin, OUTPUT);// leds relay
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(2500L, 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(1020L, 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(1040L, wavecontrol);
  timer.setInterval(1060L, 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();
}//--(end main loop )---
//*********( THE END )***********

Blynk does have a built in direct GPIO control method, that is totally unnecessary when using virtual pins. Perhaps disabling it will assure there is no conflict.

Add this to your sketch.

#define BLYNK_NO_BUILTIN  // Disable Apps built-in analog & digital pin operations

uploaded with no joy :confused: iv even tried a different virtual pin and still get the same results, the relay that causes the issue will only be on during the night so is there a way i could write in the code to just display last known temp as long as -125 hasnt been send 3 times in a row? as i dont think is dos it any more than 3 times in a row every 5 seconds.

-127 simply means the DS18B20 sensor did not work (invalid signal). That could be due to many reasons, timing, power, questionable sensor, frequent number of sensor readings in short timespan, and so on.

Unsure of the rest of your issues as they seem to have strayed from the OP Time Input (widget?) question to a hardware issue? We cannot troubleshoot your hardware from here.

As for checking number of errors, a simple counter and flagging might work. Or even pre-checking for -127 and NOT sending that result to the App.

I originally thought it was the timer causing the issue, it was only till I got this far I found out. Strangely it seems it’s 240v light I have connected to the relay. Only when it’s plugged in I get the issue with the relay high, strange as the relay is only switching the live to the lights.

so i added a counter for my alarm and that works perfectly. but when I add the following before sending the data, it still sends the data. not sure how to tell it to do nothing if the temp is -127.

void send_data_to_blynk()
{  
  if (tanktemp > -127);
  {
  tanktemp = DS18B20.getTempCByIndex(0);
  }
  if (sumptemp > -127);
  {
  sumptemp = DS18B20.getTempCByIndex(1);
  Blynk.virtualWrite(V5, tanktemp); // send tank temp to virtual pin 5
  Blynk.virtualWrite(V56, sumptemp);// send sump temp to virtual pin 56
  Serial.println("Data sent to Blynk");
  }

Any clues as to how i can do it.

Cheers Adam

Well, you seem to be doing the if test against the old values of the temperatures, then getting new values and sending them directly to Blynk without doing any if test against them.
Is this what you intended?

Pete.

Dohhh. No that wasn’t the intention. It was ment to be the new value so It didn’t get sent to blynk. How could I do it with the new values?

Also iv ordered a capasitor for the temperature probes in hope that will give them cleaner power from the arduino in a hope to cure the issue. Failed that I’ll try a seperate power source.

Cheers.
Adam.

Take the readings from your sensors, then apply the if test before sending the data to Blynk.
You could even try taking a second reading if the if test fails first time around.

I doubt very much if adding a capacitor across the power lines of your DS18B20 sensors will help. In my experience, sporadic -127° readings are usually caused by dodgy wiring.

Pete.

So should I instead of calling the sent_data-to_blynk with a timer, call it when temperature isn’t -127.

Or do I add a flag, so it if temp is -127, I set the flag to false. Then when temp is sent do a if statement followed by flag == true. Then send the temperature?

Also as far as wiring gos, I have tried everything. Reading online about the 16ch relay board, apparently it’s not strictly safe to use because of the way the ocotcouplers are used or something but the 8 channel is, I have a 8 channel on order to test. If It works I’ll just run 2 8 channel boards. I have the 5v and ground connected from the relay board to the arduino, though it’s my understanding the 5v is used to power the arduino (tried with 5v disconnected) and a seperate 12v supply to the relay board.

Only thing left would be the gnd tieing the relay board and arduino together but I havnt tried disconnecting that as I understand it needs to be attached.
Cheers.
Adam.

void send_data_to_blynk() {  
  tanktemp = DS18B20.getTempCByIndex(0);
  if (tanktemp == -127); {
  // Do nothing
} else {
  // do other stuff here based on results
}
1 Like

You should be taking readings from your temperature sensors using a timer, then analysing the results and deciding what to do with the data. If you’re getting a -127° reading you may want to skip sending it to Blynk, or maybe take another reading and repeat the process.

As far as the wiring of your relays is concerned, I think you need to read the spec sheet for your relay boards and decide which approach to take.
You must have shared ground connections back to your Arduino from all the connected devices so that logic level zero means the same thing to each device, and you don’t have differential ground level values.
A shared ground will also help reduce induced noise.

Pete.

cheers Gunner ill put it in pace now :).