BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

I want to create a climate control

esp8266
#1

Blynk+esp8266+HTU21D(si70)+relay2
Hello everyone, I want to create a climate control for my orchids, but I am new to working with Arduino IDE and Blynk. At the moment I have experience in creating a meteorological station on esp8266 and a Blynk as well as a Wi-Fi socket. I collected all this on the server blink.
But with the climate control I have trouble, I can’t write the project myself, so I found the one most suitable for my tasks and decided to modify it to fit my hardware. At the moment, the code is completely ready, but the hysteresis unit does not work for me (upon reaching setpoint does not work the relay) For 4 days I have been racking my brains and still can not understand why. I hope for your understanding and support

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <EEPROM.h>
#include <Adafruit_Si7021.h>
#include <SimpleTimer.h>

#define I2C_SCL 5  //d1    
#define I2C_SDA 4  //d2

bool metric = false;
float hum3,  temp5;

uint8_t temppin ; // LOW/HIGH
uint8_t eeprom_temp5 ; // Allow/Disallow
uint8_t min_temp5;
uint8_t max_temp5;
bool flag_temp5_off_state = true;
bool flag_temp5_on_state = true;
uint8_t lastsettemp5;

uint8_t hum3pin ; // LOW/HIGH
uint8_t eeprom_hum3 ; // Allow/Disallow
uint8_t min_hum3;
uint8_t max_hum3;
bool flag_fany_off_state = true;
bool flag_fany_on_state = true;
uint8_t lastm;
uint8_t lastbutton;
uint8_t lastp;
uint8_t lastsethum3;

char auth[] = "9babcd88889420000b8565574b3f1";
char ssid[] = "999";
char pass[] = "000";

Adafruit_Si7021 sensor;
SimpleTimer timer1; // sensor timer
SimpleTimer timer2;  // humcheck
SimpleTimer timer3;  // tempcheck

unsigned long timestamp3;

BLYNK_WRITE(V50) // reset
{
  int pinValue = param.asInt();
  if (pinValue != lastp && pinValue > 0)
  {
    lastp = 0;
    ESP.reset();
  }
}

//---------------------TEMP---------------------------------
BLYNK_WRITE(V19) // write EEPROM temp
{
  int pinValue = param.asInt();
  if (pinValue != lastp && pinValue > 0 && eeprom_temp5 == 1)
  {
    lastp = 0;
    int EEaddress = 164;
    EEPROM.write(EEaddress, min_temp5);
    EEaddress++;
    EEPROM.write(EEaddress, max_temp5);
    EEaddress++;
    EEPROM.write(EEaddress, temppin);
    EEPROM.commit();
    //ESP.reset();
  }
}
BLYNK_WRITE(V25) // eeprom access temp
{
  int pinValue = param.asInt();
  eeprom_temp5 = pinValue;
}
BLYNK_WRITE(V26) // level temp
{
  int pinValue = param.asInt();
  temppin = pinValue;
}

BLYNK_WRITE(V20) // setup temp
{
  int pinValue = param.asInt();
  lastsettemp5 = pinValue;
}
BLYNK_WRITE(V21) // temp down
{
  int pinValue = param.asInt();
  if (lastsettemp5 == 1)
  {
    if (pinValue != lastp && pinValue > 0 && min_temp5 > 0)
    {
      lastp = 0;
      min_temp5--;
      Blynk.virtualWrite(V23, min_temp5);
    }
  }

  if (lastsettemp5 == 0)
  {
    if (pinValue != lastp && pinValue > 0 && max_temp5 - min_temp5 > 1)
    {
      lastp = 0;
      max_temp5--;
      Blynk.virtualWrite(V24, max_temp5);
    }
  }
}
BLYNK_WRITE(V22) // temp up
{
  int pinValue = param.asInt();
  if (lastsettemp5 == 1)
  {
    if (pinValue != lastp && pinValue > 0 && max_temp5 - min_temp5 > 1)
    {
      lastp = 0;
      min_temp5++;
      Blynk.virtualWrite(V23, min_temp5);
    }
  }

  if (lastsettemp5 == 0)
  {
    if (pinValue != lastp && pinValue > 0 && max_temp5 < 100)
    {
      lastp = 0;
      max_temp5++;
      Blynk.virtualWrite(V24, max_temp5);
    }
  }
}
//---------------------TEMP END-----------------------------

