Skip to content

Soil Moisture Sensor

The SoilMoisture sensor class provides access to a soil moisture sensor.

Creates a new SoilMoisture object instance.

SoilMoisture(options)

options

An object of properties used to construct the class.

sensor - The hardware connection definition.

interval (optional) - The sampling interval in milliseconds.

Returns a sample object containing the current soil moisture data.

sample()

An object with the following property:

moisture - A number between 0 and 1 (inclusive) that represents the sampled relative soil moisture level, with 0 being the most dry and 1 the most wet.

const sensor = new device.sensor.SoilMoisture({
sensor: {
io: device.io.Analog,
pin: 33
}
});
const sample = sensor.sample();
console.log(`Soil moisture: ${sample.moisture * 100}%`);

Soil Moisture