ESP8266, Anemometer, Blynk

Hi. I have connect anenometer to ESP8266Devkit . But this sketch no showing data. I dont know why. One year ago this skecht working. I tryed update firmware and other Arduino IDE version and is it same. In app Blynk is ESP connecting but V1,V2,V3,V4 show still 0. Thanks.

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


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

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

 const int hallPin=3;
 volatile byte half_revolutions;
 unsigned int rpm, ms, kmh, maxMs, h1_2, m1_2, h3_4, m3_4, h5_6, m5_6, h7_8, m7_8, h9_10, m9_10, h11, m11, h3, m3, d1_2, d3_4, d5_6, d7_8, d9_10, d11, d3;
 unsigned long  count1_2, count3_4, count5_6, count7_8, count9_10, count_11, count_3;
 unsigned int den = 86400;
 unsigned int hodina = 3600;
 unsigned int minuta = 60;
 String zacatekMereni = "20.02.2017";

 SimpleTimer timer;

// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
  //get data stored in virtual pin V0 from server
  Blynk.syncVirtual(V30);
}

// restoring counter from server
BLYNK_WRITE(V30){
  //restoring int value
  maxMs = param[0].asInt();
  count1_2 = param[1].asLong();
  count3_4 = param[2].asLong();
  count5_6 = param[3].asLong();
  count7_8 = param[4].asLong();
  count9_10 = param[5].asLong();
  count_11 = param[6].asLong();
  count_3 = param[7].asLong();
}

void setup(){
   pinMode(hallPin,INPUT);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  attachInterrupt(digitalRead(hallPin), rpm_fun, RISING);
   half_revolutions = 0;
   rpm = 0;
   ms = 0;
   kmh = 0;

   timer.setInterval(3000L, mereniRPM); //kazdy tri vteriny vypocte ze signalu udaje
   timer.setInterval(600000L, zaloha); //kazdych 10 minut ulozi data na blynk server
   timer.setInterval(60000L, vypocet); //kazdou minutu vypocita udaje a posle na blynk
}

void zaloha(){
Blynk.virtualWrite(V30, maxMs, count1_2, count3_4, count5_6, count7_8, count9_10, count_11, count_3);
 }
 
void mereniRPM(){  
     rpm = (half_revolutions*20)/3;
     ms = half_revolutions/7;
     kmh = half_revolutions/2;
     
if (ms > maxMs) maxMs = ms;
if ((ms == 1)||(ms == 2)) count1_2 += 3;
if ((ms == 3)||(ms == 4)) count3_4 += 3;
if ((ms == 5)||(ms == 6)) count5_6 += 3;
if ((ms == 7)||(ms == 8)) count7_8 += 3;
if ((ms == 9)||(ms == 10)) count9_10 += 3;
if (ms >= 11) count_11 += 3;
if (ms >= 3) count_3 += 3;
     
//     Serial.println(half_revolutions,DEC); //pocet signalu za 3s. (3 signaly na otacku)
     Blynk.virtualWrite(V1, rpm);
     Blynk.virtualWrite(V2, ms);
     Blynk.virtualWrite(V3, kmh);
     Blynk.virtualWrite(V4, maxMs);

     half_revolutions = 0;
}

void vypocet(){
    d1_2 = count1_2 / den;
    h1_2 = (count1_2 % den) / hodina;
    m1_2 = ((count1_2 % den) % hodina) / minuta;

    d3_4 = count3_4 / den;
    h3_4 = (count3_4 % den) / hodina;
    m3_4 = ((count3_4 % den) % hodina) / minuta;

    d5_6 = count5_6 / den;
    h5_6 = (count5_6 % den) / hodina;
    m5_6 = ((count5_6 % den) % hodina) / minuta;

    d7_8 = count7_8 / den;
    h7_8 = (count7_8 % den) / hodina;
    m7_8 = ((count7_8 % den) % hodina) / minuta;

    d9_10 = count9_10 / den;
    h9_10 = (count9_10 % den) / hodina;
    m9_10 = ((count9_10 % den) % hodina) / minuta;

    d11 = count_11 / den;
    h11 = (count_11 % den) / hodina;
    m11 = ((count_11 % den) % hodina) / minuta;

    d3 = count_3 / den;
    h3 = (count_3 % den) / hodina;
    m3 = ((count_3 % den) % hodina) / minuta;

  if (m1_2 < 10) Blynk.virtualWrite(V5, d1_2, " d  ", h1_2, ":0", m1_2);
  else Blynk.virtualWrite(V5, d1_2, " d  ", h1_2, ":", m1_2);
  
  if (m3_4 < 10) Blynk.virtualWrite(V6, d3_4, " d  ", h3_4, ":0", m3_4);
  else Blynk.virtualWrite(V6, d3_4, " d  ", h3_4, ":", m3_4);
    
  if (m5_6 < 10) Blynk.virtualWrite(V7, d5_6, " d  ", h5_6, ":0", m5_6);
  else Blynk.virtualWrite(V7, d5_6, " d  ", h5_6, ":", m5_6);
    
  if (m7_8 < 10) Blynk.virtualWrite(V8, d7_8, " d  ", h7_8, ":0", m7_8);
  else Blynk.virtualWrite(V8, d7_8, " d  ", h7_8, ":", m7_8);
    
  if (m9_10 < 10) Blynk.virtualWrite(V9, d9_10, " d  ", h9_10, ":0", m9_10);
  else Blynk.virtualWrite(V9, d9_10, " d  ", h9_10, ":", m9_10);
    
  if (m11 < 10) Blynk.virtualWrite(V10, d11, " d  ", h11, ":0", m11);
  else Blynk.virtualWrite(V10, d11, " d  ", h11, ":", m11);
    
  if (m3 < 10) Blynk.virtualWrite(V11, d3, " d  ", h3, ":0", m3);
  else Blynk.virtualWrite(V11, d3, " d  ", h3, ":", m3);

  Blynk.virtualWrite(V12, zacatekMereni);
}

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

 }
 void rpm_fun()
 {
   half_revolutions++;
 }

