RAK12035 WisBlock Soil Moisture Sensor Module Quick Start Guide
Prerequisite
-
Assemble the RAK12035 with a WisBlock Base and WisBlock Core by following the RAK12035 Installation Guide.
-
Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
-
USB Cable
Initial Test of the RAK12035 WisBlock Module
-
This guide uses the RAK4631 WisBlock Core to demonstrate the configuration process. You can also use the RAK11200 or RAK11310 as the WisBlock Core.
-
When using the RAK11200, configure the BOOT0 pin correctly before uploading the source code. Otherwise, the upload may fail. For detailed instructions, refer to the RAK11200 Quick Start Guide.
Before you use the Soil Moisture sensor, you need to calibrate it. Install the example sketch for calibration. The calibration values will be saved on the RAK12035 sensor itself so that you can read them back later from the sensor. In the first step, the sensor is calibrated by reading the sensor values while the sensor is in the air. In the next step submerge the sensor in water (only to the white line on the sensor). After the calibration is finished, the example sketch will save the calibration values directly in the sensor. The value measured in the air corresponds to 0% RH, the value measured in water corresponds to 100% RH.
REMARK
The calibration method in air and water is not very precise. To get more precise calibration values, the calibration should be performed in dry soil and water-saturated soil. Some information about such a calibration procedure is shown in Capacitive Soil Moisture Sensor Calibration with Arduino. Another source for such a calibration in the soil can be found in Calibrating Soil Moisture Sensors
Figure 1: Burying the RAK12035 sensor probe into the plant soil-
Install the RAKwireless Arduino BSP for WisBlock by using the
package_rakwireless_index.jsonboard installation package. The WisBlock Core should now be available on the Arduino IDE. -
You need to select first the WisBlock Core you have.
Figure 1: Selecting RAK4631 as WisBlock Core-
Calibrating the sensor is a MUST. Follow first the steps on RAK12023 Quick Start Guide (Upon this guide, it will teach you how to calibrate your sensor properly.) before proceeding to STEP 3 below.
-
After following STEP 2 on how to calibrate the sensor, copy the following sample code into your Arduino IDE.
Click to view the code
/**
* @file RAK12035_Soil_Humidity.ino
* @author Bernd Giesecke (bernd.giesecke@rakwireless.com)
* @brief Simple example to read data from the RAK12023/RAK12035 Soil Moisture Sensor
* @version 0.1
* @date 2021-11-20
*
* @copyright Copyright (c) 2021
*
*/
#include <Arduino.h>
#include <Wire.h>
#include "RAK12035_SoilMoisture.h" // Click here to get the library: http://librarymanager/All#RAK12035_SoilMoisture
/** Sensor */
RAK12035 sensor;
/** Set these two values after the sensor calibration was done */
uint16_t zero_val = 845;
uint16_t hundred_val = 635;
void setup()
{
// Initialize the built in LED
pinMode(LED_GREEN, OUTPUT);
digitalWrite(LED_GREEN, LOW);
// Initialize the connection status LED
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_BLUE, HIGH);
// Initialize Serial for debug output
Serial.begin(115200);
time_t serial_timeout = millis();
// On nRF52840 the USB serial is not available immediately
while (!Serial)
{
if ((millis() - serial_timeout) < 5000)
{
delay(100);
digitalWrite(LED_GREEN, !digitalRead(LED_GREEN));
}
else
{
break;
}
}
digitalWrite(LED_GREEN, LOW);
Wire.begin();
// Initialize sensor
sensor.begin();
// Get sensor firmware version
uint8_t data = 0;
sensor.get_sensor_version(&data);
Serial.print("Sensor Firmware version: ");
Serial.println(data, HEX);
Serial.println();
// Set the calibration values
// Reading the saved calibration values from the sensor.
sensor.get_dry_cal(&zero_val);
sensor.get_wet_cal(&hundred_val);
Serial.printf("Dry calibration value is %d\n", zero_val);
Serial.printf("Wet calibration value is %d\n", hundred_val);
}
void loop()
{
// Read capacitance
uint16_t capacitance = 0;
sensor.get_sensor_capacitance(&capacitance);
Serial.print("Soil Moisture Capacitance: ");
Serial.println(capacitance);
// Read moisture in %
// after calibration, we get the Capacitance in air and in water, like zero_val and B. zero_val means 0% and B means 100%.
// So the humidity is humidity = (Capacitance-A) / ((B-A)/100.0)
uint8_t moisture = 0;
sensor.get_sensor_moisture(&moisture);
Serial.print("Soil Moisture humidity(%): ");
Serial.println(moisture);
// Read temperature
uint16_t temperature = 0;
sensor.get_sensor_temperature(&temperature);
Serial.print("Soil Moisture Temperature: ");
Serial.print(temperature / 10);
Serial.println(" *C");
delay(1000);
}
If you experience any error in compiling the example sketch, check the updated code for your WisBlock Core Module that can be found on the RAK12035 WisBlock Example Code Repository and this sample code in Github will work on all WisBlock Core.
Other sample code in the WisBlock Github Repository:
- Once the example code is open, you can now select the right serial port and upload the code.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading the RAK12035 example code- When you successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the sensor's reading logs. Try to bury the RAK12035 sensor probe into the soil, and you'll be able to see the soil's capacitance, moisture, and temperature.
Before burying the RAK12035 sensor probe, following the Recommended Depth of the RAK12035 Sensor probe is required.
Figure 1: RAK12035 Soil Moisture sensor readings