Help I need to pause and I don't know how

I want to pause since I send an alert x the email I want 10 min to pass for the next email and I don’t know how … there I pass my code to see if someone can help me


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dwRN53LZ53EhCY59wk9O6EstwM1Ws0zL";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pablo y Maca 2.4";
char pass[] = "laputaclave";

#define DHTPIN 14          // What digital pin we're connected to
#define relay1 12


// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
WidgetLED led2(V3);

void setup()
{
  // Debug console
  Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
lcd.setCursor (0,0);
 lcd.begin(16,2);
  lcd.init();
lcd.backlight();
lcd.print ("Conectando ... ");
lcd.setCursor (0,1);
lcd.print ("  Red Wifi ... ");
delay(2000);
  Blynk.begin(auth, ssid, pass);
  delay(200);
  lcd.clear ();
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();
lcd.setCursor (0,0);
lcd.backlight();
lcd.print ("Conectado con.. ");
lcd.setCursor (0,1);
lcd.print("IP:");
lcd.print( WiFi.localIP() );
delay(5000);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Bienvenido .. ");
lcd.setCursor (3,1);
lcd.print("Iniciando ...");
delay(5000);


lcd.clear();
  // Setup a function to be called every second
  timer.setInterval(2000, sendSensor);
  timer.setInterval(61000, sendTemps);    // Temperature sensor read interval. 2000 (ms) = 2 seconds. 
  
  }  


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
    Blynk.virtualWrite(V5, h);
    Blynk.virtualWrite(V6, t);
    lcd.setCursor(0,1);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print("c");
    lcd.setCursor(0,0);
    lcd.print("Humedad: ");
    lcd.print(h);
    lcd.print("%");

 if (digitalRead(relay1) == HIGH){  // Si se activa interruptor
      led2.on();     // Pause de 1 segundo 
        }
      else if (digitalRead(relay1) == LOW) {
       led2.off();       // Pausa de 1 segundo 
   } 


 }

void sendTemps()
{
 
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit  

if (t > 28) {
digitalWrite(relay1, HIGH);
led2.on();
}
else if (t <= 28) {
digitalWrite(relay1, LOW);
led2.off();

}
if (t >= 30) {
  Blynk.email("maugerijuan@gmail.com", "Temperatura Blynk ALERTA !! ", "Temperatura superior a 31º ATENCION !!");

}
}


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

Search the forum for “lambda timeout timer”

Pete.

Thank you very much Pete … but anyway you send me an email every minute and I want you to send me one every 10 minutes … I happen to you as I did …

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dwRN53LZ53EhCY59wk9O6EstwM1Ws0zL";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pablo y Maca 2.4";
char pass[] = "laputaclave";

#define DHTPIN 14          // What digital pin we're connected to
#define relay1 12


// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
WidgetLED led2(V3);

void setup()
{
  // Debug console
  Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
lcd.setCursor (0,0);
 lcd.begin(16,2);
  lcd.init();
lcd.backlight();
lcd.print ("Conectando ... ");
lcd.setCursor (0,1);
lcd.print ("  Red Wifi ... ");
delay(2000);
  Blynk.begin(auth, ssid, pass);
  delay(200);
  lcd.clear ();
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();
lcd.setCursor (0,0);
lcd.backlight();
lcd.print ("Conectado con.. ");
lcd.setCursor (0,1);
lcd.print("IP:");
lcd.print( WiFi.localIP() );
delay(5000);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Bienvenido .. ");
lcd.setCursor (3,1);
lcd.print("Iniciando ...");
delay(5000);


lcd.clear();
  // Setup a function to be called every second
  timer.setInterval(2000, sendSensor);
  timer.setInterval(61000, sendTemps);    // Temperature sensor read interval. 2000 (ms) = 2 seconds. 
  
  }  


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
    Blynk.virtualWrite(V5, h);
    Blynk.virtualWrite(V6, t);
    lcd.setCursor(0,1);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print("c");
    lcd.setCursor(0,0);
    lcd.print("Humedad: ");
    lcd.print(h);
    lcd.print("%");

 if (digitalRead(relay1) == HIGH){  // Si se activa interruptor
      led2.on();     // Pause de 1 segundo 
        }
      else if (digitalRead(relay1) == LOW) {
       led2.off();       // Pausa de 1 segundo 
   } 


 }

