WIFI temperature level control with set point and hysteresis, DHT22 and relay on/off

Can not adjust the temperature +/- online. I solved the coil to adjust the temperature online.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//#include <SimpleTimer.h>
//SimpleTimer timer;
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "DHT.h" 
DHT dht;
  int sett;
 double settemp;
 double temperature;
 int humidity;
 int Relay1=D7;
 int Relay2=D8;
 int Relay3=D9;
 int Relay4=D10;
 int sensorcurrentCount1,sensorbeforeCount1,sensor_Count1;
 int sensorcurrentCount2,sensorbeforeCount2,sensor_Count2;
 int sensorcurrentCount3,sensorbeforeCount3,sensor_Count3;
byte termometru[8] = //icon for termometer
{
    B00100,
    B01010,
    B01010,
    B01110,
    B01110,
    B11111,
    B11111,
    B01110
};

byte picatura[8] = //icon for water droplet
{
    B00100,
    B00100,
    B01010,
    B01010,
    B10001,
    B10001,
    B10001,
    B01110,
};

char auth[] = "791f0f79e650499b9412ac9daad152ef";

void setup()
{
  Serial.begin(115200);  

   Blynk.begin(auth, "saplai", "123456789");
 //  timer.setInterval(5000L, sendUptime);
  Serial.println();
  Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
  pinMode(Relay1,OUTPUT);
   pinMode(Relay2,OUTPUT);
    pinMode(Relay3,OUTPUT);
     pinMode(Relay4,OUTPUT);
        pinMode(D5,INPUT);
         pinMode(D6,INPUT);
          pinMode(D4,INPUT);
 
 
 
 sett=0;
 sensor_Count1=D4;  
 sensorbeforeCount1=HIGH; 
  sensor_Count2=D6;  
 sensorbeforeCount2=HIGH;
  sensor_Count3=D5;  
 sensorbeforeCount3=HIGH;
       settemp=0;
       lcd.begin();                      // initialize the lcd 
       lcd.begin();
       lcd.backlight();
       lcd.createChar(1,termometru);
       lcd.createChar(2,picatura);
       lcd.setCursor(0,0);
       lcd.write(1);
       lcd.setCursor(7, 0);
       lcd.print("C"); 
       lcd.setCursor(10,0);
      lcd.write(2);
       lcd.setCursor(15,0);
       lcd.print("%");

       lcd.setCursor(0,1);
       lcd.print("S:");
       lcd.setCursor(2,1);
       lcd.write(1);
   digitalWrite(Relay1,LOW);
   digitalWrite(Relay2,LOW);
   digitalWrite(Relay3,LOW);
   digitalWrite(Relay4,LOW);


  dht.setup(D3); //
  temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ
  settemp=29.00;
//  V0=29;
}

void loop()
{  
  
  TEMP();
  SwCounting3(); 
  SwCounting1();
  SwCounting2();
   SwCounting3();
  lcd.setCursor(3,1);
  lcd.print(settemp );
  lcd.setCursor(8, 1);
  lcd.print("C");

   Blynk.setProperty(V7, settemp=settemp+0.1, "ON");
   Blynk.setProperty(V8, settemp=settemp-0.1, "ON");
   set(settemp); 
  lcd.setCursor(3,1);
  lcd.print(settemp );
  lcd.setCursor(8, 1);
  lcd.print("C");
  Blynk.virtualWrite(V5, temperature);
  Blynk.virtualWrite(V6, humidity);
  lcd.createChar(1,termometru);
       lcd.createChar(2,picatura);
       lcd.setCursor(0,0);
       lcd.write(1);
       lcd.setCursor(7, 0);
       lcd.print("C"); 
       lcd.setCursor(10,0);
      lcd.write(2);
       lcd.setCursor(15,0);
       lcd.print("%");
       lcd.setCursor(14,0);
       lcd.print(" ");
       lcd.setCursor(0,1);
       lcd.print("S:");
       lcd.setCursor(2,1);
       lcd.write(1);

     Blynk.run();
}
void TEMP(){        //ชุดคำสั่งอุณหภูมิ
       humidity = dht.getHumidity(); // ดึงค่าความชื้น
       temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ
       lcd.setCursor(12, 0);
       lcd.print(humidity);
       Serial.print(humidity);
       lcd.setCursor(2, 0);
       lcd.print(temperature,2);
       Serial.print(temperature,1);
}

