Flow meter sensor + NodeMCU in Thinger, please

Good afternoon, someone can suggest me the programming of Flow Sensor FS300A in Thinger + NodeMCU

Hi @gleison_jayme, if you have a reading example from the sensor, maybe we can help you to integrate it in Thinger.io sketch.

ok

my sketch

volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
   flow_frequency++;
}
void setup()
{
   pinMode(flowsensor, INPUT);
   digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
   Serial.begin(9600);
   attachInterrupt(0, flow, RISING); // Setup Interrupt
   sei(); // Enable interrupts
   currentTime = millis();
   cloopTime = currentTime;
}
void loop ()
{
   currentTime = millis();
   // Every second, calculate and print litres/hour
   if(currentTime >= (cloopTime + 1000))
   {
      cloopTime = currentTime; // Updates cloopTime
      // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
      l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
      flow_frequency = 0; // Reset Counter
      Serial.print(l_hour, DEC); // Print litres/hour
      Serial.println(" L/hour");
   }
}

Looking at the sketch, you can easily start from the ESP8266 basic example, include the code in your example, and add an output resource in the setup like:

thing["flow"] >> outputValue(l_hour);

It should be easy… Best.

hi, thanks …

but a error in … unable to find numeric literal operator ‘operator"" _hour’

the complete sketch include Meter ad Flow … (meter ok)

#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>
#define USERNAME “-------------”
#define DEVICE_ID “ESP8266”
#define DEVICE_CREDENTIAL “------------------”

#define TRIGGER_PIN 5
#define ECHO_PIN 4

//defining SSID and password for the router
#define SSID “----”
#define SSID_PASSWORD "------"
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;

void flow () // Interrupt function
{
flow_frequency++;
}

void setup()
{
thing.add_wifi(SSID, SSID_PASSWORD);

thing[“flow”] >> outputValue(1_hour);
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
Serial.begin(9600);
attachInterrupt(0, flow, RISING); // Setup Interrupt
sei(); // Enable interrupts
currentTime = millis();
cloopTime = currentTime;

pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);

thing[“SONIC”] >> [] (pson& out){
double duration, distance;
digitalWrite(TRIGGER_PIN, LOW); // Get Start
delayMicroseconds(2); // stable the line
digitalWrite(TRIGGER_PIN, HIGH); // sending 10 us pulse
delayMicroseconds(10); // delay
digitalWrite(TRIGGER_PIN, LOW); // after sending pulse wating to receive signals
duration = pulseIn(ECHO_PIN, HIGH); // calculating time
distance = (duration/2) / 29.1; // single path

  if (( distance > 1 )&&(distance <20))
     {
      distance = 3000;
     }
     else
 
  if (( distance > 20 )&&(distance <23))
     {
      distance = 2900;
     }
  
  else

  if (( distance > 23 )&&(distance <26))
     {
      distance = 2800;
     }

  else

  if (( distance > 26 )&&(distance <29))
     {
      distance = 2700;
     }

else

  if (( distance > 29 )&&(distance <31))
     {
      distance = 2600;
     }

else

  if (( distance > 31 )&&(distance <34))
     {
      distance = 2500;
     }

else

  if (( distance > 34 )&&(distance <37))
     {
      distance = 2400;
     }

else

  if (( distance > 37 )&&(distance <40))
     {
      distance = 2300;
     }

else

  if (( distance > 40 )&&(distance <43))
     {
      distance = 2200;
     }

else

  if (( distance > 43 )&&(distance <46))
     {
      distance = 2100;
     }

else

  if (( distance > 46 )&&(distance <49))
     {
      distance = 2000;
     }

else

  if (( distance > 49 )&&(distance <52))
     {
      distance = 1900;
     }

else

  if (( distance > 52 )&&(distance <55))
     {
      distance = 1800;
     }

else

  if (( distance > 55 )&&(distance <58))
     {
      distance = 1700;
     }

else

  if (( distance > 58 )&&(distance <61))
     {
      distance = 1600;
     }

else

  if (( distance > 61 )&&(distance <64))
     {
      distance = 1500;
     }

else

  if (( distance > 64 )&&(distance <67))
     {
      distance = 1400;
     }

else

  if (( distance > 67 )&&(distance <70))
     {
      distance = 1300;
     }

else

  if (( distance >70 )&&(distance <73))
     {
      distance = 1200;
     }

else

  if (( distance > 73 )&&(distance <76))
     {
      distance =  1100;
     }

else

  if (( distance > 76 )&&(distance <79))
     {
      distance = 1000;
     }

else

  if (( distance > 79 )&&(distance <82))
     {
      distance = 900;
     }

else

  if (( distance > 82 )&&(distance <85))
     {
      distance = 800;
     }

else

  if (( distance > 85 )&&(distance <88))
     {
      distance = 700;
     }

else

  if (( distance > 88 )&&(distance <91))
     {
      distance = 600;
     }

else

  if (( distance > 91 )&&(distance <94))
     {
      distance = 500;
     }

else

  if (( distance > 94 )&&(distance <97))
     {
      distance = 400;
     }

else

  if (( distance > 97 )&&(distance <100))
     {
      distance = 300;
     }

else

  if (( distance > 100 )&&(distance <103))
     {
      distance = 200;
     }

else

  if (( distance > 103 )&&(distance <110))
     {
      distance = 100;
     }

else
{
distance = 10;
}
out = distance;
};
}

void loop()
{
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime; // Updates cloopTime
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
flow_frequency = 0; // Reset Counter
Serial.print(l_hour, DEC); // Print litres/hour
Serial.println(" L/hour");
}
thing.handle();
delay(1000);
}

Your variable is l_hour not 1_hour variables starting with numbers are not allowed. I recommend you to remove the delay(1000) in the loop for a better experience.

hi …perfect thanks.