void sendTemps()
{
 
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit  

if (t > 28) {
digitalWrite(relay1, HIGH);
led2.on();
}
else if (t <= 28) {
digitalWrite(relay1, LOW);
led2.off();

}
if (t >= 25) {
  timer.setTimeout(600000, []() 
  { 
  Blynk.email("maugerijuan@gmail.com", "Temperatura Blynk ALERTA !! ", "Temperatura superior a 31º ATENCION !!");
      });  // END of Lambda Function
 
}
}

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

You need to use the lambda timer to clear a flag. If the flag is not set then send a notification.

Pete.

this way it was easier for me … it would be wrong if I do it like this … I know I call float t = dht.readTemperature () many times; would it be wrong this way? sorry but thank you very much in advance…

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dwRN53LZ53EhCY59wk9O6EstwM1Ws0zL";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pablo y Maca 2.4";
char pass[] = "laputaclave";

#define DHTPIN 14          // What digital pin we're connected to
#define relay1 12


// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
WidgetLED led2(V3);

void setup()
{
  // Debug console
  Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
lcd.setCursor (0,0);
 lcd.begin(16,2);
  lcd.init();
lcd.backlight();
lcd.print ("Conectando ... ");
lcd.setCursor (0,1);
lcd.print ("  Red Wifi ... ");
delay(2000);
  Blynk.begin(auth, ssid, pass);
  delay(200);
  lcd.clear ();
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();
lcd.setCursor (0,0);
lcd.backlight();
lcd.print ("Conectado con.. ");
lcd.setCursor (0,1);
lcd.print("IP:");
lcd.print( WiFi.localIP() );
delay(5000);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Bienvenido .. ");
lcd.setCursor (3,1);
lcd.print("Iniciando ...");
delay(5000);


lcd.clear();
  // Setup a function to be called every second
  timer.setInterval(2000, sendSensor);
  timer.setInterval(61000, sendTemps);    // Temperature sensor read interval. 2000 (ms) = 2 seconds. 
  timer.setInterval(600000, estados);
  }  


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
    Blynk.virtualWrite(V5, h);
    Blynk.virtualWrite(V6, t);
    lcd.setCursor(0,1);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print("c");
    lcd.setCursor(0,0);
    lcd.print("Humedad: ");
    lcd.print(h);
    lcd.print("%");

 if (digitalRead(relay1) == HIGH){  // Si se activa interruptor
      led2.on();     // Pause de 1 segundo 
        }
      else if (digitalRead(relay1) == LOW) {
       led2.off();       // Pausa de 1 segundo 
   } 


 }

void sendTemps()
{
 
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit  

if (t > 28) {
digitalWrite(relay1, HIGH);
led2.on();
}
else if (t <= 28) {
digitalWrite(relay1, LOW);
led2.off();


 
}
}

void estados (){
  
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit 
 
if (t >= 31) {
  
  Blynk.email("maugerijuan@gmail.com", "Temperatura Blynk ALERTA !! ", "Temperatura superior a 31º ATENCION !!");
     
}
}
void loop()
{
  Blynk.run();
  timer.run();
}

So many things wrong with this that you’d be better starting again.

Pete.

Excuse me, is this better? anyway I don’t get the emails …

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dwRN53LZ53EhCY59wk9O6EstwM1Ws0zL";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pablo y Maca 2.4";
char pass[] = "laputaclave";

#define DHTPIN 14          // What digital pin we're connected to
#define relay1 12

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
WidgetLED led2(V3);

void setup()
{
  // Debug console
Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
lcd.setCursor (0,0);
 lcd.begin(16,2);
  lcd.init();
lcd.backlight();
lcd.print ("Conectando ... ");
lcd.setCursor (0,1);
lcd.print ("  Red Wifi ... ");
delay(200);
  Blynk.begin(auth, ssid, pass);
  delay(200);
  lcd.clear ();
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();
lcd.setCursor (0,0);
lcd.backlight();
lcd.print ("Conectado con.. ");
lcd.setCursor (0,1);
lcd.print("IP:");
lcd.print( WiFi.localIP() );
delay(5000);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Bienvenido .. ");
lcd.setCursor (3,1);
lcd.print("Iniciando ...");
delay(3000);


lcd.clear();
  // Setup a function to be called every second
  timer.setInterval(2000, sendSensor);
  }  


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

   if (digitalRead(relay1) == HIGH){  // Si se activa interruptor
      led2.on();     // Pause de 1 segundo 
        }
   else if (digitalRead(relay1) == LOW) {
    led2.off();       // Pausa de 1 segundo 
   } 
  
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
    Blynk.virtualWrite(V5, h);
    Blynk.virtualWrite(V6, t);
    lcd.setCursor(0,1);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print("c");
    lcd.setCursor(0,0);
    lcd.print("Humedad: ");
    lcd.print(h);
    lcd.print("%");
  

int tempmax = 27; 
int tempmin = 26;
int tempalert = 31;
 
if (t >= tempmax) {

timer.setInterval (61000, []() 
  { 

digitalWrite(relay1, HIGH);
led2.on(); 
});
}

else if (t <= tempmin) {
digitalWrite(relay1, LOW);
led2.off();
}

else if (t <= tempalert) {

timer.setInterval (61000, []() 
  { 
 Blynk.email("maugerijuan@gmail.com", "Temperatura Blynk ALERTA !! ", "Temperatura superior a 31º ATENCION !!");
});
}

}
void loop()

{

  Blynk.run();
  timer.run();

} ````

Not really. You’re still not getting the bit about sending an email only if a flag is clear (0) the. Setting the flag to 1 and clearing the flag inside a lambda timer once the timer has expired.

Pete.

The truth is that I was right I wanted to fix it and I did worse … but I found a way to order it and to make the code better I think … anyway I am going to find out how to send the emails and if not, notifications have an idea where I can get information ? is the code better? thank you very much for your time pete

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dwRN53LZ53EhCY59wk9O6EstwM1Ws0zL";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pablo y Maca 2.4";
char pass[] = "laputaclave";

#define DHTPIN 14          // What digital pin we're connected to
#define relay1 12

float temperature1 = 0;
float humidity1   = 0;

//Set values for Auto Control Mode
const float maxTemp = 26.5;
const float minTemp = 26.0;
const float tempalert = 31.0;

#define VPIN_HUMIDITY    V5
#define VPIN_TEMPERATURE V6

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
WidgetLED led2(V3);

void setup()
{
  // Debug console
Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
lcd.setCursor (0,0);
 lcd.begin(16,2);
  lcd.init();
lcd.backlight();
lcd.print ("Conectando ... ");
lcd.setCursor (0,1);
lcd.print ("  Red Wifi ... ");
delay(200);
  Blynk.begin(auth, ssid, pass);
Blynk.notify("Blynk iniciado correctamente");
delay(500);
  lcd.clear ();
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();
lcd.setCursor (0,0);
lcd.backlight();
lcd.print ("Conectado con.. ");
lcd.setCursor (0,1);
lcd.print("IP:");
lcd.print( WiFi.localIP() );
delay(3000);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Bienvenido .. ");
lcd.setCursor (3,1);
lcd.print("Iniciando ...");
delay(3000);
lcd.clear();

  timer.setInterval(1000L, sendSensor);
  timer.setInterval(2000L, displayData);
  timer.setInterval(1000L, estadosbotones);
  timer.setInterval(61000, estados2);
  
  }  


void readSensor(){
    
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  else {
    humidity1 = h;
    temperature1 = t;
  }  
}

void sendSensor()
{
  readSensor();
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(VPIN_HUMIDITY, humidity1);
  Blynk.virtualWrite(VPIN_TEMPERATURE, temperature1);
}

  

void displayData(){
  
    lcd.setCursor(0,0);
    lcd.print("Temp: ");
    lcd.print(temperature1);
    lcd.print("c");
    lcd.setCursor(0,1);
    lcd.print("Humedad: ");
    lcd.print(humidity1);
    lcd.print("%");
  
}


void estados2 ()
 {
  
if (temperature1 >= maxTemp) {

digitalWrite(relay1, HIGH);
led2.on(); 
}

else if (temperature1 <= minTemp) {

digitalWrite(relay1, LOW);
led2.off();
}

}



void estadosbotones()  { 
  
   if (digitalRead(relay1) == HIGH){  // Si se activa interruptor
      led2.on();     // Pause de 1 segundo 
        }
   else if (digitalRead(relay1) == LOW) {
    led2.off();       // Pausa de 1 segundo 
   } 
} 


void loop()

{

  Blynk.run();
  timer.run();

}````

