Measuring soil moisture
Measuring soil moisture is a common and useful practical exercise for learning how sensors are connected to microcontrollers and how an analog signal is turned into a meaningful physical quantity. The two most common approaches are capacitive and resistive (based on resistance). Both kinds of sensors give an electrical signal that the microcontroller reads through an AD converter (analog-to-digital converter), but they work on different physical principles and have different advantages and disadvantages in practice.
Capacitive soil moisture sensor – how it works
A capacitive soil moisture sensor is basically a capacitor made on a printed circuit board (PCB), whose capacitance changes with the electrical (dielectric) properties of the soil around it. The “electrodes” are copper traces on the board that interleave and form the two plates of the capacitor, separated by the board material and the soil around it.
When the soil moisture increases, the dielectric constant of the material between and around the traces increases (water has a much higher dielectric constant than dry soil or air). Because of this, the capacitance also increases. The sensor module has simple electronics (an oscillator, an RC circuit or a capacitance-to-voltage converter) that turns the small change of capacitance into a measurable analog voltage (AOUT), which we read with the AD converter.
Important in practice: capacitive sensors do not pass current through the soil (the traces are usually covered with a protective layer), so they do not corrode quickly. They are usually more stable and last longer, and they work well with microcontrollers at 3.3 V or 5 V.
Resistive soil moisture sensor – how it works
A resistive moisture sensor measures the electrical resistance (i.e. the conductivity) between two bare metal electrodes pushed into the soil. When the soil contains more water and dissolved ions, it conducts current better and the resistance between the electrodes decreases; when the soil is dry, the resistance increases.
A resistive probe is usually used in a voltage divider: the probe is one part of the divider, and a known resistor the other. The voltage at the middle point of the divider changes with the resistance of the probe, and the microcontroller reads it on an analog input. Many ready-made kits have a small board with an operational amplifier or a comparator, which gives both an analog output (A0) and a digital output with an adjustable threshold (D0).
Important in practice: resistive probes are simple and cheap, and the digital output is handy for simple threshold control (e.g. turning on a pump). But since direct current flows through the electrodes, they corrode and wear out over time; in the long run they also give less stable readings than capacitive sensors.
In the exercise that follows we will show how both kinds of sensors are connected to an Arduino (or ESP32), how the analog signal is read and interpreted, and how the readings are adjusted for your soil. The exercise contains wiring diagrams, example code and a graphical display of the measured values.
Resistive soil moisture sensor
This part continues the lesson on measuring moisture and deals with the resistive probe. A resistive probe is a simple and cheap sensor that measures how well the soil conducts current – a practical way to estimate moisture. Below we explain what the probe measures, what it is usually used for, and how it is connected – in a simplified diagram in Tinkercad and in a real circuit with a small driver board (the LM393 module).
How a resistive probe measures moisture
The probe has two bare metal electrodes that are pushed into the soil. The soil between the electrodes behaves like a resistor: when it has more water and dissolved ions, the resistance decreases; when it is dry, the resistance increases. The probe itself is not an active component – it must be part of a simple circuit (most often a voltage divider) so that the microcontroller can read a voltage that depends on the resistance of the soil.
It is most often used for:
- simple moisture monitoring for watering plants,
- recognizing a threshold (whether the soil is dry or moist) in automatic watering systems,
- school projects and prototypes where low cost matters.
Wiring – the basic idea
The usual electric circuit is a voltage divider. One part of the divider is the probe (the variable resistance Rsoil), and the other a known resistor R1. The voltage at the middle point is read by the microcontroller's AD converter:
VCC --- R1 ---+--- A0 (ulaz AD konvertora)
|
Rsoil (sonda)
|
GND
When Rsoil changes, the voltage at the middle point changes too, so analogRead() returns a different value. For reliable results:
- choose
R1so that the voltage at the middle point changes in a useful range of the AD converter (most often 10 kΩ), - power the probe only briefly, during the measurement, so that the electrodes wear out less,
- use a common ground for the sensor module and the microcontroller.
A soil moisture sensor measures the amount of water in the soil based on the change of its electrical resistance. When the soil is dry, the resistance is high, and in moist soil it decreases. The sensor turns this resistance into a voltage that the Arduino board can read.
Figure 2 shows the basic wiring diagram of the moisture sensor connected directly to an Arduino UNO board. The diagram, made in Tinkercad, shows a simple connection of the sensor pins VCC, GND and Signal to the matching Arduino pins.
In this exercise the analog pin A0 is used to read the sensor's output voltage. This voltage depends on the resistance of the soil between the two electrodes of the probe. The Arduino converts the analog voltage into a digital value from 0 to 1023, which shows the relative moisture.
Using a module with the LM393 comparator
Figure 3 shows a real connection of the sensor through a module with the LM393 comparator. This module lets the sensor work in both analog and digital mode.
- Analog output (A0) – gives a voltage that changes continuously with the soil moisture.
- Digital output (D0) – gives a signal 0 or 1, depending on the set threshold.
The comparator board has a small potentiometer for setting the voltage threshold. When the measured sensor voltage drops below this threshold, the digital output (D0) becomes LOW (0); otherwise it stays HIGH (1). This can trigger simple actions, for example turning on a water pump or an LED indicator.
Pinout
The LM393 module has 4 + 2 pins:
- on the side with two pins, the metal electrodes of the sensor are connected;
- on the side with four pins (the module's output):
- VCC → to the Arduino's 5V
- GND → to the Arduino's GND
- A0 → to the analog input A0
- D0 → a digital output, optional, for recognizing a threshold
This kind of wiring makes measuring moisture easier and shows well the principle of measuring through resistance with an Arduino.
Measuring soil moisture with a capacitive sensor
A capacitive soil moisture sensor is a more advanced type of moisture sensor. Unlike the resistive one, which measures the change of electrical resistance between two electrodes, the capacitive sensor measures the change of capacitance caused by the dielectric properties of the soil. When the soil becomes moister, its dielectric constant increases, the capacitance increases and the sensor's analog output signal changes.
The main advantage of the capacitive sensor over the resistive one is that it does not cause electrolysis, because no direct current flows through the soil. That is why the sensor lasts much longer and gives more stable and repeatable measurements.
Overview
Figure 1 shows a real connection of a capacitive moisture sensor with an Arduino board, pushed into a flowerpot, and Figure 2 shows the wiring diagram of the sensor – the power pins (Vcc and GND) and the analog output (A0) connected to the Arduino's analog input.
How the sensor works
The capacitive sensor has an analog output marked AO, which gives a voltage proportional to the soil moisture. The Arduino reads this voltage with the function analogRead(A0). The value is usually from 0 to 1023 and can be converted linearly into a moisture percentage, to make it easier to interpret.
// Example: reading a capacitive soil moisture sensor
int sensorPin = A0; // analog input connected to the AO pin of the sensor
float moistureValue = 0; // current moisture
void setup() {
Serial.begin(115200); // communication with Processing
}
void loop() {
int rawValue = analogRead(sensorPin); // raw value from the sensor
moistureValue = map(rawValue, 1023, 300, 0, 100); // converting to a percentage (adjust the limits for your sensor)
Serial.println(moistureValue); // sending the moisture to Processing
delay(3000); // 3-second pause between measurements
}
Serial communication and display in Processing
The data is sent to Processing the same way as for the resistive sensor. In both cases the Arduino sends one number – the soil moisture percentage – over the serial port at 115200 baud.
That is why the same Processing program from the previous part can be used for this sensor too. It receives the moisture values by itself through the function serialEvent(), shows them on the screen and displays the changes live, as text and as a colored bar.
The only difference between these two sensors is the measuring principle – resistive sensors measure conductivity, and capacitive ones the change of the dielectric constant. The wiring, communication and display are the same.
Arduino code – measuring soil moisture
The following Arduino program reads data from a resistive moisture sensor through the analog input A0. The measured value is turned into a moisture percentage and sent over the serial port every 3 seconds. The data can be watched directly in the Serial Monitor (in the Arduino IDE) or read in other programs, such as Processing, for display and further analysis.
Arduino program
// analog pin the soil moisture sensor is connected to
const int pin_A0 = A0;
// threshold below which the soil is considered dry
const int dryThreshold = 200;
void setup() {
// serial connection at 115200 bits per second
Serial.begin(115200);
}
void loop() {
// raw analog value from the sensor (0 to 1023)
int sensorValue = analogRead(pin_A0);
// converting to a percentage:
// a high value (e.g. 1023) → dry soil → a low moisture percentage
// a low value (e.g. 300) → moist soil → a high moisture percentage
float moisturePercent = 100.0 * (1023 - sensorValue) / 1023;
// sending the computed percentage to the serial port
Serial.println(moisturePercent);
// 3-second pause before the next measurement
delay(3000);
}
Explanation
analogRead(A0)reads the voltage from the sensor and converts it into a digital value from 0 to 1023.- Higher values mean drier soil (higher resistance), and lower values moister soil.
- The percentage is computed linearly, to make it easier to interpret.
Serial.println()sends the measured moisture percentage to the serial interface – it can be followed in the Serial Monitor or in other programs that read serial data, such as Processing, MATLAB or Python scripts.
This simple program can be the basis for more complex applications, such as automatic watering systems or environmental data logging.
Processing code – showing soil moisture data
The following Processing program receives soil moisture data from the Arduino over the serial port and shows it on the screen as text and graphically. Each value the Arduino sends is the current moisture percentage, sent every 3 seconds with the statement Serial.println().
Processing program
import processing.serial.*;
Serial myPort;
String val = "";
float moisture = 0; // last moisture value (0–100 %)
void setup() {
size(400, 200); // window size
myPort = new Serial(this, Serial.list()[0], 115200); // opening the first available serial port
myPort.bufferUntil('\n'); // serialEvent() is called when a whole line arrives
}
void draw() {
background(255); // white background
fill(0); // black text color
textSize(20);
text("Soil moisture: " + nf(moisture, 0, 2) + "%", 50, 60); // printing with 2 decimal places
// bar that shows the moisture
fill(0, 100, 255);
rect(50, 100, map(moisture, 0, 100.0, 0, 300), 30); // blue bar proportional to the moisture
}
void serialEvent(Serial p) {
val = p.readStringUntil('\n'); // reading the whole line sent by the Arduino
if (val != null) {
val = trim(val); // removing spaces and the newline character
try {
moisture = float(val); // converting the text to a number
} catch (Exception e) {
println("Failed to read the value: " + val); // message if the conversion fails
}
}
}
Explanation
- Serial communication: the program uses the library
processing.serialto communicate with the Arduino board over USB. Serial.list()returns the list of available ports. The first one ([0]) is usually the Arduino – if it is not, try another index.- The function
serialEvent()is called by itself when new serial data arrives. It reads the whole line (ending with the character'\n') sent by the Arduino. So that it is called only when a whole line arrives,myPort.bufferUntil('\n')is called insetup(). - The text is then converted to a
float, so that it can be used for calculation and drawing. - In the loop
draw(), the last value is shown as text and as a blue bar whose length matches the moisture percentage.
This display lets you follow moisture changes live. When you connect a resistive or capacitive sensor to the Arduino, you can see how the measured value changes in different conditions (dry, moist, wet). Processing is a simple and interesting way to show sensor data graphically in Arduino projects.
Practice tasks
Try to solve the task yourself first, and only then open the solution.
- Print the state of the soil in words: below 30 % – “dry”, from 30 to 70 % – “just right”, above 70 % – “wet”.
- Add three LEDs (red – pin 4, yellow – pin 5, green – pin 6) that show these three states.
- The capacitive sensor does not need to be powered all the time. Power it from digital pin 7: turn it on, wait 100 ms, measure, and then turn it off; repeat the measurement every 10 seconds.
Solution 1: three states of the soil
int sensorPin = A0;
void setup() {
Serial.begin(115200);
}
void loop() {
int raw = analogRead(sensorPin);
int procenat = constrain(map(raw, 1023, 300, 0, 100), 0, 100);
Serial.print(procenat);
if (procenat < 30) {
Serial.println(" % dry");
} else if (procenat <= 70) {
Serial.println(" % just right");
} else {
Serial.println(" % wet");
}
delay(1000);
}Solution 2: a traffic light for moisture
int sensorPin = A0;
const int CRVENA = 4, ZUTA = 5, ZELENA = 6;
void setup() {
pinMode(CRVENA, OUTPUT);
pinMode(ZUTA, OUTPUT);
pinMode(ZELENA, OUTPUT);
}
void loop() {
int procenat = constrain(map(analogRead(sensorPin), 1023, 300, 0, 100), 0, 100);
digitalWrite(CRVENA, procenat < 30 ? HIGH : LOW);
digitalWrite(ZUTA, (procenat >= 30 && procenat <= 70) ? HIGH : LOW);
digitalWrite(ZELENA, procenat > 70 ? HIGH : LOW);
delay(500);
}Solution 3: the sensor is turned on only for measuring
int sensorPin = A0;
const int NAPAJANJE = 7; // sensor VCC on pin 7 (the sensor draws a few mA)
void setup() {
Serial.begin(115200);
pinMode(NAPAJANJE, OUTPUT);
digitalWrite(NAPAJANJE, LOW);
}
void loop() {
digitalWrite(NAPAJANJE, HIGH); // turn the sensor on
delay(100); // wait for the output to settle
int raw = analogRead(sensorPin);
digitalWrite(NAPAJANJE, LOW); // turn the sensor off
Serial.println(raw);
delay(10000);
}Check your knowledge
Open the quiz
Quiz: soil moisture
1. What happens to the resistance of the soil when it is moister?
2. What is the main advantage of the capacitive sensor?
3. What is the output D0 on the LM393 module for?
4. Why is myPort.bufferUntil('\n') called in Processing?
Soil Moisture Measurement
Measuring soil moisture is a common and useful practical exercise for learning how sensors interface with microcontrollers and how analog signals are converted into meaningful physical measurements. Two widely used approaches are the capacitive method and the resistive (resistance-based) method. Both types of sensors produce an electrical signal that can be read by a microcontroller ADC (analog-to-digital converter), but they rely on different physical principles and have different practical trade-offs.
Capacitive Soil Moisture Sensor — Principle of Operation
A capacitive soil moisture sensor is essentially a printed circuit-board (PCB) capacitor whose effective capacitance changes with the dielectric properties of the surrounding soil. The "electrodes" are interleaved copper traces on the PCB (an interdigitated layout) that form two capacitor plates separated by the board material and the surrounding medium.
As soil moisture increases, the dielectric constant of the material between (and around) the PCB traces increases (water has a much higher dielectric constant than dry soil or air). That change in dielectric constant increases the effective capacitance. The sensor module contains simple electronics (an oscillator, RC timing circuit or capacitance-to-voltage converter) that translate the small change in capacitance into a measurable analog voltage (AOUT) which you read with the ADC.
Key practical points: capacitive sensors are non-conductive (the traces are usually coated), so they do not pass DC current through the soil and do not corrode quickly. They are generally more stable and longer lasting, and they work well with microcontrollers running at 3.3 V or 5 V.
Resistive (Resistance-based) Soil Moisture Sensor — Principle of Operation
A resistive soil moisture sensor measures the electrical resistance (or conductance) between two exposed metal electrodes that are inserted into the soil. When the soil contains more water and dissolved ions, it conducts electricity better and the resistance between the electrodes decreases; when the soil is dry the resistance increases.
The typical way to use a resistive probe is to build a voltage divider: the probe forms one leg of the divider and a known resistor forms the other. The voltage at the divider midpoint changes with the probe resistance and is read by the microcontroller analog input. Many commercial resistive sensor kits include a small driver board with an op-amp or comparator that provides both an analog output (A0) and a configurable digital threshold output (D0).
Key practical points: resistive probes are simple and cheap, and the onboard digital output is useful for simple threshold-based control (e.g. switching a pump). However, because DC current flows through the electrodes, they are prone to electrochemical corrosion and degradation over time; they also may give less stable readings in the long term compared to capacitive sensors.
In the following lab exercise we will demonstrate how to interface both sensor types with an Arduino (or ESP32), how to read and interpret the analog signal, and how to calibrate the readings for your local soil. The exercise will include wiring diagrams, example code and visualization of the measured values.
Resistive Soil Moisture Sensor
This section continues the lesson on soil moisture sensing and focuses on the resistive (resistance-based) probe. The resistive probe is a simple, low-cost sensor that measures how well the soil conducts electricity — a practical way to estimate moisture content. Below we explain what the probe measures, what it is typically used for, and how to wire it in both the simplified Tinkercad setup and a real-world circuit using the small driver board (LM393 module).
How the Resistive Probe Measures Moisture
The probe consists of two exposed metal electrodes that are inserted into the soil. The soil between the electrodes acts as a resistor: when the soil contains more water and dissolved ions, its electrical resistance decreases; when the soil is dry, resistance increases. The probe by itself is not an active device — it must be used as part of a simple circuit (usually a voltage divider) so a microcontroller can read a voltage proportional to the soil resistance.
Typical uses include:
- Simple moisture monitoring for plant irrigation.
- Threshold detection (is soil dry / wet) for automatic watering systems.
- Educational projects and prototypes where low cost is important.
Wiring and Connections — Conceptual
The usual electrical arrangement is a voltage divider.
One leg of the divider is the probe (variable resistance Rsoil)
and the other leg is a known resistor R1.
The midpoint voltage is read by the microcontroller ADC:
VCC --- R1 ---+--- A0 (ADC input)
|
Rsoil (probe)
|
GND
As Rsoil changes, the midpoint voltage changes and analogRead()
returns a different value. To get reliable results:
- Choose
R1so the midpoint voltage moves across a useful ADC range (commonly 10 kΩ). - Only power the probe briefly during a measurement to reduce electrochemical wear.
- Use common ground between sensor module and microcontroller.
The soil moisture sensor measures the amount of water in the soil by detecting changes in its electrical resistance. When the soil is dry, its resistance is high, while in moist soil the resistance decreases. The sensor converts this resistance into a voltage signal that can be read by the Arduino board.
Figure 2 shows the basic wiring diagram for connecting the soil moisture sensor directly to the Arduino UNO. The diagram, created in Tinkercad, illustrates a simple connection of the sensor pins VCC, GND, and Signal to the corresponding pins on the Arduino.
In this exercise, the analog pin A0 is used to read the output voltage from the sensor. This voltage depends on the resistance of the soil between the two probe electrodes. The Arduino converts the analog voltage into a digital value between 0 and 1023, which represents the relative moisture level.
Using the LM393 Comparator Module
Figure 3 shows the practical connection of the sensor through an LM393 comparator module. This module allows the sensor to work in both analog and digital modes.
- Analog output (A0) — provides a continuous voltage signal proportional to the soil’s moisture level.
- Digital output (D0) — provides a binary signal (0 or 1) depending on the set threshold level.
The comparator board includes a small potentiometer that lets you adjust the voltage threshold. When the measured voltage from the sensor drops below this threshold, the digital output (D0) becomes LOW (0); otherwise, it stays HIGH (1). This makes it possible to trigger simple actions, such as turning on a water pump or LED indicator.
Pin Configuration
The LM393 module has 4 + 2 pins:
- On the two-pin side: the sensor’s metal probes are connected.
- On the four-pin side (module output):
- VCC → connect to 5V on the Arduino
- GND → connect to GND on the Arduino
- A0 → connect to the analog input A0
- D0 → optional digital output for threshold-based detection
This setup allows easy measurement of soil moisture and helps demonstrate the principle of resistance-based sensing using Arduino.
Measuring Soil Moisture with a Capacitive Sensor
The capacitive soil moisture sensor represents a more advanced version of the soil humidity sensor. Unlike the resistive type, which measures changes in electrical resistance between two electrodes, the capacitive sensor measures variations in capacitance caused by the dielectric properties of the soil. When the soil becomes wetter, its dielectric constant increases, which raises the capacitance value and changes the analog signal output of the sensor.
The main advantage of a capacitive sensor compared to a resistive one is that it does not cause electrolysis, since no direct current passes through the soil. This significantly extends the sensor’s lifespan and provides more stable and repeatable measurements over time.
Overview
Figure 1 shows a real connection of the capacitive soil moisture sensor with an Arduino board inserted into a flower pot,
while Figure 2 illustrates the wiring diagram of the sensor connection — including the power pins
(Vcc and GND) and the analog output pin (A0) connected to the Arduino analog input.
Sensor Operation
The capacitive sensor has an analog output labeled AO that provides a voltage proportional
to the soil moisture level.
This voltage is read by the Arduino through the analogRead(A0) function.
The value typically ranges from 0 to 1023 and can be linearly mapped to a moisture percentage for easier interpretation.
// Example: Reading from a capacitive soil moisture sensor
int sensorPin = A0; // analog input connected to the sensor AO pin
float moistureValue = 0; // current moisture level
void setup() {
Serial.begin(115200); // communication with Processing
}
void loop() {
int rawValue = analogRead(sensorPin); // read raw sensor value
moistureValue = map(rawValue, 1023, 300, 0, 100); // map to percentage (adjust if needed)
Serial.println(moistureValue); // send moisture value to Processing
delay(3000); // wait 3 seconds between readings
}
Serial Communication and Processing Visualization
The way data is sent to Processing is exactly the same as with the resistive sensor version. In both cases, the Arduino sends a single numeric value — the soil moisture percentage — via the serial port at a baud rate of 115200.
Therefore, the same Processing sketch shown in the previous section can be used for this sensor as well.
It automatically receives the moisture values through the serialEvent() function,
displays them on screen, and visualizes changes in real time using a text label and a color bar.
The only difference between the two sensors lies in the measurement principle — resistive sensors measure conductivity, while capacitive sensors detect changes in dielectric constant. The wiring, communication, and visualization methods remain identical.
Arduino Code – Measuring Soil Moisture
The following Arduino program reads data from the resistive soil moisture sensor using the analog input pin A0.
The measured value is converted into a percentage of soil moisture and sent through the serial port every 3 seconds.
The data can be viewed directly in the Serial Monitor (from the Arduino IDE) or read in other applications
such as Processing for visualization and further analysis.
Arduino Program
// Define the analog pin connected to the soil moisture sensor
const int pin_A0 = A0;
// Threshold value to define when the soil is considered dry
const int dryThreshold = 200;
void setup() {
// Initialize serial communication at 115200 bits per second
Serial.begin(115200);
}
void loop() {
// Read the raw analog value from the sensor (0 to 1023)
int sensorValue = analogRead(pin_A0);
// Convert the raw value to a percentage:
// High sensor value (e.g., 1023) → dry soil → low moisture percent
// Low sensor value (e.g., 300) → wet soil → high moisture percent
float moisturePercent = 100.0 * (1023 - sensorValue) / 1023;
// Send the calculated moisture percentage to the serial port
Serial.println(moisturePercent);
// Wait 3 seconds before the next reading
delay(3000);
}
Explanation
analogRead(A0)reads the voltage from the sensor and converts it to a digital value between 0 and 1023.- Higher values correspond to drier soil (higher resistance), while lower values indicate more moisture.
- The percentage value is computed linearly to make it easier to interpret.
Serial.println()sends the measured humidity percentage to the serial interface — it can be monitored in Serial Monitor or other software such as Processing, MATLAB, or Python scripts that read serial data.
This simple program can serve as the basis for more advanced applications, such as automatic irrigation systems or data logging for environmental monitoring.
Processing Code – Visualization of Soil Moisture Data
The following Processing program receives soil moisture data from the Arduino via the serial port
and displays it on the screen in both text and graphical form.
Each value sent by the Arduino represents the current soil moisture percentage and is transmitted
every 3 seconds using the Serial.println() command.
Processing Program
import processing.serial.*;
Serial myPort;
String val = "";
float moisture = 0; // Stores the latest moisture value (0–100%)
void setup() {
size(400, 200); // Window size
myPort = new Serial(this, Serial.list()[0], 115200); // Open the first available serial port
myPort.bufferUntil('\n'); // call serialEvent() only when a whole line arrives
}
void draw() {
background(255); // White background
fill(0); // Black text color
textSize(20);
text("Soil Moisture: " + nf(moisture, 0, 2) + "%", 50, 60); // Display with 2 decimal places
// Visual moisture bar
fill(0, 100, 255);
rect(50, 100, map(moisture, 0, 100.0, 0, 300), 30); // Draws a blue bar proportional to moisture
}
void serialEvent(Serial p) {
val = p.readStringUntil('\n'); // Reads the entire line sent from Arduino
if (val != null) {
val = trim(val); // Removes extra whitespace and newline characters
try {
moisture = float(val); // Converts the received string to a float value
} catch (Exception e) {
println("Failed to parse value: " + val); // Error message if conversion fails
}
}
}
Explanation
- Serial communication: The program uses the
processing.seriallibrary to communicate with the Arduino board via USB. Serial.list()returns a list of available ports. The first one ([0]) is usually the Arduino — if not, try a different index.- Function
serialEvent()automatically triggers whenever new serial data arrives. It reads a complete line (terminated by'\n') sent by Arduino. - The string value is then converted to a
floatso it can be used for calculations and graphical display. - Inside the
draw()loop, the latest value is shown as text and as a blue bar proportional to soil moisture percentage.
This visual feedback allows real-time monitoring of how soil moisture changes. By connecting a resistive or capacitive sensor to the Arduino, you can observe how the measured value responds to different soil conditions (dry, damp, or wet). Processing provides an intuitive and interactive way to visualize sensor data from Arduino projects.
Check your knowledge
Open the quiz
Quiz: soil moisture
1. What happens to the soil resistance when the soil is wetter?
2. What is the main advantage of a capacitive sensor?
3. What is the D0 output of the LM393 module for?
4. Why does the Processing sketch call myPort.bufferUntil('\n')?
Previous
|< Introduction to Servo Motors