//---------------------HUM---------------------------------
BLYNK_WRITE(V13) // write EEPROM hum
{
  int pinValue = param.asInt();
  if (pinValue != lastp && pinValue > 0 && eeprom_hum3 == 1)
  {
    lastp = 0;
    int EEaddress = 161;
    EEPROM.write(EEaddress, min_hum3);
    EEaddress++;
    EEPROM.write(EEaddress, max_hum3);
    EEaddress++;
    EEPROM.write(EEaddress, hum3pin);
    EEPROM.commit();
    //ESP.reset();
  }
}
BLYNK_WRITE(V9) // eeprom access hum
{
  int pinValue = param.asInt();
  eeprom_hum3 = pinValue;
}
BLYNK_WRITE(V12) // level hum
{
  int pinValue = param.asInt();
  hum3pin = pinValue;
}

BLYNK_WRITE(V14) // setup hum
{
  int pinValue = param.asInt();
  lastsethum3 = pinValue;
}
BLYNK_WRITE(V15) // hum down
{
  int pinValue = param.asInt();
  if (lastsethum3 == 1)
  {
    if (pinValue != lastp && pinValue > 0 && min_hum3 > 0)
    {
      lastp = 0;
      min_hum3--;
      Blynk.virtualWrite(V16, min_hum3);
    }
  }

  if (lastsethum3 == 0)
  {
    if (pinValue != lastp && pinValue > 0 && max_hum3 - min_hum3 > 1)
    {
      lastp = 0;
      max_hum3--;
      Blynk.virtualWrite(V18, max_hum3);
    }
  }
}
BLYNK_WRITE(V17) // hum up
{
  int pinValue = param.asInt();
  if (lastsethum3 == 1)
  {
    if (pinValue != lastp && pinValue > 0 && max_hum3 - min_hum3 > 1)
    {
      lastp = 0;
      min_hum3++;
      Blynk.virtualWrite(V16, min_hum3);
    }
  }

  if (lastsethum3 == 0)
  {
    if (pinValue != lastp && pinValue > 0 && max_hum3 < 100)
    {
      lastp = 0;
      max_hum3++;
      Blynk.virtualWrite(V18, max_hum3);
    }
  }
}
//---------------------HUM END-----------------------------
void tempcheck()
{
  if (temp5 <= min_temp5 && flag_temp5_on_state)
  {
    if (temppin == 1 )
    {
      digitalWrite(15, LOW); //  вкл
      Blynk.virtualWrite(V27, 1023); //  вкл
      Blynk.virtualWrite(V28, 0); //  выкл
    } else {
      digitalWrite(15, HIGH); //  выкл
      Blynk.virtualWrite(V27, 0); //  выкл
      Blynk.virtualWrite(V28, 1023); //  вкл
    }
    digitalWrite(15, LOW); //  вкл
    Blynk.virtualWrite(V10, 1023); //  вкл
    flag_temp5_on_state = false;
    flag_temp5_off_state = true;
  }

  if (temp5 >= max_temp5 && flag_temp5_off_state)
  {
    if (temppin == 1 )
    {
      digitalWrite(15, HIGH); //  вкл
      Blynk.virtualWrite(V27, 0); //  вкл
      Blynk.virtualWrite(V28, 1023); //  выкл
    } else {
      digitalWrite(15, LOW); //  выкл
      Blynk.virtualWrite(V27, 1023); //  выкл
      Blynk.virtualWrite(V28, 0); //  выкл
    }

    digitalWrite(15, HIGH); //  выкл
    Blynk.virtualWrite(V10, 0); //  выкл
    flag_temp5_off_state = false;
    flag_temp5_on_state = true;
  }
}

