Shop OBEX P1 Docs P2 Docs Learn Events
household water meter using a basicstamp 2??? — Parallax Forums

household water meter using a basicstamp 2???

tercou1tercou1 Posts: 25
edited 2011-11-13 19:38 in BASIC Stamp
I have been given a project to build a household water meter, where I have to design it myself. I have decided to use a bs2 to process the data from the water flow meter to a parallax serial LCD and was wondering if anyone has interfaced one with a Basic Stamp before. I am interested in measuring the real time flow and a totalized flow to start with and then maybe a freeze alarm, a no flow alarm and a back flow alarm. If anyone has any links or has tried something similar I would appreciate any info they may have.

The water flow meter I am using is a turbine 1/2" magnetic pulse Hall effect sensor with digital output.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-08 17:44
    I assume that the flow meter puts out some specific number of pulses per revolution of the turbine and there's some formula for translating pulses per minute to gallons per minute or something like that. The COUNT statement in PBasic is intended for this sort of use (see the Basic Stamp Syntax and Reference Manual) and counts the number of received pulses in a specified period of time. You'd then have to convert that to a water flow rate. I don't know how you'd determine back flow unless the sensor puts out a different signal for reversed rotation of the turbine.
  • xanatosxanatos Posts: 1,120
    edited 2011-11-08 19:08
    I actually have just completed two projects that do exactly this, except for volatile fluids, not water. And the COUNT command is exactly what I used. The flowmeter came with a datasheet that indicates pulses per gallon for different fluid viscosities and flow rates, and I just took an average of the good ones. In my case the max flow rate still provided pulses at a low enough rate that the calculations that take place every second occur well within the space between two pulses, so no pulses are lost at any point.

    As for backflow- does it need to be allowed to do that? I'd just suggest including a backflow preventer, and you no longer need to account for that.

    Happy to help if I can, just ask.

    Dave
  • tercou1tercou1 Posts: 25
    edited 2011-11-09 17:14
    Thanks Mike, This was very helpful. This is my first time using a stamp... I'm going to use a non return valve for the back flow.
  • tercou1tercou1 Posts: 25
    edited 2011-11-09 18:17
    Thanks Dave, I've decided to use a non return valve for the back flow issue, I have attached the datasheet for the flow sensor i'm using. If I was to mount it horizontally (from datasheet), could I use a count statement and then a number of 'if' statements to determine the real time flowFLOW25L0 datasheet.pdf?

    something like: count for 1 sec,,,
    if count < 5(pulses per sec) then real time flow is 1.5 L/min (output on pin ?)
    if count >= 5 && count < 30 then real time flow is 6 L/min
    if count >= 30 && count < 65 then real time flow is 15 L/min
    if count >= 65 then real time flow is 20 L/min

    as you have probably guessed I'm a complete newbie but I'm a very fast learner... I really appreciate any time that you guys can spend with me on this... I'll update my progress and if I'm going off the beaten track, can you nudge me back in the right direction??
  • FalconFalcon Posts: 191
    edited 2011-11-10 04:39
    If you don't mine me asking, what was the price and source for this flow sensor? I'm looking for something like this in the 1" size.

    falcon
  • tercou1tercou1 Posts: 25
    edited 2011-11-10 09:45
    Here's the website Falcon... prices are very reasonable:

    http://www.futurlec.com/FLOW25L0.shtml
  • FalconFalcon Posts: 191
    edited 2011-11-11 04:36
    tercou1,
    Thanks for the link. I started off getting just the flow sensor and before I was finished I had a cart full of stuff.

    I'll be monitoring this thread because I have a plan similar to yours.

    Thanks,

    falcon
  • xanatosxanatos Posts: 1,120
    edited 2011-11-11 15:35
    Hi Tercou1,

    I don't know the specs on your flowmeter, but mine runs around 220 pulses per gallon. So I set my ppg VAR to 220 and here's the rest of the goodies I do to get my count:
    Main:
    
    rawCount = 0
    galsPumped = 0
    GalTotal = 0
    
    DO
    
        COUNT flowCount, 2500, rawCount     ' 1000 for BS2 (1ms/count); 2500 for BS2sx (400uS/count).
    
        rawCount = rawCount + remains
        galsPumped = rawCount / ppg
        remains = rawCount - (galsPumped * ppg)
        galTotal = galTotal + galsPumped
    
        IF IN8 = 1 THEN
          GOSUB Reprint
        ENDIF
    
    LOOP UNTIL IN3 = 0
    
    remains = (remains * 10)/ppg
    GOSUB Get_Time
    GOSUB Print_2
    
    PUT 0, Word galTotal ' Word
    PUT 2, remains       ' Byte
    PUT 3, month
    PUT 4, date
    PUT 5, year
    PUT 6, hrs
    PUT 7, mins
    
    galsPumped = 0
    rawCount = 0
    galTotal = 0
    remains = 0
    
    DO
      DEBUG "Waiting for button to release...", CR
      PAUSE 100
    LOOP UNTIL IN3 = 1
    
    GOTO Main
    
    
    END
    
    
    

    I've got some GOSUBS in there, but the stuff you're interested in is all there - how I count pulses, figure gallons, and do it to a 1/10th gallon accuracy. I could go more accurate, but the client isn't that concerned about anything less than a tenth.

    Let me know if it all makes sense to you.

    Dave
  • tercou1tercou1 Posts: 25
    edited 2011-11-12 07:11
    Dave thanks for sharing this code, it's something to get my teeth into....thanks again, really appreciated
  • xanatosxanatos Posts: 1,120
    edited 2011-11-12 07:33
    Happy to help... let me know how it goes.

    Dave
  • tercou1tercou1 Posts: 25
    edited 2011-11-13 19:17
    ok so here's the code I have so far, with a big thanks to Dave,

    ' =========================================================================
    '
    ' File...... Domestic Water Meter.BS2
    ' Purpose... To measure current flow rate and total flow rate
    ' in liters per second through a flow sensor
    ' Student... B00008869
    ' Started... 10 Nov 2011
    ' Updated... 14 Nov 2011
    '
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    ' =========================================================================
    '
    '
    '
    [ I/O Definitions ]


    SpeedIn PIN 14 'Receive Input from Hall Sensor


    '
    [ Constants ]



    Capture CON 1000 ' Num of msec to listen for input
    ppl CON 216 ' pulses per liter

    '
    [ Variables ]

    remains VAR Byte
    literspumped VAR Word ' total pulses after 10 secs
    pulses VAR Word ' input pulses from flow sensor
    average VAR Word ' average of pulses over 10 secs
    totalLiters VAR Word
    '
    [ Initialization ]



    pulses = 0
    literspumped = 0
    totalLiters = 0

    DO
    COUNT SpeedIn, Capture, pulses

    pulses = pulses + remains
    literspumped = pulses / ppl
    remains = pulses - (literspumped * ppl)
    totalLiters = totalLiters + literspumped

    DEBUG CR, "Pulses = ", DEC pulses, CR
    DEBUG CR, "liters pumped = ", DEC literspumped, CR
    DEBUG CR, "total pumped = ", DEC totalLiters, CR
    PAUSE 1000


    LOOP

    END

    seems to be working pretty well... but i'm still not sure how the "remains" variable works... it seems to me that it is the equivalent of subtracting pulses from pulses, so how does it have a value?? can you enlighten me dave, or anybody else. thanks in advance
  • xanatosxanatos Posts: 1,120
    edited 2011-11-13 19:30
    Remains is what is left after you divide out your raw count with your pulse count. You have 216 ppl, so say you pump 2168 pulses in your 10 second window. After you divide out your integer value of pulses ( remember BS2 doesn't do floating point math) you get 10 litres. Then you subtract that even number of pulses (2160) from your raw count and you get a remains of 8. Rather than drop those pulses, they get added in at the beginning of each loop. It's an accounting thing so little errors don't creep in.

    Did I explain this well enough? Just let me know.

    Dave
  • tercou1tercou1 Posts: 25
    edited 2011-11-13 19:38
    thanks dave, makes perfect sense now...
Sign In or Register to comment.