Delay when turning off pins

Hello, guys! My project is to control two relays, V10 and V11. I dont know why, but when I turn off the pins, either they are virtual ou digital on the app, there’s a delay of 5 seconds, which is the timer for one function. To turn on, it is instantly.
And it happens randomly too. Yesterday I had delay in both pins, now only one of them take time to turn off.

I dont know if its power related, because when the plate is connected to the USB, it works normally. I use a MB102 breadboard power supply. 5V to the relays and 3.3V to the NodeMCU and the sensors.

Here’s the code

    /* PORTAS EM USO
          D0 - RELE 1
          D1 - RELE 2
          V0 - TERMINAL
          V1 - DESLIGAR TUDO
          V2 - TIMER
          V5 - UMIDADE
          V6 - TEMPERATURA
    */

    /*
      NODEMCU    ARDUINO
      DO          16
      D1          5
      D2          4
      D3          0
      D4          2
      D5          14
      D6          12
      D7          13
      D8          15
      D9          3
      D10         1
    */

    #define BLYNK_PRINT Serial
    #define pinSom 4
    #define tempoMaximoDeUmaPalma  150 //milisegundos
    #define tempoMaximoEntrePalmas 500 //milisegundos

    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    #include <SPI.h>
    #include <DHT.h>
    #include <TimeLib.h>
    #include <WidgetRTC.h>

    int contaPalmas = 0;
    long tempoEspera = 0;
    long tempoEsperaEntrePalmas = 0;
    int estadoinicial;
    char auth[] = "312835a81d59443aaxxxx1b54caef57";

    #define DHTPIN 12          // PINO D6 DO SENSOR
    #define DHTTYPE DHT11     // DHT 11 - TIPO DO SENSOR
    //#define gasPin x        // pino do sensor de gas

    char ssid[] = "x";  // LOGIN
    char pass[] = "x";  // SENHA


    WidgetTerminal terminal(V0);
    DHT dht(DHTPIN, DHTTYPE);
    BlynkTimer timer;
    WidgetRTC rtc;

    BLYNK_CONNECTED() {
      Serial.println("\n\n\n\n\n");
      Serial.println("------------------");
      Serial.println("AUTOMACAO 1 - CONECTADO");
      Serial.println("------------------");

      terminal.println("\n\n\n\n\n");
      terminal.println("------------------");
      terminal.println("AUTOMACAO 1 - CONECTADO");
      terminal.println("------------------");
      terminal.flush();
      Blynk.syncAll();
      rtc.begin();
    }
    BLYNK_APP_CONNECTED() {
      Serial.println("App aberto.");
      terminal.println("App aberto.");
      terminal.flush();
    }

    // This is called when Smartphone App is closed
    BLYNK_APP_DISCONNECTED() {
      Serial.println("App fechado.");
    }

    //FUNCAO RTC
    void clockDisplay()
    {
      String currentTime = String(hour()) + ":" + minute();
      String currentDate = String(day()) + "/" + month() + "/" + year();

      Serial.print("-ONLINE: \n");
      Serial.print("  HORA: ");
      Serial.print(currentTime);
      Serial.print("\n");
      Serial.print("\n");

      terminal.print("-ONLINE: \n");
      terminal.print("  HORA: ");
      terminal.print(currentTime);
      terminal.print("\n");
      terminal.print("\n");

      // Send time to the App
      Blynk.virtualWrite(V20, currentTime);
      // Send date to the App
      Blynk.virtualWrite(V21, currentDate);
    }
    //FIM DA FUNCAO

    // FUNCAO LIGAR E DESLIGAR TODAS LAMPADAS
    BLYNK_WRITE(V1) {
      int estado = param.asInt();
      if (estado == 1) {
        digitalWrite(D0, HIGH);
        digitalWrite(D1, HIGH);
      }
      else {
        digitalWrite(D0, LOW);
        digitalWrite(D1, LOW);
      }

      Blynk.virtualWrite(V11, param.asInt());
      Blynk.virtualWrite(V10, param.asInt());
    }
    // FIM DA FUNCAO

    BLYNK_WRITE(V10) {
      digitalWrite(D0, param.asInt());
    }
    BLYNK_WRITE(V11) {
      digitalWrite(D1, param.asInt());
    }
    // FUNCAO SENSOR TEMPERATURA E UMIDADE
    void sendSensor()
    {
      float h = dht.readHumidity();
      float t = dht.readTemperature(); // (true) para Fahrenheit

      if (isnan(h) || isnan(t)) {
        Serial.println("Falha ao ler sensor DHT11!");
        return;
      }
      Blynk.virtualWrite(V5, h);
      Blynk.virtualWrite(V6, t);

      Serial.println("\n");
      Serial.print("Temperatura: ");
      Serial.print(t);
      Serial.println("C");

      Serial.print("Umidade: ");
      Serial.print(h);
      Serial.println("%");

    }
    // FIM DA FUNCAO


    /* FUNCAO SENSOR GAS
        void SensorGas()
        {
          int mq2 = (analogRead(gasPin));

          Serial.println(mq2);

          if (isnan(mq2)) {
                Serial.println("Falha ao ler sensor MQ2!");
                return;
          }
          if (mq2>400){
                   g = "Gas detectado";
                   Serial.println(g);
                   terminal.println(g);
          }
          else{
                   gasDetected= "Ar limpo";
                   Serial.println(g);
                   terminal.println(g);
          }
        Blynk.virtualWrite(V9, g);
        }*/
    // FIM DA FUNCAO

    // TESTE FUNCAO TIMER
    /*
      BLYNK_WRITE (V2)
          int estado = param.asInt();
          if(estado == 1){
            digitalWrite(D0, HIGH);
            //digitalWrite(D1, HIGH);
            //digitalWrite(D3, HIGH);
            //digitalWrite(D4, HIGH);
          }
          else{
            digitalWrite(D0, LOW);
            //digitalWrite(D1, LOW);
            //digitalWrite(D3, LOW);
            //digitalWrite(D4, LOW);
          }
        }
    */

    void sensorPalma() {
      int sensorSom = digitalRead(pinSom);

      //se o sensor detectou palmas
      if (sensorSom == LOW) {

        //espera um tempo para nao detectar a mesma palma mais de uma vez
        if (tempoEspera == 0) {
          tempoEspera = tempoEsperaEntrePalmas = millis();
          contaPalmas++;
        } else if ((millis() - tempoEspera) >= tempoMaximoDeUmaPalma) {
          tempoEspera = 0;
        }
      }

      //caso exceda o tempo maximo entre palmas, zera o contador de palmas
      if ( (contaPalmas != 0) && ((millis() - tempoEsperaEntrePalmas) > 500) ) {
        executarAcao();
        contaPalmas = 0;
        tempoEsperaEntrePalmas = millis();
      }
    }

    void executarAcao()
    {

      switch (contaPalmas) {
        case 2:
          digitalWrite(D1, !digitalRead(D1));
          break;
        case 1:
          digitalWrite(D0, !digitalRead(D0));
          break;
        case 3:
          digitalWrite(D1, !digitalRead(D0));
          break;

          break;

      }
    }

    void setup()
    {
      Serial.begin(9600);
      Blynk.begin(auth, ssid, pass);
      dht.begin();


      timer.setInterval(10000L, sendSensor); // envia funcao a cada 5s
      timer.setInterval(1200000L, clockDisplay);
      // timer.setInterval(70000L, SensorGas);
      //timer.setInterval(150L, sensorPalma);
      //timer.setInterval(150L, executarAcao);
    }

    void loop()
    {
      Blynk.run();
      timer.run();
      //sensorPalma();
      //executarAcao();

    }