void humcheck()
{
  if (hum3 <= min_hum3 && flag_fany_on_state)
  {
    if (hum3pin == 1 )
    {
      digitalWrite(13, LOW); //  вкл
      Blynk.virtualWrite(V10, 1023); //  вкл
      Blynk.virtualWrite(V11, 0); //  выкл
    } else {
      digitalWrite(13, HIGH); //  выкл
      Blynk.virtualWrite(V10, 0); //  выкл
      Blynk.virtualWrite(V11, 1023); //  выкл
    }
    digitalWrite(13, LOW); // увлажнитель вкл
    Blynk.virtualWrite(V10, 1023); // увлажнитель вкл
    flag_fany_on_state = false;
    flag_fany_off_state = true;
  }

  if (hum3 >= max_hum3 && flag_fany_off_state)
  {
    if (hum3pin == 0 )
    {
      digitalWrite(13, HIGH); //  вкл
      Blynk.virtualWrite(V10, 0); //  вкл
      Blynk.virtualWrite(V11, 1023); //  выкл
    } else {
      digitalWrite(13, LOW); //  выкл
      Blynk.virtualWrite(V10, 1023); //  выкл
      Blynk.virtualWrite(V11, 0); //  выкл
    }
    digitalWrite(13, HIGH); // увлажнитель выкл
    Blynk.virtualWrite(V10, 0); // увлажнитель выкл
    flag_fany_off_state = false;
    flag_fany_on_state = true;
  }
}

void sendSensor1()
{
  float temp5 = sensor.readTemperature();
  float hum3 = sensor.readHumidity();
  Blynk.virtualWrite(V3, hum3);
  Blynk.virtualWrite(V5, temp5);
}

void readEEPROM(int startAdr, int maxLength, char* dest)
{
  EEPROM.begin(256);
  delay(10);
  for (int i = 0; i < maxLength; i++)
  {
    dest[i] = char(EEPROM.read(startAdr + i));
  }
  EEPROM.end();
}
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  Wire.begin(I2C_SDA, I2C_SCL);
  EEPROM.begin(256);
  min_hum3 = EEPROM.read(161);
  max_hum3 = EEPROM.read(162);
  hum3pin = EEPROM.read(163);
  min_temp5 = EEPROM.read(164);
  max_temp5 = EEPROM.read(165);
  temppin = EEPROM.read(166);

  timer1.setInterval(1500L, sendSensor1);
  timer2.setInterval(500L, humcheck);
  timer3.setInterval(500L, tempcheck);

  pinMode(13, OUTPUT); // увлажнитель
  digitalWrite(13, HIGH); // увлажнитель выкл
  pinMode(15, OUTPUT); //
  digitalWrite(15, HIGH); //

  Blynk.virtualWrite(V16, min_hum3);
  Blynk.virtualWrite(V18, max_hum3);
  Blynk.virtualWrite(V24, max_temp5);
  Blynk.virtualWrite(V23, min_temp5);

  if (min_hum3 <= 30 ||  min_hum3 >= 99 || max_hum3 <= 30 ||  max_hum3 >= 99) {
    min_hum3 = 45;
    max_hum3 = 50;
  }
  if (min_temp5 <= 0 ||  min_temp5 >= 99 || max_temp5 <= 0 ||  max_temp5 >= 99) {
    min_temp5 = 20;
    max_temp5 = 25;
  }
  if (!sensor.begin())
  {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
}

void loop()
{
  timer1.run();
  timer2.run();
  timer3.run();
  Blynk.run();
}



0 Likes

#2

Reduce this to one timer with three instances (each BlynkTimer can have up to 16)… better memory management and performance that way

Sorry, no idea on the hysteresis bit… that would take more thinking power then I have available right now :stuck_out_tongue:

1 Like

#3

Just taking a quick glance at the code. This function is using temp5,

void tempcheck()
{
 if (temp5 <= min_temp5 && flag_temp5_on_state)
 {

but

void sendSensor1()
{
  float temp5 = sensor.readTemperature();
  float hum3 = sensor.readHumidity();
  Blynk.virtualWrite(V3, hum3);
  Blynk.virtualWrite(V5, temp5);
}

temp5 is declared as a local variable, not global.

Same for humidity.

0 Likes

#4

Scratch that I see them declared as global at the top.

float hum3,  temp5;

Maybe remove the second declaration in the sendSensor1 function.

void sendSensor1()
{
   temp5 = sensor.readTemperature();
   hum3 = sensor.readHumidity();
  Blynk.virtualWrite(V3, hum3);
  Blynk.virtualWrite(V5, temp5);
}
1 Like

#5

Гистерезис это хорошо, но в данной ситуации не вижу смысла его использовать когда можно просто увеличить время проверки температуры и влажности, потом одним if задать рамки включения. совет на будущее

1 Like

#6

Yea, your advice helped solve the problem.
This is because shortage of experience in C :thinking:

0 Likes

#7

looks like a good start, but have a think about incorporating “dewpoint” as an input as well as (or instead of) raw humidity…

0 Likes

#8

Hi Dave1829.I read the paper that you laid out at the dew point. This is a really great idea that will help solve many problems. I also read code examples for my hardware (HTU21D), and I think that my skill is not enough to create such solutions. But I will set myself this task

0 Likes

#9

my simple dew point calculation to all my climate code is this:

double dewPoint(double celsius, double humidity)
{
 // (1) Saturation Vapor Pressure = ESGG(T)
 double RATIO = 373.15 / (273.15 + celsius);
 double RHS = -7.90298 * (RATIO - 1);
 RHS += 5.02808 * log10(RATIO);
 RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1 / RATIO ))) - 1) ;
 RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
 RHS += log10(1013.246);

