Soil moisture sensors are a nice first hardware project for a developer: one analog pin, one sensor, and you get a number you can log, graph, or act on. This build uses an Arduino MKR WiFi 1010 and a capacitive soil moisture sensor to read how wet the dirt is, which is the core of any plant-watering or garden-monitoring project.
The full tutorial, with every detail and the line-by-line code explanation, is on our site: Arduino MKR WiFi 1010 - Soil Moisture Sensor
What you need
- Arduino MKR WiFi 1010
- Micro USB Cable
- Capacitive Soil Moisture Sensor
- Breadboard
- Jumper Wires
- DC Power Jack
- DIYables Sensor Kit (18 sensors/displays)
Wiring
The sensor has three pins. VCC goes to power on the MKR WiFi 1010 (3.3V or 5V), GND goes to ground, and AOUT, the analog signal pin, connects to an analog input pin on the board. You can wire this on a breadboard with jumper wires, or connect it directly without a breadboard. Plugging the board into USB gives enough power for both the MKR WiFi 1010 and the sensor, so no separate power supply is needed.
How it works
The capacitive sensor doesn't pass current through the soil the way a resistive sensor does, so it avoids the electrolysis that corrodes resistive probes over time. Its coated sensing area instead produces a voltage that depends on how much moisture is around it, following an inverse relationship: dry soil gives a higher voltage on AOUT, wet soil gives a lower voltage. The MKR WiFi 1010 reads that voltage and converts it into a digital number, typically between 0 and 1023, that your code can act on.
Code
The sketch reads the analog value from the sensor pin with analogRead() and prints it to the Serial Monitor every half second, so you can watch the number change as you move the sensor between dry air and wet soil. From there, calibration is just recording an air reading and a wet reading, then picking a THRESHOLD between them so your code can decide whether the soil counts as wet or dry and print that status instead of a raw number.
arduino-mkr-wifi-1010-soil-moisture-sensor.ino
/*
* This Arduino MKR WiFi 1010 code was developed by newbiely.com
*
* This Arduino MKR WiFi 1010 code is made available for public use without any restriction
*
* For comprehensive instructions and wiring diagrams, please visit:
* https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-soil-moisture-sensor
*/
#define AOUT_PIN A6 // Arduino Nano 33 IoT pin A6 that connects to AOUT pin of moisture sensor
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(AOUT_PIN); // read the analog value from sensor
Serial.print("Moisture value: ");
Serial.println(value);
delay(500);
}
Things that go wrong
If the reading never changes no matter what you dip the sensor into, check the signal wire connection between AOUT and the analog pin first. If you're using a resistive sensor instead of a capacitive one, expect it to corrode and stop working reliably after days or weeks in wet soil. Power shouldn't be an issue since USB supplies enough current, but a low-quality battery can cause fluctuating, unreliable readings.
Full tutorial
The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-soil-moisture-sensor

Top comments (0)