top of page

Basic Capacitive Soil Moisture Sensor

This program works with the capacitive soil moisture sensor probe and scales the readings from the sensor so you get soil moisture readings from 0% (dry) to 100% (soaked).

Program


---

Basic Capacitive Soil Moisture Sensor Program

Get readings from the sensor on pin a1 and scale them

between the min and max calibration values to get a reading

between 0 and 100.

---


prog_vars =

d/count 0

-- Calibration values

d/min_value 6

d/max_value 56

-- The final soil moisture reading

d/soil_moisture 0

prog_vars.


prog_start =

pclear

print "Program Start"

-- Setup the sensor on pin a1

gvr a1 100 0

prog_start.


prog_loop =

-- main program loop

get_soil_moisture

print "Count /count Soil moisture /soil_moisture"

inc /count

any /count >= 10 -> exitprog

-- Wait 1 sec between readings

d1000



prog_loop.

get_soil_moisture =

-- Get the reading from a1 and scale it

mapi /min_value /max_value 0 100 /a1 -> /soil_moisture


get_soil_moisture.


prog_stop =

print "Bye"

prog_stop.



bottom of page