Not really.
I’d normally recommend that people step away from the computer and document the process on paper using either words or pictures - depending on what you are trying to achieve.
But, in your case you are too entrenched in handling the main processes using three separate interval timers rather than one timer running more processes less frequently. As a result, I don’t think anything I say is going to help.

It’s all in the documentation…

https://docs.blynk.cc/

Pete.

Thank you very much for your help and your time,
I think that by doing it this way, everything is more orderly and I can give each thing its time … but is it really what is wrong? is it better to try to do only one process? I am learning and with the lambda it seemed more complicated, it is always better to less processes?

The lambda timer was necessary to ensure that you don’t send notifications too frequently, but needs to be used in conjunction with a flag.
You can’t replace the lambda timer with an unconnected interval timer and expect to achieve the same result.

Think about the process…

  1. take a temperature reading
  2. update your displays (LCD and Blynk)
  3. decide if the heater relay needs to be turned on/off and if so, do your displays need to be updated

One temperature reading is needed and one interval timer needed to do these processes, but that timer doesn’t need to be any more frequent than every 5 seconds.

Pete.

Thank you very much for the help, I will find out more about lambda timer so I can better order the code. Grace is very helpful.

Pete I think I’m closer to getting it right, but when he sends the emails and notifications reach me 3 times, I don’t know if what is in timer.setTimeout (wait, [] () {… repeats it 3 times …

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dwRN53LZ53EhCY59wk9O6EstwM1Ws0zL";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pablo y Maca 2.4";
char pass[] = "laputaclave";

#define DHTPIN 14          // What digital pin we're connected to
#define relay1 12
int flag =0;
//Set values for Auto Control Mode
const float maxTemp = 25.0;
const float minTemp = 24.5;
const float tempalert = 26.0;
long esperar = 60000;
long esperar2 = 120000;
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
WidgetLED led2(V3);

void setup()
{
  // Debug console
  Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
lcd.setCursor (0,0);
 lcd.begin(16,2);
  lcd.init();
lcd.backlight();
lcd.print ("Conectando ... ");
lcd.setCursor (0,1);
lcd.print ("  Red Wifi ... ");
delay(200);
  Blynk.begin(auth, ssid, pass);
  delay(200);
  lcd.clear ();
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();
lcd.setCursor (0,0);
lcd.backlight();
lcd.print ("Conectado con.. ");
lcd.setCursor (0,1);
lcd.print("IP:");
lcd.print( WiFi.localIP() );
delay(3000);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Bienvenido .. ");
lcd.setCursor (3,1);
lcd.print("Iniciando ...");
delay(3000);


lcd.clear();
  // Setup a function to be called every second
  timer.setInterval(3500, sendSensor);
  timer.setInterval(500, botonesblynk);    // Temperature sensor read interval. 2000 (ms) = 2 seconds. 
  
  }  


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  
}
    Blynk.virtualWrite(V5, h);
    Blynk.virtualWrite(V6, t);
    lcd.setCursor(0,1);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print("c");
    lcd.setCursor(0,0);
    lcd.print("Humedad: ");
    lcd.print(h);
    lcd.print("%");


if (t >=  maxTemp) {
timer.setTimeout(esperar2,[](){
digitalWrite(relay1, HIGH);
led2.on();
 });
}

else if (t <= minTemp) {
timer.setTimeout(esperar2,[](){
digitalWrite(relay1, LOW);
led2.off();
});
}

if (t >= tempalert && flag==0) {
 timer.setTimeout(esperar,[](){
Blynk.email("maugerijuan@gmail.com", "Temperatura Blynk ALERTA !! ", "Temperatura superior a 31º ATENCION !!"); 
Blynk.notify("TEMPRATURA + 31º!!");
flag=1; 
});
}
else if (flag==1) {
flag=0;
}  
}


void botonesblynk () {
  

 if (digitalRead(relay1) == HIGH){  // Si se activa interruptor
      led2.on();     // Pause de 1 segundo 
        }
      else if (digitalRead(relay1) == LOW) {
       led2.off();       // Pausa de 1 segundo 
   } 


 }



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

Once again, your code flow seems all wrong to me.

You’re not doing this…

And the lambda timeout timers that you have used…

serve no purpose, as the relay is being controlled every 3.5 seconds independently of what these timers are doing.

