-
Notifications
You must be signed in to change notification settings - Fork 7
/
Soil moisture.py
46 lines (39 loc) · 1.36 KB
/
Soil moisture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# .';:cc;.
# .,',;lol::c.
# ;';lddddlclo
# lcloxxoddodxdool:,.
# cxdddxdodxdkOkkkkkkkd:.
# .ldxkkOOOOkkOO000Okkxkkkkx:.
# .lddxkkOkOOO0OOO0000Okxxxxkkkk:
# 'ooddkkkxxkO0000KK00Okxdoodxkkkko
# .ooodxkkxxxOO000kkkO0KOxolooxkkxxkl
# lolodxkkxxkOx,. .lkdolodkkxxxO.
# doloodxkkkOk .... .,cxO;
# ddoodddxkkkk: ,oxxxkOdc'..o'
# :kdddxxxxd, ,lolccldxxxkkOOOkkkko,
# lOkxkkk; :xkkkkkkkkOOO000OOkkOOk.
# ;00Ok' 'O000OO0000000000OOOO0Od.
# .l0l.;OOO000000OOOOOO000000x,
# .'OKKKK00000000000000kc.
# .:ox0KKKKKKK0kdc,.
# ...
#
# Author: peppe8o
# Blog: https://peppe8o.com
# Date: Mar 19th, 2022
# Version: 1.0
# import required modules
from machine import ADC, Pin
import utime
# use variables instead of numbers:
soil = ADC(Pin(26)) # Soil moisture PIN reference
#Calibraton values
min_moisture=0
max_moisture=65535
readDelay = 0.5 # delay between readings
while True:
# read moisture value and convert to percentage into the calibration range
moisture = (max_moisture-soil.read_u16())*100/(max_moisture-min_moisture)
# print values
print("moisture: " + "%.2f" % moisture +"% (adc: "+str(soil.read_u16())+")")
utime.sleep(readDelay) # set a delay between readings