This is the part I use to turn them on or off:

     BLYNK_WRITE(V10) {
          digitalWrite(D0, param.asInt());
        }
        BLYNK_WRITE(V11) {
          digitalWrite(D1, param.asInt());

I have tried using them directly as digital pins on the app, but the problem still happens.
Just for you to know, today it’s working normally, but probably it wont anytime

Thanks

another thing:
I’m having conflict with the 2 function timers. For this code 10000 and 1200000, the clock display works fine, but the sensor is never read

I changed it to 5000 and 5000 and it’s kind of bugged.

The only way it works fine is 1000 on clock and 5000 on sensor (DHT11 sensor btw).

When you use 5000 for both function it may not be able to do both at the same time, therefore buggy, I’d use slightly different times.

And regarding the first issue I’m not sure if I understood what is happening.

it’s kind of simple: my relay pins, either if i use them virtual as usual or if I change to digital, sometimes in the day, have a delay to turn off.
I press the button on app, the relay light turns off, but only in like 5secs (which is the timer for one function), the relay makes the noies and the led I use to check them turn off.
It’s completely random. Sometimes restarting the NodeMCU solves the problem, sometimes not, or sometimes, like now, it’s working perctly.

As the second issue, I have tried using very different numbers to the timer, but it only works good (checking by serial monitor) when sensor is like 5000 and clock 1000

No more help? :frowning:

It looks like you did not call “sensorPalma” function in this code. In timer attach side, its commented. My suggest, translate your code to English. I am doing like that to get help for my issues.

I have really good internet connection. Sometimes i have about 3 seconds latency problems. I think it is normal.

Try to call your relay control function with timers. May be function depends some if else statement now.

(I felt lazy to read all code without comments :smile: try translated code )

The sensorPalma is for a ClapSensor function, to turn the lights. I dont even use it in this project at all.

This problem still happens :frowning:

Is this project on a breadboard? if so then you cant really expect to get reliable long term results as the resistance between the breadboard sockets and the devices and wires you have plugged into them will cause erratic behaviour.
It also seems that you have doubts about your power supply. Have you tried a beefed-up power supply?

It’s very difficult for people to help you when your code is cluttered-up with unused functions and your comments and variable names aren’t in English. It’s also very difficult to diagnose random problems, especially if you don’t supply serial print data that relates to the point in time when the random event occurred.

I’d put money on the fact that this behaviour isn’t being caused by Blynk so it really fits into the category of something that only you can sort-out by simplifying your code then monitoring these random disconnections and looking for a pattern.

Pete.

had to delete because i forgot to delete the auth part

Hey pete!

So the problem that still persists is the incompatibility between the RTC function and the DHT 11 sensor reading function.
When I have the RTC running, the sensor only works with some values of the timer, like when the RTC is 5000 and the sensor function is 12000

this is the updated code:

 #define BLYNK_PRINT Serial   
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <DHT.h>
#include <SPI.h>
#include <WidgetRTC.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>

#define DHTPIN D7          
#define DHTTYPE DHT11    
#define relay1 D8
#define relay2 D1
#define relay3 D2
#define button1 D3
#define button2 D4
#define button3 D5
#define IR_LED D0
#define RAWBUF 400

uint16_t ac24[] = {9060,  4564, 548,  1724, 548,  1724, 548,  596, 552,  604, 548,  596, 548,  596, 548,  596, 552,  1732, 548,  596, 548,  1724, 548,  1720, 548,  608, 548,  596, 548,  600, 544,  600, 548,  604, 548,  1724, 548,  1724, 548,  596, 548,  604, 548,  596, 552,  596, 548,  596, 548,  604, 552,  596, 548,  1720, 552,  596, 548,  604, 548,  596, 552,  1720, 548,  1724, 548,  608, 548,  596, 548,  596, 548,  596, 548,  608, 548,  596, 548,  596, 548,  596, 552,  604, 548,  596, 548,  600, 548,  596, 548,  604, 548,  600, 548,  596, 548,  596, 548,  604, 548,  8076, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 544,  604, 544,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 544,  604, 544,  600, 548,  600, 544,  604, 548,  600, 544,  600, 548,  600, 548,  600, 544,  600, 548,  600, 544,  604, 548,  600, 544,  600, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  600, 548,  600, 548,  600, 544,  604, 544,  600, 548,  600, 544,  604, 544,  600, 548,  600, 548,  600, 544,  604, 544,  600, 548,  600, 548,  600, 544,  604, 544,  600, 548,  600, 544,  604, 544,  660, 544,  1728, 544,  600, 544,  600, 548,  608, 544,  600, 548,  1724, 544,  1724, 548,  604, 544};
uint16_t ac23[] = {9060, 4568, 552, 1724, 548, 1724, 544, 600, 548, 608, 548, 596, 548, 596, 548, 600, 548, 1732, 544, 600, 548, 1724, 548, 1724, 548, 608, 548, 600, 544, 600, 548, 596, 548, 608, 548, 1724, 548, 1724, 548, 596, 548, 608, 548, 596, 548, 596, 548, 600, 548, 604, 548, 596, 552, 1720, 552, 596, 548, 604, 552, 1724, 548, 596, 548, 1724, 548, 604, 552, 596, 544, 600, 548, 600, 548, 604, 548, 596, 552, 596, 548, 596, 548, 608, 548, 596, 548, 596, 548, 600, 548, 604, 548, 600, 548, 596, 548, 596, 548, 604, 548, 8080, 548, 600, 548, 600, 548, 600, 548, 600, 548, 596, 552, 596, 548, 600, 548, 600, 548, 600, 548, 596, 548, 600, 552, 596, 548, 600, 548, 600, 548, 600, 548, 600, 548, 600, 548, 596, 548, 600, 552, 596, 548, 600, 544, 604, 548, 600, 548, 596, 552, 596, 548, 600, 548, 600, 548, 600, 548, 600, 548, 596, 552, 596, 552,596, 548, 600, 548, 600, 548, 600, 548, 596, 552, 596, 548, 600, 548, 600, 548, 600, 548, 600, 548, 600, 548, 596, 548, 600, 548, 600, 548, 600, 548, 600, 548, 600, 548, 596, 552, 596, 548, 600, 548, 600, 548, 596, 552, 600, 548, 596, 552, 656, 548, 1724, 548, 596, 548, 596, 552, 604, 548, 1724, 548, 596, 552, 1720, 552, 600, 548}; 
uint16_t ac22[] = {9060, 4564, 548, 1724, 544, 1728, 544, 600, 544, 608, 548, 596, 548, 600, 544, 600, 544, 1736, 544, 600, 544, 1728, 544, 1728, 544, 608, 544, 600, 548, 600, 544, 600, 544, 608, 548, 1724, 544, 1728, 544, 600, 544, 608, 548, 600, 544, 600, 544, 600, 544, 612, 544, 600, 544, 1724, 548, 600, 544, 608, 544, 604, 544, 600, 544, 1728, 544, 608, 544, 600, 544, 600, 548, 600, 544, 608, 544, 600, 548, 600, 544,600, 544, 608, 548, 600, 544, 600, 544, 600, 544, 612, 544, 600, 544, 600, 544, 600, 544, 608, 544, 8080, 544, 604, 544, 604, 544, 600, 548, 600, 544, 604, 544, 600, 548, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 548, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 548, 600, 544, 604, 544, 600, 548, 600, 548, 600, 544, 604, 544, 600, 544, 604, 544, 600, 548, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 544, 604, 544, 604, 544, 600, 548, 600, 544, 660, 544, 1728, 544, 600, 544, 604, 544, 608, 544, 600, 544, 604, 544, 1724, 544, 604, 548};
uint16_t  onac22[] = {9012,  4592, 524,  1752, 520,  1748, 520,  628, 520,  632, 520,  624, 520,  628, 520,  624, 520,  1760, 520,  624, 520,  1752, 520,  1752, 520,  636, 520,  624, 520,  624, 520,  628, 516,  636, 520,  1752, 520,  1752, 520,  1752, 520,  632, 520,  628, 520,  624, 520,  624, 520,  636, 520,  624, 520,  1752, 520,  624, 520,  636, 520,  624, 520,  624, 520,  1752, 520,  632, 524,  624, 520,  624, 520,  624, 520,  636, 520,  624, 520,  624, 520,  628, 516,  636, 520,  624, 520,  628, 516,  628, 520,  632, 520,  624, 520,  628, 520,  624, 520,  632, 516,  8108, 520,  628, 520,  628, 520,  628, 520,  624, 524,  624, 520,  628, 520,  628, 520,  624, 520,  628, 520,  628, 520,  628, 520,  628, 520,  624, 520,  628, 520,  628, 520,  628, 520,  624, 520,  628, 520,  628, 520,  628, 520,  628, 516,  628, 520,  628, 520,  628, 520,  628, 520,  628, 520,  624, 520,  628, 520,  628, 520,  628, 520,  624, 520,  628, 520,  628, 520,  628, 520,  628, 520,  624, 520,  628, 520,  628, 520,  628, 520,  624, 520,  628, 520,  628, 520,  628, 520,  628, 520,  628, 516,  628, 520,  628, 520,  628, 520,  624, 520,  628, 520,  628, 520,  628, 520,  628, 520,  624, 520,  632, 516,  688, 516,  1752, 520,  628, 520,  1752, 520,  632, 520,  624, 520,  628, 520,  1752, 520,  628, 520};
uint16_t onac24[] = {9040,  4564, 548,  1724, 548,  1724, 548,  596, 548,  608, 548,  596, 548,  596, 548,  600, 548,  1732, 548,  596, 548,  1724, 548,  1724, 548,  608, 544,  600, 548,  596, 548,  596, 548,  608, 548,  1720, 552,  1724, 544,  1724, 548,  608, 548,  596, 548,  600, 544,  600, 548,  604, 548,  596, 548,  1724, 548,  600, 548,  604, 548,  596, 548,  1724, 548,  1724, 548,  608, 544,  600, 548,  596, 548,  596, 548,  608, 548,  596, 548,  596, 548,  596, 548,  608, 548,  596, 548,  596, 548,  600, 548,  604, 548,  596, 548,  600, 548,  596, 548,  600, 548,  8080, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 548,  596, 552,  596, 548,  600, 548,  596, 552,  596, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  596, 552,  596, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 548,  656, 548,  1724, 548,  596, 548,  1724, 548,  608, 548,  596, 548,  1724, 548,  1724, 548,  600, 548};
uint16_t timer24[]= {9044,  4568, 544,  1728, 544,  1724, 548,  600, 544,  608, 544,  604, 544,  600, 544,  600, 544,  1736, 544,  600, 544,  1728, 544,  1728, 544,  608, 548,  600, 544,  600, 544,  600, 548,  608, 544,  1724, 548,  1724, 548,  596, 548,  608, 544,  600, 548,  600, 544,  600, 544,  608, 548,  600, 544,  1728, 544,  600, 544,  1736, 544,  600, 544,  1728, 544,  1728, 544,  608, 548,  1724, 544,  604, 544,  1724, 548,  608, 544,  600, 548,  600, 544,  600, 544,  608, 544,  604, 544,  600, 548,  596, 544,  608, 548,  600, 544,  600, 544,  600, 548,  604, 544,  8080, 548,  600, 544,  604, 544,  604, 544,  604, 544,  600, 544,  604, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  604, 544,  600, 548,  600, 548,  600, 544,  604, 544,  600, 548,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  604, 544,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  604, 544,  660, 544,  600, 544,  600, 548,  1724, 544,  1736, 548,  600, 544,  1724, 548,  1724, 548,  604, 544};
uint16_t timer23[]= {9064,  4564, 548,  1724, 548,  1724, 544,  604, 544,  608, 544,  600, 548,  596, 548,  600, 544,  1736, 544,  600, 544,  1728, 544,  1728, 544,  608, 544,  600, 548,  596, 548,  600, 544,  608, 544,  1728, 544,  1728, 544,  600, 544,  608, 548,  600, 544,  600, 544,  600, 548,  608, 544,  600, 544,  1728, 544,  600, 544,  1736, 544,  1728, 544,  604, 544,  1724, 548,  608, 544,  1728, 544,  600, 544,  1728, 544,  608, 548,  600, 544,  600, 544,  600, 544,  612, 544,  600, 544,  600, 544,  600, 548,  608, 544,  600, 544,  600, 544,  604, 544,  604, 544,  8080, 548,  600, 548,  600, 544,  604, 544,  604, 544,  600, 544,  604, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  604, 544,  604, 544,  600, 548,  600, 544,  660, 548,  600, 544,  600, 544,  1728, 544,  1736, 544,  1728, 544,  600, 544,  1728, 544,  604, 548};
uint16_t timer22[]= {9064,  4564, 548,  1724, 548,  1724, 548,  596, 548,  608, 548,  596, 548,  596, 548,  600, 548,  1732, 548,  596, 548,  1724, 548,  1724, 548,  604, 548,  596, 552,  596, 548,  596, 548,  604, 552,  1724, 544,  1724, 552,  596, 548,  604, 548,  596, 552,  596, 548,  596, 552,  600, 548,  600, 548,  1724, 544,  600, 548,  1732, 548,  596, 548,  596, 548,  1724, 548,  608, 544,  1724, 548,  596, 552,  1724, 544,  608, 548,  596, 548,  596, 548,  600, 548,  604, 548,  596, 548,  600, 548,  596, 548,  604, 548,  596, 548,  600, 548,  596, 548,  600, 548,  8080, 548,  600, 548,  596, 552,  596, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 548,  596, 552,  596, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  596, 552,  596, 548,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 548,  600, 548,  600, 544,  600, 548,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 548,  596, 548,  600, 548,  600, 548,  600, 548,  600, 544,  600, 548,  660, 548,  596, 548,  596, 548,  1724, 548,  1732, 548,  600, 548,  596, 548,  1724, 548,  600, 548};
int khz = 38;

BlynkTimer timer;
DHT dht(DHTPIN, DHTTYPE);
WidgetRTC rtc;
WidgetLED led1(V20);  
WidgetLED led2(V21); 
WidgetLED led3(V22);
WidgetTerminal terminal(V0);
IRsend irsend(IR_LED); 

char auth[] = "";

char ssid[] = "xx";  
char pass[] = "5";  

//---------------------------------------------------

int relayVButton1 = 0;
int relayVButton2 = 0;
int relayVButton3 = 0;
int isFirstConnect = true;

boolean relayState1 = 1;
boolean relayState2 = 1;
boolean relayState3 = 1;
boolean buttonState1 = 1;
boolean buttonState2 = 1;
boolean buttonState3 = 1;

//------------------msgs conectado e disc-----------
BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
    isFirstConnect = false;
  }

  Serial.println("\n\n\n\n\n");
  Serial.println("------------------");
  Serial.println("AUTOMACAO 1 - CONECTADO");
  Serial.println("------------------");

  terminal.println("\n\n\n\n\n");
  terminal.println("------------------");
  terminal.println("AUTOMACAO 1 - CONECTADO");
  terminal.println("------------------");
  terminal.flush();
  rtc.begin();
}
  
