Aquarium control help

Check out the PUSH DATA example in the Sketch Builder.

1 Like

Thanks Problem Solved. Now I add the other sensors

1 Like

Hi, I do not write the value of pin a1 in v2. Why?

 Blynk.virtualWrite(2,A1 ); //pin virtuale lampada spot

You have the following in your sketch:

#define NTCPIN A0 

and no mention of A0 as far as I can see.

If you are picking up data from the A0 port then you need:

Blynk.virtualWrite(2, NTCPIN ); //pin virtuale lampada spot

1 Like

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.