void set(float temp){
    
        if(temperature>=(temp+0.5)){
             lcd.setCursor(10,1);
             lcd.print("TEMP-");
             digitalWrite(Relay1,HIGH);
             digitalWrite(Relay2,HIGH);
             digitalWrite(Relay3,LOW);
             digitalWrite(Relay4,LOW);
        
//lcd.clear();
      WidgetLED led1(V1);
  WidgetLED led2(V2);
  WidgetLED led3(V3);
   led1.on();
   led2.on();
   led3.off();
                         }
  else if(temperature<=(temp-0.5)){
          lcd.setCursor(10,1);
          lcd.print("TEMP+");
          digitalWrite(Relay1,LOW);
          digitalWrite(Relay2,HIGH);
          digitalWrite(Relay3,HIGH); 
          digitalWrite(Relay4,LOW);  
   WidgetLED led1(V1);
  
  WidgetLED led2(V2);
  
  WidgetLED led3(V3);
   led1.off();
   led2.on();
   led3.on();      
 
//lcd.clear();
  }
  else if(temperature==temp){
          digitalWrite(Relay1,LOW);
          digitalWrite(Relay2,LOW);
          digitalWrite(Relay3,LOW);
          digitalWrite(Relay4,LOW);
      WidgetLED led1(V1);
       led1.off();
        WidgetLED led2(V2);
         led2.off();
         WidgetLED led3(V3);
          led3.off();  
          lcd.setCursor(10,1);
          lcd.print("     ");
  }
  }






void SwCounting1(void)
{
    sensorcurrentCount1 = digitalRead(sensor_Count1);                  
   if ((sensorbeforeCount1 !=0 && sensorcurrentCount1==0 ))
    {
      settemp=settemp+0.1;
    }
      sensorbeforeCount1 = sensorcurrentCount1;
}

void SwCounting2(void)
{
    sensorcurrentCount2 = digitalRead(sensor_Count2);                 
   if ((sensorbeforeCount2 !=0 && sensorcurrentCount2==0 ))
    {
      settemp=settemp-0.1;
    }
      sensorbeforeCount2 = sensorcurrentCount2;
}

void SwCounting3(void)
{
    sensorcurrentCount3 = digitalRead(sensor_Count3);                    
   if ((sensorbeforeCount3 !=0 && sensorcurrentCount3==0 ))
    {
     
      if(sett==2){ sett=0;  
         lcd.setCursor(10,1);
          lcd.print("      ");}
          else  sett=sett+1;
   }
      sensorbeforeCount3 = sensorcurrentCount3;
}

Welcome to the Blynk Forum.

You are running too much in your void loop()… you need to move everything except the Blynk.run(); into timer loops or your project will just flood and crash.

http://docs.blynk.cc/#troubleshooting-flood-error

http://docs.blynk.cc/#blynk-firmware-blynktimer

here you go: http://help.blynk.cc/

what i mean is temperatur controlled

oh, OK, try here: Search results for '' - Blynk Community

there is definitely one in there…

1 Like

OK thank you mister… i am find on ESP8266 HVAC control

could you help me, please?
Can not adjust the temperature +/- online. I solved the coil to adjust the temperature online.

Wire.h>

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "DHT.h" 
DHT dht;
  int sett;
 double settemp;
 double temperature;
 int humidity;
 int Relay1=D7;
 int Relay2=D8;
 int Relay3=D9;
 int Relay4=D10;
 int sensorcurrentCount1,sensorbeforeCount1,sensor_Count1;
 int sensorcurrentCount2,sensorbeforeCount2,sensor_Count2;
 int sensorcurrentCount3,sensorbeforeCount3,sensor_Count3;
byte termometru[8] = //icon for termometer
{
    B00100,
    B01010,
    B01010,
    B01110,
    B01110,
    B11111,
    B11111,
    B01110
};

byte picatura[8] = //icon for water droplet
{
    B00100,
    B00100,
    B01010,
    B01010,
    B10001,
    B10001,
    B10001,
    B01110,
};

char auth[] = "791f0f79e650499b9412ac9daad152ef";

void setup()
{
  Serial.begin(115200);  

   Blynk.begin(auth, "saplai", "123456789");
 //  timer.setInterval(5000L, sendUptime);
  Serial.println();
  Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
  pinMode(Relay1,OUTPUT);
   pinMode(Relay2,OUTPUT);
    pinMode(Relay3,OUTPUT);
     pinMode(Relay4,OUTPUT);
        pinMode(D5,INPUT);
         pinMode(D6,INPUT);
          pinMode(D4,INPUT);
 
 
 
 sett=0;
 sensor_Count1=D4;  
 sensorbeforeCount1=HIGH; 
  sensor_Count2=D6;  
 sensorbeforeCount2=HIGH;
  sensor_Count3=D5;  
 sensorbeforeCount3=HIGH;
       settemp=0;
       lcd.begin();                      // initialize the lcd 
       lcd.begin();
       lcd.backlight();
       lcd.createChar(1,termometru);
       lcd.createChar(2,picatura);
       lcd.setCursor(0,0);
       lcd.write(1);
       lcd.setCursor(7, 0);
       lcd.print("C"); 
       lcd.setCursor(10,0);
      lcd.write(2);
       lcd.setCursor(15,0);
       lcd.print("%");

       lcd.setCursor(0,1);
       lcd.print("S:");
       lcd.setCursor(2,1);
       lcd.write(1);
   digitalWrite(Relay1,LOW);
   digitalWrite(Relay2,LOW);
   digitalWrite(Relay3,LOW);
   digitalWrite(Relay4,LOW);


  dht.setup(D3); //
  temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ
  settemp=29.00;
//  V0=29;
}