Maybe you wired it up wrong this year :stuck_out_tongue:

PS, Lots of things can change in that time… for example, SimpleTimer is now replaced with BlynkTimer, and built into the Library…

You can delete this #include <SimpleTimer.h>;

And change this SimpleTimer timer; to this BlynkTimer timer;

http://docs.blynk.cc/#blynk-firmware-blynktimer

1 Like

So i fix it.Delete SimpleTimer.h and change to BlynkTimer timer; but is it same. Still blynk show 0.
And BlynkTimer timer; - is in BlynkSimpleEsp8266.h library ? Thanks.

Oh I know that wasn’t the cause of your issue… I have no idea about that… not enough info.

I was just pointing out that since things change like the timer, who knows what else has changed since you last tried it.

If connected but no values, then I would suspect physical connection, power, faulty sensor, etc. But you would have to test all that, and confirm proper Blynk connection and communication with some other process and display… perhaps an uptime counter?

1 Like

I think connection with anemometer is good.Arduino nano with my anemometer working good and ESP8266 devkit too one year ago… now no. I think something is wrong in a library…Thanks

const int m_time = 5;      //Meassuretime in Seconds
int wind_ct = 0;
float wind = 0.0;
unsigned long time = 0;


void setup()
{
  Serial.begin(9600);
  time = millis();
}

void loop()
{

  meassure();

  Serial.print("Windgeschwindigkeit: ");
  Serial.print(wind);       //Speed in Km/h
  Serial.print(" km/h - ");
  Serial.print(wind / 3.6); //Speed in m/s
  Serial.println(" m/s");

}

void countWind() {
  wind_ct ++;
}

void meassure() {
  wind_ct = 0;
  time = millis();
  attachInterrupt(1, countWind, RISING);
  delay(1000 * m_time);
  detachInterrupt(1);
  wind = (float)wind_ct / (float)m_time * 2.4;
}


https://www.youtube.com/watch?v=5CyexLsvuwg&feature=youtu.bev

And in Serial Monitor i have this:

[6974] Connected to WiFi
[6974] IP: 192.168.1.122
[6974] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.1 on Arduino

[7044] Connecting to blynk-cloud.com:80
[7130] <[02|00|01|00] b003999375154c80a70f16c3365b86c5
[7162] >[00|00|01|00|C8]
[7172] Ready (ping: 9ms).
[7201] Free RAM: 44648
[7238] <[11|00|02|00]Hver[00]0.5.1[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Arduino[00]build[00]Nov 30 2018 23:24:15[00]
[7375] >[00|00|02|00|C8]
[7442] <[10|00|03|00|05]vr[00]30
[7460] >[14|00|03|00|15]
[7460] >vw[00]30[00]3[00]0[00]3[00]0[00]0[00]0[00]0[00]3
[10507] <[14|00|04|00|06]vw[00]1[00]0
[10635] <[14|00|05|00|06]vw[00]2[00]0
[10719] <[14|00|06|00|06]vw[00]3[00]0
[10804] <[14|00|07|00|06]vw[00]4[00]3
[13507] <[14|00|08|00|06]vw[00]1[00]0
[13594] <[14|00|09|00|06]vw[00]2[00]0
[13678] <[14|00|0A|00|06]vw[00]3[00]0
[13762] <[14|00|0B|00|06]vw[00]4[00]3
[16507] <[14|00|0C|00|06]vw[00]1[00]0
[16600] <[14|00|0D|00|06]vw[00]2[00]0
[16693] <[14|00|0E|00|06]vw[00]3[00]0
[16778] <[14|00|0F|00|06]vw[00]4[00]3
[17507] <[06|00|10|00|00]
[17526] >[00|00|10|00|C8]
[19507] <[14|00|11|00|06]vw[00]1[00]0
[19630] <[14|00|12|00|06]vw[00]2[00]0
[19720] <[14|00|13|00|06]vw[00]3[00]0
[19805] <[14|00|14|00|06]vw[00]4[00]3
[22507] <[14|00|15|00|06]vw[00]1[00]0
[22592] <[14|00|16|00|06]vw[00]2[00]0
[22677] <[14|00|17|00|06]vw[00]3[00]0
[22762] <[14|00|18|00|06]vw[00]4[00]3

Different perhaps, but not likely wrong.

Since Blynk’s 'influence" is primarily in the transmission of the data to the App, try confirming your data values with serial prints.

And how can i confirming your data values with serial prints? Thanks

I can’t teach you how to program :stuck_out_tongue: but look here…

https://www.arduino.cc/reference/en/language/functions/communication/serial/print/

1 Like

Oh yes i know. So i tryed and in Serial Monitor is too 0.

void loop(){

  Serial.print(ms / 3.6); //Speed in m/s
  Serial.print(ms);
  Serial.println(" ms");
 
  Blynk.run();
  timer.run(); // Initiates SimpleTimer

 }

But why? Thanks

So i change

const int wind=12; //pin D6

//  attachInterrupt(digitalRead(wind), rpm_fun, RISING);
  attachInterrupt(wind, rpm_fun, RISING);

And now is it working. :blush:

1 Like