Led Blynk receive result from an if

Hello,
I’m from Brazil, and I’m using google translator, so sorry for the typos.

I have a Blynk application with my NodeMcu,
I’m trying to connect Blynk’s LEDs after a check, how can I do it?
I’m going to put my code and a (?) where I would put a function so that the led of BLYNK received the result.

void loop()
{

   if(digitalRead(boia) == 0)
   {
     lcd.setCursor(0,1);
     lcd.print("NIVEL BAIXO");
     (?)
   }
   else
      {
     lcd.setCursor(0,1);
     lcd.print("NIVEL OK");
     (?)
      } 

I was able to solve the problem IN VOID LOOP()

Blynk.run();
  
   if(digitalRead(boia) == 0)
   {
     lcd.setCursor(0,1);
     lcd.print("NIVEL BAIXO");
     Blynk.virtualWrite(V0, 255);
     Blynk.virtualWrite(V1, 0);
   }
   else
      {
     lcd.setCursor(0,1);
     lcd.print("NIVEL OK");
     Blynk.virtualWrite(V0, 0);
     Blynk.virtualWrite(V1, 255);
      }

That is not a solution. Suggest you study the PUSH_DATA example for how to call functions at timed intervals.

I have refactored by removing “void loop ()”, below my code.

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>

/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// Inicializa o display no endereco 0x27
LiquidCrystal_I2C lcd(0x3F, 16, 4);

//NOVO
#define BLYNK_PRINT Serial
float temp;
int tempmin = 99;
int tempmax = 99;
int boia = 16;

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

                         
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "REDE DS";
char pass[] = "1234554321";

/*                        
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "LoVeS";
char pass[] = "123ab456cd";
*/
/*
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "CHICOS";
char pass[] = "a1b1c1d1e1";
*/

BlynkTimer timer;

void myTimerEvent()
{
   if(digitalRead(boia) == 0)
   {
     lcd.setCursor(-2,3);
     lcd.print("NIVEL BAIXO");
     Blynk.virtualWrite(V0, 255);
     Blynk.virtualWrite(V1, 0);
     digitalWrite(D7, LOW);
   }
   else
      {
     lcd.setCursor(-2,3);
     lcd.print("NIVEL OK");
     Blynk.virtualWrite(V0, 0);
     Blynk.virtualWrite(V1, 255);
     digitalWrite(D7, HIGH);
      } 

  sensors.requestTemperatures();       //Prepare the sensor for reading
  temp = sensors.getTempCByIndex(0);
  Serial.println(temp);
    Serial.println(tempmin);
      Serial.println(tempmax);

   if(tempmin > temp)
    {
     digitalWrite(D8, HIGH);
    }
   if(tempmax < temp)
    {
     digitalWrite(D8, LOW);
    }


  // ----Mostra dados no LCD----  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temp.:       ");
  //Simbolo grau
  lcd.write(223);
  lcd.print("C");
  lcd.setCursor(7,0);
  lcd.print(temp);
  
  lcd.setCursor(0,1);
  lcd.print("Temp.Min.:   ");
  lcd.write(223);
  lcd.setCursor(11,1);
  lcd.print(tempmin);
  lcd.setCursor(14,1);
  lcd.print("C");
  
  lcd.setCursor(-4,2);
  lcd.print("Temp.Max.:   ");
  lcd.write(223);
  lcd.setCursor(7,2);
  lcd.print(tempmax);
  lcd.setCursor(10,2);
  lcd.print("C"); 

  Blynk.virtualWrite(10, temp); //virtual pin V10
  Blynk.run();
  Blynk.virtualWrite(V5, millis() / 1000);

}


void setup()
{
  timer.setInterval(1000L, myTimerEvent);
  
  pinMode(boia,INPUT); 
 
  lcd.init();   // INICIALIZA O DISPLAY LCDLCD
  lcd.backlight(); // Enable or Turn On the backlight 

  // Debug console
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  sensors.begin();
}
  
BLYNK_WRITE(V11) //Set Temperature Button
{
tempmin = param.asInt();
}
BLYNK_WRITE(V12) //Set Temperature Button
{
tempmax = param.asInt();
}

  
void loop()
{
  timer.run(); // Initiates BlynkTimer
  Blynk.run();
}
/***************************************************
 * Send Sensor data to Blynk
 **************************************************/

Thank you for your attention.
What do you think of the new code?

Please see how I edited your post with formatted code.

Your changes are correct. You have used a timer to send Blynk VirtualWrites which is good practise.

Enormous improvement.

thanks for the help, friends.
I’m having a problem with my application.

1- My level sensor is only activating the relay if I put a button as a switch and click once, then the relay works normally. It’s like you need a start.
2- I turned on the door that triggers a relay to show me if it is on or off if the level is low, everything is working normal, but the button is not receiving the values of 0 or 1.

Thanks for the help.

?

Maybe the relay is active LOW, most are. You can switch the on and off in the app.

?

My level sensor:
image

2- I put a button(in blynk) on the door that activates a relay to show me if it is on or off if the level is low, everything is working normal, but the button is not receiving values of 0 or 1.

Buttons don’t tend to act as displays by default… are you refering to using Blynk.virtualWrite(vPin, value) and/or Blynk.setProperty(vPin, “property”, value). If so, just follow the Documentation and also look at this Sync Physical Button example sketch for the general principle.

Could it be a wiring problem? Or a problem with a “floating value” because you do not have a pull up/down resistor in your circuit? How are you activating the relay? Do you have the proper voltage and current for the relay coil coming from your microprocessor?

I’ll try thank you.

everything is ok with the wiring and so on.

How do I set the I2C RTC to the current time and date and send it to the Blynk?
using NodeMcu

Sounds like a new thread.

I’m create the New Topic.
Thank you.