Watermeter pulsesensor



  • I have build an sensor with the watermeterpulsesensor sketch with an arduino nano and the TCRT5000 module sensor.
    It works but everytime the value rises with 2 for one rotation of my watermeter. Default /1000 ( 1liter per rotation)
    So again when i get with a mirror and make the sensor go high (green led goes on) the value rises with 1 but when i remove the reflector (green led goes off) also the value rises wth one again.
    So it looks like the code triggers to the up and down going flank together of one pulse.
    Do i have to change something in the code?


  • Contest Winner

    @egbertje

    maybe you re getting some bounce which creates two interrupts...

    you could play around with that here:

    void onPulse()     
    { 
      if (!SLEEP_MODE) {
        unsigned long newBlink = micros();   
        unsigned long interval = newBlink-lastBlink;
    	lastPulse = millis();
        if (interval<500000L) {
          // Sometimes we get interrupt on RISING,  500000 = 0.5sek debounce ( max 120 l/min)<<<<<< HERE
          return;   
        }
        flow = (60000000.0 /interval) / ppl;
        lastBlink = newBlink;
      }
      pulseCount++; 
    }
    


  • Hi Bulldog,

    I allready played with that value and increased it to 2 or 3 seconds but that does not change my problem.
    I think the problem is that this code sees a pulse and when the pulse is going from zero to high it is 1 count but also when this pulse is going again to zero the count is 2.


  • Contest Winner

    @egbertje

    try the other edge yet?

    pinMode(2, INPUT_PULLUP); // keep pin from floating
    attachInterrupt(INTERRUPT, onPulse, FALLING);


  • Also this does not work (pinmode3)



  • This post is deleted!


  • After testing some more i get better result with this setting:
    attachInterrupt(INTERRUPT, onPulse, LOW);


Log in to reply
 

Suggested Topics

  • 4
  • 9
  • 8
  • 2
  • 4
  • 20

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts