Aquarium control help

Would you give me a last help? I need to add a flowmeter and let it write the liters / minutes on the virtual pin 4. i do not know where to start. These are the characteristics of the flow meter
1, appearance of product identification clear, accurate to meet the requirements in line
2, hydrostatic pressure less than1.75MPa
3, Operating voltage range DC3 ~ 24V compliance
4, Insulation resistance> 100MΩ> 100MΩ
5, Accuracy in 1 ~ 60L / MIN ± 2% in line
6, Flow pulse characteristics F = (0.55 * Q) Q = L / Min meet
7, low temperature test at -20 ° C temperature set after 72h, at room temperature for 1h, the first measurement accuracy within ± 5% value in line
8, high temperature test temperature at 85 ° C placed after 72h, at room temperature for 1h, the first measurement accuracy within ± 5% value

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx96f";
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
int ThermistorPin = 0;
int SpotPin = 1;
int UvbPin = 2;
int Vo;
int lux1;
int lux2;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Fxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxx";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial

// or Software Serial on Uno, Nano...
SoftwareSerial softSerial(10, 11); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)

{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable

  // process received value
}
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.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 50000);
   Blynk.virtualWrite(V2, millis() / 50000);
   Blynk.virtualWrite(V3, millis() / 50000);
}

void setup() 
{
   
  uint32_t baud = 115200;
  Serial.begin(baud);
  softSerial.begin(baud);
  Serial.print("SETUP!! @");
  Serial.println(baud);
   // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  
}


void loop() 
{
   Blynk.run(); 
   lux2=analogRead(UvbPin);
  lux1=analogRead(SpotPin);
  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 

  Serial.print("Temperature: "); 
  Serial.print(Tf);
  Serial.print(" F; ");
  Serial.print(Tc);
  Serial.println(" C");   


 
  Blynk.virtualWrite(1,Tc ); //pin virtuale lampada temp
  Blynk.virtualWrite(2,lux1 ); //pin virtuale lampada temp
    Blynk.virtualWrite(3,lux2 ); //pin virtuale lampada temp
timer.run(); // Initiates BlynkTimer
   




  

    
}

There are several flow meter threads on this site. Take a look at this thread and the instructable link that we were involved in [SOLVED] Flow meter intergration with Wemos D1

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
char auth[] = "**";
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
int ThermistorPin = 0;
int SpotPin = 1;
int UvbPin = 2;
int Vo;
int lux1;
int lux2;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 4;

// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 0.55;

volatile byte pulseCount;  

float flowRate;
int flowMilliLitres;
float totalMilliLitres;
float totalpour;
unsigned long oldTime; 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "**-1-EAgN0OZffijm";
char pass[] = "***";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial

// or Software Serial on Uno, Nano...
SoftwareSerial softSerial(10, 11); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)

{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable

  // process received value
}
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.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 50000);
   Blynk.virtualWrite(V2, millis() / 50000);
   Blynk.virtualWrite(V3, millis() / 50000);
   Blynk.virtualWrite(V4, millis() / 50000);
}

void setup() 
{
   
  uint32_t baud = 115200;
  Serial.begin(baud);
  softSerial.begin(baud);
  Serial.print("SETUP!! @");
  Serial.println(baud);
   // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
 pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  
}


void loop() 
{
   Blynk.run(); 
   lux2=analogRead(UvbPin);
  lux1=analogRead(SpotPin);
  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 

  Serial.print("Temperature: "); 
  Serial.print(Tf);
  Serial.print(" F; ");
  Serial.print(Tc);
  Serial.println(" C");   


 
  Blynk.virtualWrite(1,Tc ); //pin virtuale lampada temp
  Blynk.virtualWrite(2,lux1 ); //pin virtuale lampada temp
    Blynk.virtualWrite(3,lux2 ); //pin virtuale lampada temp



   
   if((millis() - oldTime) > 1000)    // Only process counters once per second
  { 
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    detachInterrupt(sensorInterrupt);
        
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    
    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();
    
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;
      
    totalpour =(20 - (totalMilliLitres / 1000));
    
  

    // Print the cumulative total of litres flowed since starting
 
    Serial.print(" Keg Remaining: ");
    Serial.print(totalpour, 2);
    Serial.println(" Litres ");
    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
     Blynk.virtualWrite(4,totalpour ); //pin virtuale lampada temp
    timer.run(); // Initiates BlynkTimer
  }
  }