void loop()
{  
  
  TEMP();
  SwCounting3(); 
  SwCounting1();
  SwCounting2();
   SwCounting3();
  lcd.setCursor(3,1);
  lcd.print(settemp );
  lcd.setCursor(8, 1);
  lcd.print("C");

   Blynk.setProperty(V7, settemp=settemp+0.1, "ON");
   Blynk.setProperty(V8, settemp=settemp-0.1, "ON");
   set(settemp); 
  lcd.setCursor(3,1);
  lcd.print(settemp );
  lcd.setCursor(8, 1);
  lcd.print("C");
  Blynk.virtualWrite(V5, temperature);
  Blynk.virtualWrite(V6, humidity);
  lcd.createChar(1,termometru);
       lcd.createChar(2,picatura);
       lcd.setCursor(0,0);
       lcd.write(1);
       lcd.setCursor(7, 0);
       lcd.print("C"); 
       lcd.setCursor(10,0);
      lcd.write(2);
       lcd.setCursor(15,0);
       lcd.print("%");
       lcd.setCursor(14,0);
       lcd.print(" ");
       lcd.setCursor(0,1);
       lcd.print("S:");
       lcd.setCursor(2,1);
       lcd.write(1);

     Blynk.run();
}
void TEMP(){        //ชุดคำสั่งอุณหภูมิ
       humidity = dht.getHumidity(); // ดึงค่าความชื้น
       temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ
       lcd.setCursor(12, 0);
       lcd.print(humidity);
       Serial.print(humidity);
       lcd.setCursor(2, 0);
       lcd.print(temperature,2);
       Serial.print(temperature,1);
}

void set(float temp){
    
        if(temperature>=(temp+0.5)){
             lcd.setCursor(10,1);
             lcd.print("TEMP-");
             digitalWrite(Relay1,HIGH);
             digitalWrite(Relay2,HIGH);
             digitalWrite(Relay3,LOW);
             digitalWrite(Relay4,LOW);
        
//lcd.clear();
      WidgetLED led1(V1);
  WidgetLED led2(V2);
  WidgetLED led3(V3);
   led1.on();
   led2.on();
   led3.off();
                         }
  else if(temperature<=(temp-0.5)){
          lcd.setCursor(10,1);
          lcd.print("TEMP+");
          digitalWrite(Relay1,LOW);
          digitalWrite(Relay2,HIGH);
          digitalWrite(Relay3,HIGH); 
          digitalWrite(Relay4,LOW);  
   WidgetLED led1(V1);
  
  WidgetLED led2(V2);
  
  WidgetLED led3(V3);
   led1.off();
   led2.on();
   led3.on();      
 
//lcd.clear();
  }
  else if(temperature==temp){
          digitalWrite(Relay1,LOW);
          digitalWrite(Relay2,LOW);
          digitalWrite(Relay3,LOW);
          digitalWrite(Relay4,LOW);
      WidgetLED led1(V1);
       led1.off();
        WidgetLED led2(V2);
         led2.off();
         WidgetLED led3(V3);
          led3.off();  
          lcd.setCursor(10,1);
          lcd.print("     ");
  }
  }






void SwCounting1(void)
{
    sensorcurrentCount1 = digitalRead(sensor_Count1);                  
   if ((sensorbeforeCount1 !=0 && sensorcurrentCount1==0 ))
    {
      settemp=settemp+0.1;
    }
      sensorbeforeCount1 = sensorcurrentCount1;
}

void SwCounting2(void)
{
    sensorcurrentCount2 = digitalRead(sensor_Count2);                 
   if ((sensorbeforeCount2 !=0 && sensorcurrentCount2==0 ))
    {
      settemp=settemp-0.1;
    }
      sensorbeforeCount2 = sensorcurrentCount2;
}

void SwCounting3(void)
{
    sensorcurrentCount3 = digitalRead(sensor_Count3);                    
   if ((sensorbeforeCount3 !=0 && sensorcurrentCount3==0 ))
    {
     
      if(sett==2){ sett=0;  
         lcd.setCursor(10,1);
          lcd.print("      ");}
          else  sett=sett+1;
   }
      sensorbeforeCount3 = sensorcurrentCount3;
}
1 Like

Please do not ask for the same help in multiple posts… I have moved this last post back into your original topic.

1 Like

I will suggest you use av step widget instead of two buttons and get the set temperature into your code with this:

BLYNK_WRITE(V1) {
  setTemp = param.asFloat();
}

please follow this advice from @Gunner, then get back to tell us how it performed, (only once you conform to normal Blynk coding guidelines can anyone really provide more help).

this is all set out in the help section…

1 Like