Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4794

Automation, sensing and robotics • Re: (Yet another) Water cooler volume sensor question

$
0
0
I got this running and it is working fine. It sends the weight (in pounds) to my Android phone every 30 minutes using Tasker and AutoRemote. Tasker converts the pounds to a percent full value and sends the date, time, percent, and weight data to a spreadsheet. I'm going to let it run for a few days to watch for drift. If it seems stable I will deploy it in the water cooler and change it to send once per day.

I would also like to have it run once through and stop instead of in a "while True" loop. I will have to do something about the tare function of the first part. Wonder if there is some way to establish a standard reference value so I can run on a cronjob...

Code:

import timeimport sysimport RPi.GPIO as GPIOfrom hx711 import HX711import requestsfrom ShaneKeys import ARKEY1def cleanAndExit():    print("Cleaning...")            print("Bye!")    sys.exit()hx = HX711(20, 21)hx.set_reading_format("MSB", "MSB")referenceUnit = 114hx.set_reference_unit(referenceUnit)hx.reset()hx.tare()print("Tare done! Add weight now...")while True:    try:        val = hx.get_weight(5)        wholeval = (val * -1)        newval = wholeval / 100        roundedval = round(newval, 2)        print(roundedval)        weight = str(roundedval)        r = requests.post(ARKEY1 + "|water|" + str(roundedval))        hx.power_down()        hx.power_up()        time.sleep(1800)    except (KeyboardInterrupt, SystemExit):        cleanAndExit()
Please disregard all the

Code:

wholeval = (val * -1)        newval = wholeval / 100        roundedval = round(newval, 2)        print(roundedval)        weight = str(roundedval)
mess. I was just cleaning up the math because it was reporting -2014.648973296334 for a 20 pound weight and -3994.4979318759 for a 40 pound weight. The "roundedval" is what equals the weight on the scale, in pounds. I tested it with a variety of dumbells. The water cooler tank is 5 gallons, which should be about 41.5 pounds.

Statistics: Posted by duckredbeard — Wed Jan 22, 2025 3:43 am



Viewing all articles
Browse latest Browse all 4794

Trending Articles