/*
Insterrupt Service Routine
 */
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}

It is OK?Works on nano arduino

No it’s not OK, remember what you learnt from the PUSH DATA example?

1 Like
Blynk.begin(auth);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

Do I have to add this?With this the sensors are not stable. The second one marks a value of 2

Suggest you study the instructables code.

thing? Sorry I am new to the Arduino world

 #include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
char auth[] = "**************************************";
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
int ThermistorPin = 0;
int SpotPin = 1;
int UvbPin = 2;
int Vo;
int lux1;
int lux2;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 4;

// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.8;

volatile byte pulseCount;  

float flowRate;
int flowMilliLitres;
float totalMilliLitres;
float totalpour;
unsigned long oldTime; 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****************";
char pass[] = "******************";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial

// or Software Serial on Uno, Nano...
SoftwareSerial softSerial(10, 11); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)

{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable

  // process received value
}
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.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() /  100000);
   Blynk.virtualWrite(V2, millis() / 100000);
   Blynk.virtualWrite(V3, millis() / 100000);
   Blynk.virtualWrite(V4, millis() / 100000);
}

void setup() 
{
   
  uint32_t baud = 115200;
  Serial.begin(baud);
  softSerial.begin(baud);
  Serial.print("SETUP!! @");
  Serial.println(baud);
   // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
 pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  
}


void loop() 
{
   Blynk.run(); 
   lux2=analogRead(UvbPin);
  lux1=analogRead(SpotPin);
  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 

  

 
  Blynk.virtualWrite(1,Tc ); //pin virtuale lampada temp
  Blynk.virtualWrite(2,lux1 ); //pin virtuale lampada temp
    Blynk.virtualWrite(3,lux2 ); //pin virtuale lampada temp



   
   if((millis() - oldTime) > 1000)    // Only process counters once per second
  { 
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    detachInterrupt(sensorInterrupt);
        
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    
    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();
    
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;
      
    totalpour =(20 - (totalMilliLitres / 1000));
    
  

    // Print the cumulative total of litres flowed since starting
 
   
    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
     Blynk.virtualWrite(4,flowRate*60 ); //pin virtuale flusso per minuto
    timer.run(); // Initiates BlynkTimer
      delay(1000);
  }
  }

/*
Insterrupt Service Routine
 */
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}

I work perfectly but sometimes I disconnect. How ever?
Arduino nano + esp8266wifi
https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/42/03/metablogapi/0385.image_714FA209.png

I’m surprised when you say it works perfectly with this huge Baudrate…
And please… your code looks like Arduino world, not Blynk style… Follow @Costas’ recommendations…

But I can not figure out how to modify it in blynk style. Does the baudrate put it at 9600?I’m at the first experience with Arduino. Please help me.

I changed the bitrate to 9600 but I still disconnect every 24 hours. Anyone can kindly help me?

Yes, read the whole thread again.

Done but I do not understand.

OK, what did learn from the PUSH_DATA example?

And what do you think this code does in your sketch?

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   Blynk.virtualWrite(V1, millis() /  100000);
   Blynk.virtualWrite(V2, millis() / 100000);
   Blynk.virtualWrite(V3, millis() / 100000);
   Blynk.virtualWrite(V4, millis() / 100000);
}
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() /  100000);
    Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 
  Blynk.virtualWrite(1,Tc ); //pin virtuale lampada temp

errors?

That looks MUCH better than what you had before.

 #include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
char auth[] = "**************************************";
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
int ThermistorPin = 0;
int SpotPin = 1;
int UvbPin = 2;
int Vo;
int lux1;
int lux2;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 4;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.8;
volatile byte pulseCount;  
float flowRate;
int flowMilliLitres;
float totalMilliLitres;
float totalpour;
unsigned long oldTime; 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****************";
char pass[] = "******************";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial
// or Software Serial on Uno, Nano...
SoftwareSerial softSerial(10, 11); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9500
ESP8266 wifi(&EspSerial);
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // process received value
}
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.

