Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. aesanto
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    aesanto

    @aesanto

    2
    Reputation
    1
    Posts
    305
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    aesanto Follow

    Best posts made by aesanto

    • RE: Water Flow sensor

      Hi,

      Here you can find a simplified version of the WaterFlow node.
      This version only sends to the GW the current flow volume in liters/hour.
      I don't know your model (G??) as the pulses per liter/hour vary from different flow sensors. Mine is G1" so the math is for this sensor.

      I had a problem with interrupts, and this was the way i found to work.

      Hope this helps!

      #include <SPI.h>
      #include <MySensor.h>  
      
      #define DIGITAL_INPUT_SENSOR 3                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)
      #define SENSOR_INTERRUPT DIGITAL_INPUT_SENSOR-2        // Usually the interrupt = pin -2 (on uno/nano anyway)
      
      #define CHILD_ID 1                              // Id of the sensor child
      
      int READ_INTERVAL = 3;           // Read interval to count the pulses (in seconds). 
      
      long lastReadStart;
      int flow;
      
      MySensor gw;
      MyMessage flowMsg(CHILD_ID,V_FLOW);
      
      
      int READ_INTERVAL_MILLIS=READ_INTERVAL * 1000;        // Just to simple the math!
      volatile unsigned long pulseCount = 0;   
      
      void setup()  
      {  
        gw.begin(); 
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Water Meter", "1.2");
      
        // Register this device as Waterflow sensor
        gw.present(CHILD_ID, S_WATER);       
      
        pulseCount = 0;
      
        lastReadStart = millis();
      
        attachInterrupt(SENSOR_INTERRUPT, onPulse, RISING);
      }
      
      
      void loop()     
      { 
        unsigned long currentTime = millis();
      	
      
        if (currentTime - lastReadStart > READ_INTERVAL_MILLIS)
        {
          flow = pulseCount*60/READ_INTERVAL;  //Need to change here for the G type
          lastReadStart=currentTime;
           
      
      
            Serial.print("l/hour:");
            Serial.println(flow);
            gw.send(flowMsg.set(flow));
            
            pulseCount = 0;
        }
      }
      
      
      void onPulse()
      {
        pulseCount++; 
      }```
      posted in My Project
      aesanto
      aesanto

    Latest posts made by aesanto

    • RE: Water Flow sensor

      Hi,

      Here you can find a simplified version of the WaterFlow node.
      This version only sends to the GW the current flow volume in liters/hour.
      I don't know your model (G??) as the pulses per liter/hour vary from different flow sensors. Mine is G1" so the math is for this sensor.

      I had a problem with interrupts, and this was the way i found to work.

      Hope this helps!

      #include <SPI.h>
      #include <MySensor.h>  
      
      #define DIGITAL_INPUT_SENSOR 3                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)
      #define SENSOR_INTERRUPT DIGITAL_INPUT_SENSOR-2        // Usually the interrupt = pin -2 (on uno/nano anyway)
      
      #define CHILD_ID 1                              // Id of the sensor child
      
      int READ_INTERVAL = 3;           // Read interval to count the pulses (in seconds). 
      
      long lastReadStart;
      int flow;
      
      MySensor gw;
      MyMessage flowMsg(CHILD_ID,V_FLOW);
      
      
      int READ_INTERVAL_MILLIS=READ_INTERVAL * 1000;        // Just to simple the math!
      volatile unsigned long pulseCount = 0;   
      
      void setup()  
      {  
        gw.begin(); 
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Water Meter", "1.2");
      
        // Register this device as Waterflow sensor
        gw.present(CHILD_ID, S_WATER);       
      
        pulseCount = 0;
      
        lastReadStart = millis();
      
        attachInterrupt(SENSOR_INTERRUPT, onPulse, RISING);
      }
      
      
      void loop()     
      { 
        unsigned long currentTime = millis();
      	
      
        if (currentTime - lastReadStart > READ_INTERVAL_MILLIS)
        {
          flow = pulseCount*60/READ_INTERVAL;  //Need to change here for the G type
          lastReadStart=currentTime;
           
      
      
            Serial.print("l/hour:");
            Serial.println(flow);
            gw.send(flowMsg.set(flow));
            
            pulseCount = 0;
        }
      }
      
      
      void onPulse()
      {
        pulseCount++; 
      }```
      posted in My Project
      aesanto
      aesanto