BLYNK_APP_CONNECTED() {
  Serial.println("App aberto.");
  terminal.println("App aberto.");
  terminal.flush();
}
//----------------------------------------------------

//-------------------------------SETUP---------------------------------------------------
void setup(){
 Serial.begin(9600); 
 Blynk.begin(auth, ssid, pass); 
 dht.begin();
 
 timer.setInterval(12000L, sendSensor);    // SENSOR DHT
 timer.setInterval(10000L, clockDisplay);  // CLOCK
 timer.setInterval(300L, somefunction);   // FUNÇAO RELAY

while (Blynk.connect() == false) {
 buttonState1 = digitalRead (button1);
  if (buttonState1 > 0){
    relayState1 = !relayState1;
      } 
      digitalWrite(relay1, relayState1);
       buttonState2 = digitalRead (button2);
  if (buttonState2 > 0){
    relayState2 = !relayState2;
      } 
      digitalWrite(relay2, relayState2);
  if (buttonState3 > 0){
    relayState3 = !relayState3;
      } 
      digitalWrite(relay3, relayState3);
  }
  
pinMode(relay1, OUTPUT);
pinMode(button1,INPUT_PULLUP);
pinMode(relay2, OUTPUT);
pinMode(button2,INPUT_PULLUP);
pinMode(relay3, OUTPUT);
pinMode(button3,INPUT_PULLUP);
}
//-----------------------------------------------------------------------------------------