// factor -3 is to adjust units - Vapor Pressure SVP * humidity

double VP = pow(10, RHS - 3) * humidity;

// (2) DEWPOINT = F(Vapor Pressure)

double T = log(VP / 0.61078); // temp var
return (241.88 * T) / (17.558 - T);
}

so then add

          yourSensorName**DewPoint** = dewPoint(yourSensorName**Temp,** yourSensorName**Hum**);

into your

void sendSensor1()

function :slight_smile:

i think dewpoint function was originally ‘obtained’ from here: https://forum.arduino.cc/index.php?topic=333969.0

0 Likes

#10

Hello guys. Thank you to everyone who helped me. At the moment it’s done: Fixed a bug with (float temp5) (Thanks to Toro_Blanco). Free Loop from timers (Thanks to Gunner). And in order to save your nerves, suffered a pin relay with gpio15 to gpio12. In the near future, I plan to add a time relay for the light and the cooler (if it works out with the schedule for the week :crazy_face:) and also think about how to rewrite the code under the dew point (Thanks to Dave)

#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <EEPROM.h>
#include <Adafruit_Si7021.h>
#include <SimpleTimer.h>

#define I2C_SCL 5  //d1    
#define I2C_SDA 4  //d2
#define relay1 13
#define relay2 12

bool metric = false;

float hum3, temp5;
uint8_t temppin ; // LOW/HIGH
uint8_t eeprom_temp5 ; // Allow/Disallow
uint8_t min_temp5;
uint8_t max_temp5;
bool flag_temp5_off_state = true;
bool flag_temp5_on_state = true;
uint8_t lastsettemp5;

uint8_t hum3pin ; // LOW/HIGH
uint8_t eeprom_hum3 ; // Allow/Disallow
uint8_t min_hum3;
uint8_t max_hum3;
bool flag_fany_off_state = true;
bool flag_fany_on_state = true;
uint8_t lastm;
uint8_t lastbutton;
uint8_t lastp;
uint8_t lastsethum3;

char auth[] = "9babcd14a5f9423fb00000000";
char ssid[] = "MK0000";
char pass[] = "fre0004";//

unsigned long timestamp3;

Adafruit_Si7021 sensor;
BlynkTimer timer;

BLYNK_WRITE(V50) // reset
{
  int pinValue = param.asInt();
  if (pinValue != lastp && pinValue > 0)
  {
    lastp = 0;
    ESP.reset();
  }
}
//---------------------TEMP---------------------------------
BLYNK_WRITE(V19) // write EEPROM temp
{
  int pinValue = param.asInt();
  if (pinValue != lastp && pinValue > 0 && eeprom_temp5 == 1)
  {
    lastp = 0;
    int EEaddress = 164;
    EEPROM.write(EEaddress, min_temp5);
    EEaddress++;
    EEPROM.write(EEaddress, max_temp5);
    EEaddress++;
    EEPROM.write(EEaddress, temppin);
    EEPROM.commit();
    //ESP.reset();
  }
}
BLYNK_WRITE(V25) // eeprom access temp
{
  int pinValue = param.asInt();
  eeprom_temp5 = pinValue;
}
BLYNK_WRITE(V26) // level temp
{
  int pinValue = param.asInt();
  temppin = pinValue;
}

