Thermostat - relay + DS18B20

I think you will get a lot of disconnect issues
Tell us if that works well.

Disconnection ?

Yes because of your 4 timers at same time.
1000 ms and 5000 ms

Please check if everything is fine.
For pins - D2; D3; D5 - limit switch. D7; D8 - relays; D6 - DS18B20.
Suspends me.

#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D6        // This is the ESP8266 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress tempSensor1 = { 0x28, 0xFF, 0xD5, 0x1B, 0x80, 0x16, 0x05, 0x73 }; // Adres temperatury #1
DeviceAddress tempSensor2 = { 0x28, 0xFF, 0x72, 0x55, 0x80, 0x16, 0x05, 0xE4  }; // Adres temperatury #2
DeviceAddress tempSensor3 = { 0x28, 0xFF, 0x27, 0xF1, 0x85, 0x16, 0x04, 0x6F  }; // Adres temperatury #2
DeviceAddress tempSensor4 = { 0x28, 0xFF, 0x46, 0x5C, 0xB1, 0x16, 0x03, 0x44  }; // Adres temperatury #2

char auth[] = "";  // Kod BLYNK
char ssid[] = "";  // Login WIFI
char pass[] = "";    // Hasło WIFI 

SimpleTimer timer;
int pin = D2; // Pin cyfrowy krancówka
WidgetLED led1(V5); // Pin wirtualny krancowy
int pin2 = D3; // Pin cyfrowy krancówka
WidgetLED led2(V6); // Pin wirtualny krancowy
int pin3 = D5; // Pin cyfrowy krancówka
WidgetLED led3(V7); // Pin wirtualny krancowy 

int tempC1, tempC2, tempC3, tempC4;         // Variables for storing temperatures
BLYNK_CONNECTED() {
    Blynk.syncAll();
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(led1,INPUT);
pinMode(led2,INPUT);
pinMode(led3,INPUT);

  while (Blynk.connect() == false) {
    // Wait until connected
  }

  sensors.begin();
  timer.setInterval(1000L, brama1); //Sprawdzanie stanu
  timer.setInterval(1000L, brama2); //Sprawdzanie stanu
  timer.setInterval(1000L, brama3); //Sprawdzanie stanu
  sensors.setResolution(tempSensor1, 9);   // More on resolutions: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/
  sensors.setResolution(tempSensor2, 9);
  sensors.setResolution(tempSensor3, 9);
  sensors.setResolution(tempSensor4, 9);
  // These timers are used so that data does not flood Blynk
  timer.setInterval(5000L, sendSensor1);  //  Czas pomiaru temperatury #1
  timer.setInterval(5000L, sendSensor2);  //  Czas pomiaru temperatury #2
  timer.setInterval(5000L, sendSensor3);  //  Czas pomiaru temperatury #2
  timer.setInterval(5000L, sendSensor4);  //  Czas pomiaru temperatury #2
}



void sendSensor1() {
  sensors.requestTemperatures();                // Polls the sensors
  tempC1 = sensors.getTempC(tempSensor1);  // C - celsjusza / F - fahrenheita
  Blynk.virtualWrite(V1, tempC1);  // 1 Pin wirtualny 
}

void sendSensor2() 
{
  sensors.requestTemperatures();
  tempC2 = sensors.getTempC(tempSensor2);
  Blynk.virtualWrite(V2, tempC2);  // 2 Pin wirtualny 
}
void sendSensor3() 
{
  sensors.requestTemperatures();
  tempC3 = sensors.getTempC(tempSensor3);
  Blynk.virtualWrite(V3, tempC3);  // 3 Pin wirtualny 
}

void sendSensor4() {
  sensors.requestTemperatures();                // Polls the sensors
  tempC4 = sensors.getTempC(tempSensor4);  // C - celsjusza / F - fahrenheita
  Blynk.virtualWrite(V4, tempC4);  // 1 Pin wirtualny 
}

  void brama1()
{
if(digitalRead(pin) == 1){
  led1.on();
}
else{
  led1.off();
}
}
void brama2()
{
if(digitalRead(pin2) == 1){
  led2.on();
}
else{
  led2.off();
}
}
void brama3()
{
if(digitalRead(pin3) == 1){
  led3.on();
}
else{
  led3.off();
}
}

void loop()
{
  Blynk.run();
  timer.run();
}

What is the reason for this line of code when you are using Blynk.begin?

Pete.

I do not know. I will remove it but it is probably not the cause of the hang?

@tomixps You were already warned about possible disconnections :stuck_out_tongue:

These two groups of timers are all trying to run at the same time respectively, within their identical timeframes… and then every 5 seconds ALL seven timers try to run at the same time.

Probably causing some issue when trying to read multiples of those sensors and pins at the exact same time.

Try staggering the timers…

PS, I merged your two posts together… as they are working on same basic thing :slight_smile:

1 Like

ok i will try to do tomorrow