//---------------FUNCAO DHT-----------------------------------------------------------------
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // (true) para Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Falha ao ler sensor DHT11!");
    return;
  }
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);

  Serial.println("\n");
  Serial.print("Temperatura: ");
  Serial.print(t);
  Serial.println("C");

  Serial.print("Umidade: ");
  Serial.print(h);
  Serial.println("%");
}//-------------------------------------------------------------------------------------------

//------------FUNCAO RELAY--------------------------------------------------------------------
void somefunction(){
  buttonState1 = digitalRead (button1);
    if (buttonState1 < 1 || relayVButton1 > 0)    {
    relayState1 = !relayState1;
    } 
    digitalWrite(relay1, relayState1);
     
  buttonState2 = digitalRead (button2);
    if (buttonState2 < 1  || relayVButton2 > 0){
      relayState2 = !relayState2;
    } 
      digitalWrite(relay2, relayState2);
      
  buttonState3 = digitalRead (button3);
    if (buttonState3 < 1  || relayVButton3 > 0){
      relayState3 = !relayState3;
    } 
      digitalWrite(relay3, relayState3);

//----------------button virtual led----------------
  byte inp = digitalRead(relay1);   
  if (inp == HIGH){
   led1.on();
  }
   else
   led1.off();

  byte inp2 = digitalRead(relay2);   
  if (inp2 == HIGH){
   led2.on();
  }
   else
   led2.off();

  byte inp3 = digitalRead(relay3);   
  if (inp3 == HIGH){
   led3.on();
  }
   else
   led3.off();
}
//--------------leitura pino app-------------------- 
BLYNK_WRITE(V10){
  relayVButton1 = param.asInt();   
}

