plant watering

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
soggycashew
Posts: 55
Joined: Sat Sep 18, 2021 10:21 pm

Re: plant watering

Post by soggycashew » Sat Jan 08, 2022 5:30 pm

torwag wrote:
Mon Nov 11, 2019 7:32 am
Building a loop which measures e.g. 20 values of the soil sensor and create the average out of it (to make sure that it is not triggered by a wrong measurement), then decide to turn or not turn on the pump for a fixed amount of time, finally wait for 1 hour before cycle again (the process itself is slow, no need to measure every second).
I know this is a old thread but how would I go about building a loop which measures 50 values of the soil sensor and create the average out of it?

Thanks!

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: plant watering

Post by davef » Tue Jan 11, 2022 6:45 am

Modify for your requirement:

Code: Select all

count = 0
result = 0

#  read LiFePO4 battery voltage
    while (count < 100):
        battery_ADC_reading = adc1_ch4.read()
        result = result + battery_ADC_reading
        utime.sleep_ms(10)
        count += 1

        battery_26V = (result * 10) / 1095 / 100 #  100 samples

Post Reply