BLYNK_WRITE(V20) // setup temp
{
  int pinValue = param.asInt();
  lastsettemp5 = pinValue;
}
BLYNK_WRITE(V21) // temp down
{
  int pinValue = param.asInt();
  if (lastsettemp5 == 1)
  {
    if (pinValue != lastp && pinValue > 0 && min_temp5 > 0)
    {
      lastp = 0;
      min_temp5--;
      Blynk.virtualWrite(V23, min_temp5);
    }
  }
  if (lastsettemp5 == 0)
  {
    if (pinValue != lastp && pinValue > 0 && max_temp5 - min_temp5 > 1)
    {
      lastp = 0;
      max_temp5--;
      Blynk.virtualWrite(V24, max_temp5);
    }
  }
}
BLYNK_WRITE(V22) // temp up
{
  int pinValue = param.asInt();
  if (lastsettemp5 == 1)
  {
    if (pinValue != lastp && pinValue > 0 && max_temp5 - min_temp5 > 1)
    {
      lastp = 0;
      min_temp5++;
      Blynk.virtualWrite(V23, min_temp5);
    }
  }
  if (lastsettemp5 == 0)
  {
    if (pinValue != lastp && pinValue > 0 && max_temp5 < 100)
    {
      lastp = 0;
      max_temp5++;
      Blynk.virtualWrite(V24, max_temp5);
    }
  }
}
//---------------------TEMP END-----------------------------

//---------------------HUM---------------------------------
BLYNK_WRITE(V13) // write EEPROM hum
{
  int pinValue = param.asInt();
  if (pinValue != lastp && pinValue > 0 && eeprom_hum3 == 1)
  {
    lastp = 0;
    int EEaddress = 161;
    EEPROM.write(EEaddress, min_hum3);
    EEaddress++;
    EEPROM.write(EEaddress, max_hum3);
    EEaddress++;
    EEPROM.write(EEaddress, hum3pin);
    EEPROM.commit();
    //ESP.reset();
  }
}
BLYNK_WRITE(V9) // eeprom access hum
{
  int pinValue = param.asInt();
  eeprom_hum3 = pinValue;
}
BLYNK_WRITE(V12) // level hum
{
  int pinValue = param.asInt();
  hum3pin = pinValue;
}

BLYNK_WRITE(V14) // setup hum
{
  int pinValue = param.asInt();
  lastsethum3 = pinValue;
}
BLYNK_WRITE(V15) // hum down
{
  int pinValue = param.asInt();
  if (lastsethum3 == 1)
  {
    if (pinValue != lastp && pinValue > 0 && min_hum3 > 0)
    {
      lastp = 0;
      min_hum3--;
      Blynk.virtualWrite(V16, min_hum3);
    }
  }
  if (lastsethum3 == 0)
  {
    if (pinValue != lastp && pinValue > 0 && max_hum3 - min_hum3 > 1)
    {
      lastp = 0;
      max_hum3--;
      Blynk.virtualWrite(V18, max_hum3);
    }
  }
}
BLYNK_WRITE(V17) // hum up
{
  int pinValue = param.asInt();
  if (lastsethum3 == 1)
  {
    if (pinValue != lastp && pinValue > 0 && max_hum3 - min_hum3 > 1)
    {
      lastp = 0;
      min_hum3++;
      Blynk.virtualWrite(V16, min_hum3);
    }
  }
  if (lastsethum3 == 0)
  {
    if (pinValue != lastp && pinValue > 0 && max_hum3 < 100)
    {
      lastp = 0;
      max_hum3++;
      Blynk.virtualWrite(V18, max_hum3);
    }
  }
}
//---------------------HUM END-----------------------------
void tempcheck()
{
  if (temp5 <= min_temp5 && flag_temp5_on_state)
  {
    if (temppin == 1 )
    {
      digitalWrite(12, LOW); //  вкл
      Blynk.virtualWrite(V27, 1023); //  вкл
      Blynk.virtualWrite(V28, 0); //  выкл
    } else {
      digitalWrite(12, HIGH); //  выкл
      Blynk.virtualWrite(V27, 0); //  выкл
      Blynk.virtualWrite(V28, 1023); //  вкл
    }
    //digitalWrite(12, LOW); //  вкл
    //Blynk.virtualWrite(V10, 1023); //  вкл
    flag_temp5_on_state = false;
    flag_temp5_off_state = true;
  }
  if (temp5 >= max_temp5 && flag_temp5_off_state)
  {
    if (temppin == 1 )
    {
      digitalWrite(12, HIGH); //  вкл
      Blynk.virtualWrite(V27, 0); //  вкл
      Blynk.virtualWrite(V28, 1023); //  выкл
    } else {
      digitalWrite(12, LOW); //  выкл
      Blynk.virtualWrite(V27, 1023); //  выкл
      Blynk.virtualWrite(V28, 0); //  выкл
    }

    //digitalWrite(12, HIGH); //  выкл
    //Blynk.virtualWrite(V10, 0); //  выкл
    flag_temp5_off_state = false;
    flag_temp5_on_state = true;
  }
}

