## How to sum up the data read by sensor?

hefeilong1991
Posts: 15
Joined: Wed May 14, 2014 1:38 am

### How to sum up the data read by sensor?

I have one project to record the usage of water daily use raspberry and water flow sensor . I am able to run the sensor with my code but I do not know how to sum up all the readings.
The water flow meter I use is http://www.seeedstudio.com/wiki/G1/2_Water_Flow_sensor
below is the part of my code

Code: Select all

``````if count >2:
totaltime = endtime - starttime
flow = totaltime * 30 * 0.26417
``````
my question is how to sum up after a new reading had read?
Please help me.thank you

joan
Posts: 14763
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

### Re: How to sum up the data read by sensor?

Perhaps have a variable called total_flow and add flow to that variable each time flow is calculated.

rgrbic
Posts: 128
Joined: Thu Jun 12, 2014 1:07 pm
Contact: Website

### Re: How to sum up the data read by sensor?

You have to get the value from sensor in liters per second. Read the sensor every second and just add the reading to some variable which you have to set to 0 every day.
Or, if you don't need current flow then just count the pulses and at the end of a day calculate consumption in liters.
At 127.0.0.1
Twitter: @rgrbic
IoT-projects.com

hefeilong1991
Posts: 15
Joined: Wed May 14, 2014 1:38 am

### Re: How to sum up the data read by sensor?

joan wrote:Perhaps have a variable called total_flow and add flow to that variable each time flow is calculated.
ya, I know the logic but I do not know how to convert it into codes. May u help me ?
after count the amount of water I used every time on and off the tap, how to store it into a variable called total_usage?

hefeilong1991
Posts: 15
Joined: Wed May 14, 2014 1:38 am

### Re: How to sum up the data read by sensor?

rgrbic wrote:You have to get the value from sensor in liters per second. Read the sensor every second and just add the reading to some variable which you have to set to 0 every day.
Or, if you don't need current flow then just count the pulses and at the end of a day calculate consumption in liters.
May u help me covert your sentence into coding? As I am new in raspberry, in addition how to make it reset after 12pm

joan
Posts: 14763
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

### Re: How to sum up the data read by sensor?

There are plenty of web based tutorials.

Perhaps http://www.sthurlow.com/python/ would help?

Return to “Beginners”