void setup() 
{
  uint32_t baud = 115200;
  Serial.begin(baud);
  softSerial.begin(baud);
  Serial.print("SETUP!! @");
  Serial.println(baud);
   // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
 pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
   // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
}
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() /  100000);
    Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 
  Blynk.virtualWrite(1,Tc ); //pin virtuale lampada temp
   

  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, millis() /  100000);
   lux1=analogRead(SpotPin);

  Blynk.virtualWrite(2,lux1 ); //pin virtuale lampada temp
  
   

  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V3, millis() /  100000);
    lux2=analogRead(UvbPin);
 
    Blynk.virtualWrite(3,lux2 ); //pin virtuale lampada temp
  
  
 
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V4, millis() /  100000);
   if((millis() - oldTime) > 1000)    // Only process counters once per second
  
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    detachInterrupt(sensorInterrupt);
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;
    totalpour =(20 - (totalMilliLitres / 1000));
    // Print the cumulative total of litres flowed since starting
    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
     Blynk.virtualWrite(4,flowRate*60 ); //pin virtuale flusso per minuto
    
  }
  

void loop() 
{
   Blynk.run(); 
    timer.run(); // Initiates BlynkTimer
  
  }

Are there any other errors?

Probably, all the best code has some errors :slight_smile:

You didn’t answer this question.

I notice you still have this in your sketch but you have “hidden” it amongst other code. What do you think this code does and why do you have it in your sketch? If you don’t know the answer simply say so but don’t ignore our questions if you want to move forward.

Rather expect Blynkers to debug your code you need to do comprehensive testing and if you can’t find the bugs give a detailed description of what you are trying to do, what results you expected and what results you actually received. Rather than a catch all “does my sketch have any bugs?”.

I think this sketch tells you to write the value on v1 once per second. Right? I’m ignorant of programming and even in english. Go with goole translator so i apologize




 #include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
char auth[] = "**************************************";
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
int ThermistorPin = 0;
int SpotPin = 1;
int UvbPin = 2;
int Vo;
int lux1;
int lux2;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 4;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.8;
volatile byte pulseCount;  
float flowRate;
int flowMilliLitres;
float totalMilliLitres;
float totalpour;
unsigned long oldTime; 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****************";
char pass[] = "******************";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial
// or Software Serial on Uno, Nano...
SoftwareSerial softSerial(10, 11); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // process received value
}
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.

void setup() 
{
  uint32_t baud = 115200;
  Serial.begin(baud);
  softSerial.begin(baud);
  Serial.print("SETUP!! @");
  Serial.println(baud);
   // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
 pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
   // Setup a function to be called every second
  timer.setInterval(5000L, myTimerEvent);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
}
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}
void myTimerEvent()
{
  

    Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 
  Blynk.virtualWrite(1,Tc ); //pin virtuale lampada temp
   

 
 
   lux1=analogRead(SpotPin);

  Blynk.virtualWrite(2,lux1 ); //pin virtuale lampada temp
  
   

  

    lux2=analogRead(UvbPin);
 
    Blynk.virtualWrite(3,lux2); //pin virtuale lampada temp
  
  
 
  
   if((millis() - oldTime) > 1000)    // Only process counters once per second
  
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    detachInterrupt(sensorInterrupt);
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;
    totalpour =(20 - (totalMilliLitres / 1000));
    // Print the cumulative total of litres flowed since starting
    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
     Blynk.virtualWrite(4,flowRate*60 ); //pin virtuale flusso per minuto
    
  }
  

void loop() 
{
   Blynk.run(); 
    timer.run(); // Initiates BlynkTimer
  
  }

By analyzing the line I do not understand what it is for. that all right?

Google is not just for translation.

Almost all ESP code is based around Arduino code.

So something like “Arduino millis” as a search term in Google will give you a good idea of what the code does. Use the same format for any code you don’t understand.

Almost all MCU’s start an internal “clock” when they are reset and the clock starts at time zero. So the millis() function tells you how long the MCU has been running and is commonly referred to as uptime. millis as the name suggests is measured in milliseconds so quite often you will see millis() / 1000 to show the uptime seconds and it’s very rare you would see millis() / 100000.

So this code interspersed with your other code:

   Blynk.virtualWrite(V1, millis() /  100000);
   Blynk.virtualWrite(V2, millis() / 100000);
   Blynk.virtualWrite(V3, millis() / 100000);
   Blynk.virtualWrite(V4, millis() / 100000);

sends the uptime in 100th’s of a second to V1 widget, then send the uptime in 100th’s of a second to V2 widget etc.
Totally useless information for almost all projects and you should remove the 4 lines of code from your sketch.

The reason the PUSH_DATA example uses millis() is because it’s an inbuilt “sensor” that all MCU’s have rather than temperature, light or wind sensors that some Blynkers will have but many will not.

2 Likes