Tailwind series: Using moisture sensor with Arduino
by Quasortech Labs

The article discusses the measurement of soil moisture using an Arduino Uno and a moisture sensor.
Disclaimer
-
The calibration of moisture sensors is not addressed in this article.
-
The working principles of the flow meter are not discussed here.
Working sample
Before we continue, let's examine what our final outcome will resemble.
Click on this video to play.
Items needed
-
Arduino Uno.
-
Soil moisture sensor.
Pre-requisites
This post assumes you already have,
1. Arduino Editor installed on your laptop.
2. Your laptop connected to Arduino using the USB cable.
3. Basic familiarity with Arduino programming using C++.
Technical details
How moisture sensors work?
This post does not delve deeply into the operational intricacies of moisture sensors. There are abundant resources available on the internet for further information.
Here's an example: https://create.arduino.cc/projecthub/electropeak/complete-guide-to-use-soil-moisture-sensor-w-examples-756b1f

Schematic & Wiring diagrams

This is how the final setup looks like:

How-to steps
Step 1: Connecting Arduino to moisture sensor


Connection point details:
Step 2: Arduino C++ code
No additional libraries need to be downloaded. The code is straightforward.
C++ code
#define SensorAnalogPin A2
float sensorOutputValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
//Through analog pin A2, take 100 measurements of sensor value to increase accuracy of reading
for (int counter = 0; counter <= 100; counter++) {
sensorOutputValue = sensorOutputValue + analogRead(SensorAnalogPin);
delay(10);
}
sensorOutputValue = sensorOutputValue / 100.0;
Serial.println(sensorOutputValue);
delay(1000);
}
Step 3: Testing the bidirectional message communication
Now the setup should be ready to test the moisture sensor. Please refer to the last section of the accompanying video on this page to see the working demo.
Closing note
I hope this post provides you with the fundamental details for measuring moisture content using Arduino and a resistive moisture sensor. For a demonstration, please refer to the accompanying video located at the top of this page.
Thanks!
Music by QubeSounds from Pixabay