Maker of open-source software and hardware.

Hydroponics: Measuring moisture levels and water levels

Moisture sensor

To know when I need to water my seedlings in the propagator, I got an analogue capacitive soil moisture sensor for £3.67 (including P&P).

The pinout is a simple three-wire interface, with Vcc, ground and the analogue output pin. To read the values, I just needed to do the following in Espruino:

const moistureSensorPin = A5;
const airMoisture = 955;
const waterMoisture = 670;

pinMode(moistureSensorPin, 'analog');

const moisture = Math.round(analogRead(moistureSensorPin) * 1000);
const moisturePercent = Math.round(map(moisture, airMoisture, waterMoisture, 0, 100));
console.log(`Moisture is ${moisture} ~ ${moisturePercent} %`);

if (moisturePercent < 16) {
  console.log('Needs more water');
  // TODO: alarm notification
}

To get airMoisture and waterMoisture, I took readings from the sensor when it was dry and placed in a glass of water respectively. The map() function I got from the Arduino libraries:

function map(x, in_min, in_max, out_min, out_max) {
  // from https://www.arduino.cc/reference/en/language/functions/math/map/
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

I place the sensor directly under the rockwool cubes of the seedlings to measure the moisture content.

Water level sensor

To detect the height of the water level sensor, I'm using a VL53L0X LIDAR sensor, that uses a laser and time-of-flight measurements to accurately measure distances between 50mm and 1200mm. It's pretty amazing that they can fit a laser and a detector into a package that's barely larger than a grain of rice.

The sensor uses an I2C interface, so I connected the pins as follows:

To set it up in Espruino, you just do:

  I2C2.setup({ sda: B3, scl: B10 } );
  laser = require("VL53L0X").connect(I2C2);

To then perform a measurement, you do:

// measure water level
const distance = laser.performSingleMeasurement().distance;
if (distance > 20) {
  console.log(distance, 'mm');
  // TODO: minimum water level notification
}

I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.

#100DaysToOffload #day67 #hydroponics