Skip to main content

Simple Soil Sensor - Measuring and detectiing humidity with regular sensor (example)

This page contains a simple example with function documentation on how to detect and measure humidity of the soil using the sensor.


Initialization

To use the sensor, first include the required library, create the sensor object (SimpleRainSensor), and initialize it in the setup() function. You can use the return value of begin() to check if everything is connected correctly.

#include "Simple-soil-sensor-easyC-SOLDERED.h"

SimpleSoilSensor sensor;

void setup(){
sensor.begin();
}
//...

SimpleSoilSensor sensor

Creates SimpleSoilSensor object

Returns value: none

sensor.begin()

Initializes the sensor.

Returns value: Returns true if initialization is successful, false otherwise.


Measuring with both digital and analog output

In this library, there are two options for displaying the analog value: for a percentage value, call the getValue() function, and for the raw value, call the getRawValue() function.

#include "Simple-soil-sensor-easyC-SOLDERED.h"

#define CALIBRATION_RESISTANCE_TIP_IN_WATER 30000
#define CALIBRATION_RESISTANCE_FULL_IN_WATER 10000

// Declare the sensor object
SimpleSoilSensor sensor;

void setup()
{
// Initialize the serial communication via UART
Serial.begin(115200);

// Initialize the sensor
// Start I2C communication on default address (0x30)
sensor.begin();

sensor.calibrate(CALIBRATION_RESISTANCE_TIP_IN_WATER, CALIBRATION_RESISTANCE_FULL_IN_WATER);
}

void loop()
{
Serial.print("Raw value of sensor: "); // Print information message
Serial.print(sensor.getValue()); // Prints percent value of soil sensor
Serial.print("% ");
Serial.println(sensor.getRawValue()); // Prints raw value of soil sensor

Serial.print("Resistance of sensor: "); // Print information message
Serial.print(sensor.getResistance()); // Prints resistance of soil sensor
Serial.println(" Ohms."); // Print information message

Serial.print("Humidity: "); // Print information message
Serial.print(sensor.getHumidity()); // Prints raw value of soil sensor
Serial.println(" %."); // Print information message

// Wait a bit before next reading
delay(200);
}
}

sensor.getValue()

Returns the percent value of the soil humidity sensor.

Returns value: Returns a float representation of the rain humidity sensor value in percentage.

sensor.getRawValue()

Returns the raw ADC value.

Returns value: Returns an integer representation of the rain sensor value.

sensor.getResistance()

Returns the calculated resistance.

Returns value: Returns a float representation of the rain sensor resistance.

sensor.getHumidity()

Returns the percent value of the soil humidity.

Returns value: Returns a float representation of the soil humidity in percentage.

Sensor when water is not present
Sensor when water is not present
Serial Monitor output
Serial Monitor output
Sensor when rain is present
Sensor when rain is present
Serial Monitor output
Serial Monitor output

Full example

Try all of the functions mentioned above in the full example below:

Read_values_easyC.ino

Example for using the digital and analog read functions for Simple soil humidity sensor with Qwiic.