BLYNK_WRITE(V11){
  relayVButton2 = param.asInt(); 
}
BLYNK_WRITE(V12){
  relayVButton3 = param.asInt(); 
}
//TV ON-OFF
BLYNK_WRITE(V30){
  if(param.asInt()==1){
    irsend.sendNEC(0x20DF10EF,32); 
    delay(300);
    Blynk.virtualWrite(V30, LOW);
  }
}
//TV V-UP
BLYNK_WRITE(V31){
  if(param.asInt()){
    irsend.sendNEC(0x20DF40BF,32); 
  }
}
//TV V-DOWN
BLYNK_WRITE(V32){
  if(param.asInt()){
    irsend.sendNEC(0x20DFC03F,32); 
  }
}
//TV CH-UP
BLYNK_WRITE(V33){
  if(param.asInt()){
    irsend.sendNEC(0x20DF00FF,32); 
  }
}
//TV CH-DOWN
BLYNK_WRITE(V34){
  if(param.asInt()){
    irsend.sendNEC(0x20DF807F,32); 
  }
}
//TV MUTE
BLYNK_WRITE(V35){
  if(param.asInt()==1){
    irsend.sendNEC(0x20DF906F,32);
    delay(300);
    Blynk.virtualWrite(V35, LOW); 
  }
}
//TV INPUT
BLYNK_WRITE(V36){
  if(param.asInt()){
    irsend.sendNEC(0x20DFD02F,32); 
  }
}
//TV EXIT
BLYNK_WRITE(V37){
  if(param.asInt()){
    irsend.sendNEC(0x20DFDA25,32); 
  }
}
//TV OK
BLYNK_WRITE(V38){
  if(param.asInt()){
    irsend.sendNEC(0x20DF22DD,32); 
  }
}
//AC ON-OFF 22
BLYNK_WRITE(V50){
  if(param.asInt()==1){
    irsend.sendRaw(onac22, sizeof(onac22) / sizeof(onac22[0]), 38);
    delay(300);
    Blynk.virtualWrite(V50, LOW); 
  }
}
//AC ON-OFF 24
BLYNK_WRITE(V51){
  if(param.asInt()){
   irsend.sendRaw(onac24, sizeof(onac24) / sizeof(onac24[0]), khz);
  }
}
//AC 24
BLYNK_WRITE(V54){
  if(param.asInt()){
    irsend.sendRaw(ac24, sizeof(ac24) / sizeof(ac24[0]), khz);
  }
}
//AC 23
BLYNK_WRITE(V53){
  if(param.asInt()){
    irsend.sendRaw(ac23, sizeof(ac23) / sizeof(ac23[0]), khz);
  }
}
//AC 22 
BLYNK_WRITE(V52){
  if(param.asInt()){
    irsend.sendRaw(ac22, sizeof(ac22) / sizeof(ac22[0]), khz);
  }
}
//AC TIMER 24 
BLYNK_WRITE(V55){
  if(param.asInt()){
    irsend.sendRaw(timer24, sizeof(timer24) / sizeof(timer24[0]), khz); 
  }
}
//AC TIMER 23 
BLYNK_WRITE(V56){
  if(param.asInt()){
    irsend.sendRaw(timer23, sizeof(timer23) / sizeof(timer23[0]), khz);  
  }
}
//AC TIMER 22 
BLYNK_WRITE(V57){
  if(param.asInt()){
    irsend.sendRaw(timer22, sizeof(timer22) / sizeof(timer22[0]), khz);  
  }
}

