Hi All,
I’ve been experimenting using the soil moisture sensor to measure the soil height as my Sil wasn’t very flat and there was too much variance in the photogrammetry.
- Wet the soil
- Run code that drives along, lowers at 5mm increments.
- Once it detects moisture, it logs the X, y and z coordinates as a day point (also taking into account the offset for the soil moisture sensor)
- Go to the data points and click the square for at soil level.
One down side so far. If it is raining, water gets in under and shorts out the connectors giving false readings.
I’m not sure the best way to share the code. Any assistance or suggestions are greatly appreciated
– Soil-height probe using a moisture sensor
– Requires a location variable called “Plant”
local plant = variable(“Plant”)
if not plant then
toast(“No plant variable found”, “error”)
return
end
– CONFIG
local MOIST_PIN = 59 – analogue moisture pin
local THRESHOLD = 950 – your calibrated trigger
local STEP = 5.0 – mm per step
local MAX_DEPTH = 150.0 – max distance to probe
local TRAVEL_Z = -400.0 – safe Z between plants
local RETRACT = 5.0 – lift after contact
local Z_OFFSET = -80.0 – record “z - 80” as soil height
– 1) go to this plant at safe height
move{ x = plant.x, y = plant.y, z = TRAVEL_Z }
wait(1000)
– 2) probe down from TRAVEL_Z
local start_z = TRAVEL_Z
local dropped = 0
local reading = read_pin(MOIST_PIN, “analog”)
local soil_z = nil
while dropped < MAX_DEPTH do
if reading <= THRESHOLD then
– contact detected
local contact_z = start_z - dropped
move{ z = contact_z + RETRACT }
wait(500)
soil_z = contact_z + Z_OFFSET
break
end
– keep going down
local next_z = start_z - (dropped + STEP)
move{ z = next_z }
wait(500)
dropped = dropped + STEP
reading = read_pin(MOIST_PIN, “analog”)
end
– 3) store as a soil-height point
if soil_z then
toast(“Soil height at this plant: " .. soil_z .. " mm”)
api({
method = “post”,
url = “/api/points”,
body = {
x = plant.x,
y = plant.y,
z = soil_z,
radius = plant.radius or 25,
pointer_type = “GenericPointer”,
at_soil_level = true,
name = "Soil probe " .. (plant.name or “”)
}
})
else
toast(“No soil detected within " .. MAX_DEPTH .. " mm”, “warn”)
end
– 4) back to travel height for the next plant
move{ z = TRAVEL_Z }
wait(1000)