void humcheck()
{
  if (hum3 <= min_hum3 && flag_fany_on_state)
  {
    if (hum3pin == 1 )
    {
      digitalWrite(13, LOW); //  вкл
      Blynk.virtualWrite(V10, 1023); //  вкл
      Blynk.virtualWrite(V11, 0); //  выкл
    } else {
      digitalWrite(13, HIGH); //  выкл
      Blynk.virtualWrite(V10, 0); //  выкл
      Blynk.virtualWrite(V11, 1023); //  выкл
    }
    //digitalWrite(13, LOW); // увлажнитель вкл
    //Blynk.virtualWrite(V10, 1023); // увлажнитель вкл
    flag_fany_on_state = false;
    flag_fany_off_state = true;
  }
  if (hum3 >= max_hum3 && flag_fany_off_state)
  {
    if (hum3pin == 1 )
    {
      digitalWrite(13, HIGH); //  вкл
      Blynk.virtualWrite(V10, 0); //  вкл
      Blynk.virtualWrite(V11, 1023); //  выкл
    } else {
      digitalWrite(13, LOW); //  выкл
      Blynk.virtualWrite(V10, 1023); //  выкл
      Blynk.virtualWrite(V11, 0); //  выкл
    }
    //digitalWrite(13, HIGH); // увлажнитель выкл
    //Blynk.virtualWrite(V10, 0); // увлажнитель выкл
    flag_fany_off_state = false;
    flag_fany_on_state = true;
  }
}

void sendSensor1()
{
  temp5 = sensor.readTemperature();
  hum3 = sensor.readHumidity();
  Blynk.virtualWrite(V3, hum3);
  Blynk.virtualWrite(V5, temp5);
}

void readEEPROM(int startAdr, int maxLength, char* dest)
{
  EEPROM.begin(256);
  delay(10);
  for (int i = 0; i < maxLength; i++)
  {
    dest[i] = char(EEPROM.read(startAdr + i));
  }
  EEPROM.end();
}
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  Wire.begin(I2C_SDA, I2C_SCL);
  EEPROM.begin(256);
  min_hum3 = EEPROM.read(161);
  max_hum3 = EEPROM.read(162);
  hum3pin = EEPROM.read(163);
  min_temp5 = EEPROM.read(164);
  max_temp5 = EEPROM.read(165);
  temppin = EEPROM.read(166);

  timer.setInterval(333L, sendSensor1);
  timer.setInterval(500L, humcheck);
  timer.setInterval(444L, tempcheck);

  pinMode(13, OUTPUT); // увлажнитель
  digitalWrite(13, LOW); // 
  pinMode(12, OUTPUT); // нагреватель
  digitalWrite(12, LOW); //

  Blynk.virtualWrite(V16, min_hum3);
  Blynk.virtualWrite(V18, max_hum3);
  Blynk.virtualWrite(V24, max_temp5);
  Blynk.virtualWrite(V23, min_temp5);

  if (min_hum3 <= 30 ||  min_hum3 >= 99 || max_hum3 <= 30 ||  max_hum3 >= 99) {
    min_hum3 = 45;
    max_hum3 = 50;
  }
  if (min_temp5 <= 0 ||  min_temp5 >= 99 || max_temp5 <= 0 ||  max_temp5 >= 99) {
    min_temp5 = 20;
    max_temp5 = 25;
  }
  if (!sensor.begin())
  {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
}

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

And lastly, I do not know whether to close the topic or leave, since the project is not over yet?

1 Like

#11

Hello guys, I gradually study the time entry widget for lighting, and thanks to the information on the forum, there are almost no questions. Today I would like to ask for help what would be the best way to use and to run the cooler every 30 minutes for 10 minutes. Do I need to use the timer for a millise or is there something more correct?

0 Likes

#12

На твоё усмотрение, но мне лично нравиться задать таймер в 1 секунду и функция в которой switch(i++), позволяет легко задавать временные рамки по переменной i с помощью case, кода мало читать легко.

1 Like