//------------------------------------------------------------------------------------------------

//----------------------------FUNCAO CLOCK---------------------------------------------------------
void clockDisplay()
{  
  String currentTime = String(hour()) + ":" + minute();
  String currentDate = String(day()) + "/" + month() + "/" + year();
 
  Serial.print("-ONLINE: \n");
  Serial.print("  HORA: ");
  Serial.print(currentTime);
  Serial.print("\n");
  Serial.print("\n");

  // Send time to the App
  Blynk.virtualWrite(V15, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V16, currentDate);
}
//--------------------------------------------------------------------------------------------------
//---------------------------------------GERAL-------------------------------------------
BLYNK_WRITE(V1) {
  int estado = param.asInt();
  if (estado == 1) {
    relayState1 = relayState2;
    relayState1 = !relayState1;
    relayState2 = !relayState2;
    relayState3 = relayState2;
  }
  delay(300);
  Blynk.virtualWrite(V1, LOW);
}
BLYNK_WRITE(V100) {
  if (param.asInt() == 1) {
      if(relayState1 == 1){
          relayState1 = !relayState1;
      }
      if(relayState2 == 1){
          relayState2 = !relayState2;
      }
      if(relayState3 == 1){
          relayState3 = !relayState3;
      }      
      delay(300);
      Blynk.virtualWrite(V100, LOW);
  }
}
BLYNK_WRITE(V101) {
  if (param.asInt() == 1) {
      if(relayState1 == 1){
          relayState1 = !relayState1;
      }
      if(relayState2 == 1){
          relayState2 = !relayState2;
      }
      if(relayState3 == 1){
          relayState3 = !relayState3;
      }
      irsend.sendRaw(onac22, sizeof(onac22) / sizeof(onac22[0]), 38);
      irsend.sendNEC(0x20DF10EF,32); 
      delay(300);
      Blynk.virtualWrite(V101, LOW);
  }
  
}

BLYNK_WRITE(V102) {
  if (param.asInt() == 1) {
      if(relayState1 == 1){
          relayState1 = !relayState1;
      }
      if(relayState2 == 1){
          relayState2 = !relayState2;
      }
      if(relayState3 == 1){
          relayState3 = !relayState3;
      }
      irsend.sendNEC(0x20DF10EF,32); 
      delay(300);
      Blynk.virtualWrite(V102, LOW);
  }  
}
//--------------------------------------------------------------------------------------

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

The timer part:

timer.setInterval(12000L, sendSensor);    // dht sensor 
timer.setInterval(10000L, clockDisplay);  // rtc 
timer.setInterval(300L, somefunction);   // relay function

The sensor part:

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

  if (isnan(h) || isnan(t)) {
    Serial.println("Falha ao ler sensor DHT11!"); // "failed to read dht11 sensor
    return;
  }
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);

  Serial.println("\n");
  Serial.print("Temperatura: ");
  Serial.print(t);
  Serial.println("C");

  Serial.print("Umidade: ");
  Serial.print(h);
  Serial.println("%");

So when I put random values on the timer, this happens:
The dht sensor is not read

So is that your only problem.

Pete.

Yes. I have an IR problem but it is discussed in another topic.