If your intention is to use this to implement hysteresis, to prevent the relay turning on and off frequently then this isn’t necessary as you’ve done that by having a high and low temperature range.

Pete.

The truth is that you are right, I am going to set the maximum temperature to 31º, and the minimum to 25 … there is a lot of difference and timers are not necessary, it is a great help since I have no one to consult

I’m working I can’t figure out how to do the if right because I can’t test it but if I think about it, I think about it like this

if (t >= tempalert && flag==0) {
flag=1;
timer.setTimeout(61000,[](){
Blynk.email("maugerijuan@gmail.com", "Temperatura Blynk ALERTA !! ", "Temperatura superior a 31º ATENCION !!"); 
Blynk.notify("TEMPRATURA + 31º!!");

flag=0;
});
} ```


I don't know if it's okay if you don't know how to find this information so I learn to do it?

I think that your problem is that you’re not working through the process flow of the code.

When I first learned to develop software, the program flow had to be drawn in a flowchart and
the code had to be written out on paper and you had to show the program flow and the value of each variable at each change point.

You then queued-up to access a green-screen terminal, type in your code then compile and execute it.

Whilst this approach was a real pain, it did teach me to approach software development from a more structured and thoughtful manner. I don’t tend to take the same approach now, but I do attempt to sketch out the program flow and use in-code comments to remind myself why I’m doing each process and under what circumstances it will execute.

Your approach seems to lack any clarity of plan, or commentary to explain to your self why you are doing each step of process.

Pete.

I could always do it, I had the answer in front of me, he made me see it in several opportunities but I could not realize it, it is evident that I do not know and I am learning … I thank you with what you told me I could do it on paper and understand what to do … this It’s my code, I don’t know if it’s okay yet, but I thank you for the things you told me, they helped me understand how it works and so I was able to do it. He’s an excellent teacher

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dwRN53LZ53EhCY59wk9O6EstwM1Ws0zL";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pablo y Maca 2.4";
char pass[] = "laputaclave";
#define DHTPIN 14          // What digital pin we're connected to
#define relay1 12
int flag =0;

//Set values for Auto Control Mode
const float maxTemp = 27.0;
const float minTemp = 23.5;
const float tempalert = 26.0;

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT21   // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
WidgetLED led2(V3);
void setup()
{
  // Debug console
  Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
lcd.setCursor (0,0);
 lcd.begin(16,2);
  lcd.init();
lcd.backlight();
lcd.print ("Conectando ... ");
lcd.setCursor (0,1);
lcd.print ("  Red Wifi ... ");
delay(200);
  Blynk.begin(auth, ssid, pass);
  delay(200);
  lcd.clear ();
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
dht.begin();
lcd.setCursor (0,0);
lcd.backlight();
lcd.print ("Conectado con.. ");
lcd.setCursor (0,1);
lcd.print("IP:");
lcd.print( WiFi.localIP() );
delay(3000);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Bienvenido .. ");
lcd.setCursor (3,1);
lcd.print("Iniciando ...");
delay(3000);
lcd.clear();
  // Setup a function to be called every second
  timer.setInterval(3500, sendSensor);
  timer.setInterval(500, botonesblynk);    // Temperature sensor read interval. 2000 (ms) = 2 seconds. 
  }  
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
}
    Blynk.virtualWrite(V5, h);
    Blynk.virtualWrite(V6, t);
    lcd.setCursor(0,1);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print("c");
    lcd.setCursor(0,0);
    lcd.print("Humedad: ");
    lcd.print(h);
    lcd.print("%");

if (t >=  maxTemp) {
digitalWrite(relay1, HIGH);
led2.on();
}

else if (t <= minTemp) {
digitalWrite(relay1, LOW);
led2.off();
}


if (t >= tempalert && flag==0) {
flag=1;
Blynk.email("maugerijuan@gmail.com", "Temperatura Blynk ALERTA !! ", "Temperatura superior a 31º ATENCION !!"); 
Blynk.notify("TEMPRATURA + 31º!!");
timer.setTimeout(1800000 ,[](){
flag=0; 
});
}
} 


void botonesblynk () {
 if (digitalRead(relay1) == HIGH){  // Si se activa interruptor
      led2.on();     // Pause de 1 segundo 
        }
      else if (digitalRead(relay1) == LOW) {
       led2.off();       // Pausa de 1 segundo 
   } 
 }

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