sample sketch to read a water meter and upload to web site

I'm new to the Arduino world, but I did research a little. I see others have done something similar but can't find exactly what I need so I'd appreciate your inputs greatly.

I'm considering installing a water meter with a reed switch (100 pulses / gal) at a vacation home I have. I'd like to use the Uno and essentially count the pulses, do the math and upload data to a website for easy monitoring. Or better yet, eventually do a Smartthings (ST) integration. ST can wait; I'll settle right now for just being able to see if water is flowing whenever I want to and how much. I already have a remotely operated cutoff valve by which I can turn water off from my ST hub and iPhone.

I'm using an Uno and a Ethernet shield (W5100). I also have the ST shield for the Uno, but I figure that is a whole new set of challenges (i.e. having a ST tile that shows me water usage on my iPhone). I figure get the basic setup working with a LAN; then try other improvements.

So, two questions:

  1. Can someone point me to a sketch that would read the reed switch interrupts and totalize the count; converting that to gallons & then send that a website for access.

  2. Suggestions and hints on uploading that data to a website to plot the data; popular websites, etc?

Thank you in advance,

Dave

for (1) I did something similar long ago, count pulses of a KWH meter.
code will be roughly the same

you probably do make it simpler by just updating the counter in the interrupt

volatile unsigned long count = 0;
unsigned long count_old = 0;

// The interrupt routine
void IRQ()
{
    count++;                    // just increment raw pulse counter.
}

float readFlow()
{
    // prevent interrupts happening while copy the counter
    cli;
    unsigned long t = count;
    sei;
    float val = (t - count_old)/22.0;  // adjust formula to your needs.
    count_old = t;
    return val;
}

///////////////////////////////////////
void setup() 
{
    Serial.begin(115200);
    Serial.println("Start flowmeter 0.1");
    
    attachInterrupt(0, IRQ, FALLING);
}

//
// MAIN LOOP
//
void loop() 
{
    delay(1000);
	float flow = readFLow();
	Serial.print("Flow: ");    
	Serial.print(flow, 4);
}

should get you started

Thanks Rob... I'll give it a look.

Dave

I use a stripped down version of this

Nick,

Very interesting project. I might go this route. I like the reset buttons. Not sure on some of the code though, but I'll do some experimenting.

Dave

It is an example of counting in the background using interrupt. I have found it extraordinarily accurate for quantity but useless for rate. In the light of the former I believe the rate could be fixed by having a longer time window or taking an average. I got rid of the reset stuff.

Dumb question.
Can't the rate be calculated faster from the time (millis) between two pulses.
Leo..

Not that dumb. There is no problem with the calcs, it’s with the variations and rate of update. In the programme I alluded to, the display - l/min - is updated every second but it varies like crazy and you have no idea what is really going on.

Having said that, measuring litres each day, which is still a rate, puts Arduino with a $5 turbine within about 1% of an expensive commercial unit with all the government standards marks on it, and you know exactly what is going on.

I don’t think OP is interested in 1 second updates, and stripping that out of the Jaycar programme will probably be fine.

I am interested in rapid updates but I’m not too sure what to do. In the light of the accurate daily rates, it may be OK to trust Arduino to get on with the calcs and just not display them.