Water meter : grey scale sensor


  • Hero Member

    Hello,

    A friend of mine has a Sensus Residia Jet water meter, which can work through Z-wave with a "Secure SWM301 Water Meter Sensor".

    Only one domotic box support it but not the other at this time, so I tried to make it work with mysensors..

    I have found a way based on "DFRobot Analog Grayscale Sensor V2" that works !

    The sensor: http://www.dfrobot.com/index.php?route=product/product&product_id=81

    Simply scotch the sensor on the counter so that it detects the wheel (no magnet or visual signal on this counter... the zwave sensors uses VLF induction with two tors).

    IMG_20150630_172731.jpg

    /*
     Use this sensor to measure volume and flow of your house watermeter.
     You need to set the correct pulsefactor of your meter (pulses per m3).
     The sensor starts by fetching current volume reading from gateway (VAR 1).
     Reports both volume and flow back to gateway.
    
     Sensor on pin analog 0
     
     DFRobot Analog Grayscale Sensor V2
     Watermeter sensus Residia Jet
     
     http://www.dfrobot.com/index.php?route=product/product&product_id=81
    
    Contribution: Hek, adapted by epierre to greyscale sensor water meter
      License: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
    
    
    */
    
    #include <MySensor.h>  
    #include <SPI.h>
    
    #define ANALOG_INPUT_SENSOR 0                   // The analog input you attached your sensor. 
    #define PULSE_FACTOR 1000                       // Nummber of blinks per m3 of your meter (One rotation/liter)
    #define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.
    #define MAX_FLOW 40                             // Max flow (l/min) value to report. This filetrs outliers.
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2        // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 5                              // Id of the sensor child
    unsigned long SEND_FREQUENCY = 20000;           // Minimum time between send (in seconds). We don't want to spam the gateway.
    
    MySensor gw;
    MyMessage flowMsg(CHILD_ID,V_FLOW);
    MyMessage volumeMsg(CHILD_ID,V_VOLUME);
    MyMessage pcMsg(CHILD_ID,V_VAR1);
     
    double ppl = ((double)PULSE_FACTOR)/1000;        // Pulses per liter
    
    volatile unsigned long pulseCount = 0;   
    volatile unsigned long lastBlink = 0;
    volatile double flow = 0;   
    boolean pcReceived = false;
    unsigned long oldPulseCount = 0;
    unsigned long newBlink = 0;   
    double oldflow = 0;
    double volume;                     
    double oldvolume;
    unsigned long lastSend;
    unsigned long lastPulse;
    unsigned long currentTime;
    boolean metric;
    long lastDebounce = 0;
    long debounceDelay = 500;    // Ignore bounces under 1/2 second
    int oldval =0;
    int val=0;
    
    
    void setup()  
    {  
      gw.begin(incomingMessage); 
      
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Water Meter", "1.0 greyscale");
    
      // Register this device as Waterflow sensor
      gw.present(CHILD_ID, S_WATER);       
    
      // Fetch last known pulse count value from gw
       gw.request(CHILD_ID, V_VAR1);
    
      //Serial.print("Last pulse count from gw:");
      //Serial.println(pulseCount);
      //  attachInterrupt(INTERRUPT, onPulse, RISING);
      lastSend = millis();
      
      //led blinking
      pinMode(13, OUTPUT);
    }
    
    
    void loop()     
    { 
      gw.process();
      currentTime = millis();
    
      val=analogRead(0);
      //Serial.println(val);
      if ((oldval <100) and (val >100)) {
        pulseCount++;
        oldval=val;
      } else {
            oldval=val;
      }
      delay(100);	
        // Only send values at a maximum frequency or woken up from sleep
      bool sendTime = currentTime - lastSend > SEND_FREQUENCY;
      
        // Pulse count has changed
        if (pulseCount != oldPulseCount) {
          gw.send(pcMsg.set(pulseCount));                  // Send  volumevalue to gw VAR1
          double volume = ((double)pulseCount/((double)PULSE_FACTOR));     
          oldPulseCount = pulseCount;
          if (volume != oldvolume) {
            gw.send(volumeMsg.set(volume, 3));               // Send volume value to gw
            //Serial.print("V=");
            //Serial.println(volume);
            oldvolume = volume;
          } 
        }
        lastSend = currentTime;
        if (sendTime && !pcReceived) {
        // No count received. Try requesting it again
        gw.request(CHILD_ID, V_VAR1);
        lastSend=currentTime;
        }
      
      
    }
    
    
    void incomingMessage(const MyMessage &message) {
      if (message.type==V_VAR1) {  
        pulseCount = oldPulseCount = message.getLong();
        Serial.print("Received last pulse count from gw:");
        Serial.println(pulseCount);
        pcReceived = true;
      }
    }
    
    

    Here a picture of the emitter, a Nano with high range antennae in a box !
    IMG_20150701_143623.jpg


  • Hero Member

    @epierre Pretty Cool..



  • Hello. I'm very interested by your system to replace SWM301 with arduino nano and grey scale sensor. I'm new in arduino world and a little bit lost to succeed. I'm usine VERA as controller. Can you send me schematic for connexions of radio, grey scale sensor and the sketchs need to be included. I tried a serial gateway sketch, which seems to be uploaded but when I try to upload your sketch I have this error :

    WARNING: Spurious .ci folder in 'MySensors' library
    WARNING: Spurious .mystools folder in 'MySensors' library
    In file included from /Users/patriceagnesmetairie1 1/Documents/Arduino/sketch_compteur_eau/sketch_compteur_eau.ino:20:0:
    /Users/patriceagnesmetairie1 1/Documents/Arduino/libraries/MySensors-master/MySensors.h:405:2: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
    #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
    ^
    exit status 1

    can you help me ?
    Thanks a lot
    Patrice


  • Hero Member

    Hello,

    I've dropped this approch to use the CNY70 ir on this water meter.

    I did that for a friend that has not the mysensors gateway (range issue) so I made it with a Particle Photon using a wifi extender, but it is quite straightforward reading the pulse up and down.


  • Hero Member

    here is a link with the schematics (so simple !):https://easydomoticz.com/forum/viewtopic.php?f=17&t=1737&start=70



  • And why you do not remove a half of plastic cover above rotating sensor wheel to put sensor closer?


  • Hero Member

    it you remove plastic it is not water proof anymore, and greyscale was not precise enough....
    CNY70 has reflexion protection which is much better



  • @epierre Plus presumably it can be universally applied whether a wet or dry register?


Log in to reply
 

Suggested Topics

  • 87
  • 6
  • 7
  • 10
  • 2
  • 5

17
Online

11.4k
Users

11.1k
Topics

112.7k
Posts