Arduino Nano 33 IoT - Soil Moisture Sensor

This guide shows you how to use the Arduino Nano 33 IoT board to measure soil moisture with a sensor. We will cover:

Arduino Nano 33 IoT soil moisture sensor

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×Capacitive Soil Moisture Sensor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Many soil moisture sensors available in the market are unreliable, regardless of their version. We strongly recommend buying the sensor with TLC555I Chip from the DIYables brand using the link provided above. We tested it, and it worked reliably.

Overview of Soil Moisture Sensor Sensor

capacitive moisture sensor vs resistive moisture sensor

Moisture sensors come in two types:

  • Resistive moisture sensor – a water sensor that measures moisture by checking how well electricity flows through a material.
  • Capacitive moisture sensor – a water sensor that detects moisture by measuring changes in a material’s ability to hold an electrical charge.

Both sensors show the soil moisture level. But they work in different ways. We strongly suggest using the capacitive moisture sensor because of these reasons:

  • The resistive soil moisture sensor gets damaged over time. The electrical current between its metal parts causes it to wear away.
  • The capacitive soil moisture sensor does not get damaged over time. Its metal parts are hidden, so no electrical current passes between them.

The picture below shows rust on a sensor that checks how wet the soil is using electrical resistance.

resistive soil moisture sensor corrosion

For the rest of this guide, we will use the capacitive soil moisture sensor.

Capacitive Soil Moisture Sensor Pinout

A capacitive sensor for soil moisture comes with three connection pins.

  • GND pin: Connect this pin to ground (0 volts).
  • VCC pin: Connect this pin to the power supply (5V or 3.3V).
  • AOUT pin: This pin sends an analog signal. The voltage it outputs goes down when the soil is more moist. Connect this pin to an analog input on the Arduino Nano 33 IoT.
capacitive soil moisture sensor pinout

How It Works

When there is more water in the soil, the AOUT pin's voltage is lower.

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT soil moisture sensor

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

Please note that the Arduino Nano 33 IoT pins A4 and A5 have built-in pull-up resistors for I2C communication. This can affect analog readings, so it is recommended to avoid using these pins with any devices/sensors that relies on ADC.

Arduino Nano 33 IoT Code

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-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); }

Detailed Instructions

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Copy the code shown above and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to send the code to your Arduino Nano 33 IoT board.
  • Bury the sensor in the soil, then pour some water onto the soil. Alternatively, slowly lower the sensor into a cup of salt water.
  • Open the Serial Monitor to see the result. It will look like this:
COM6
Send
Moisture value: 2230 Moisture value: 2223 Moisture value: 2255 Moisture value: 2279 Moisture value: 2313 Moisture value: 2350 Moisture value: 2383 Moisture value: 2395 Moisture value: 1260 Moisture value: 1325 Moisture value: 1271 Moisture value: 1261 Moisture value: 1254 Moisture value: 1261 Moisture value: 1264 Moisture value: 1360 Moisture value: 1258 Moisture value: 1263 Moisture value: 1266 Moisture value: 1258 Moisture value: 1239 Moisture value: 1264 Moisture value: 1307 Moisture value: 1488 Moisture value: 1647 Moisture value: 1746 Moisture value: 1846
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ NOTE THAT:

  • Don't use pure water for testing because it doesn't let electricity flow, so it won't change the sensor's numbers.
  • The sensor will never show a zero reading. It is normal for the sensor's numbers to be between 3100 and 2600, although this might change depending on how deep the sensor is placed, what the soil or water is made of, and the power supply voltage.
  • Don't cover the circuit part (which is on top of the sensor) with soil or water, because this might damage the sensor.

Calibration for Capacitive Soil Moisture Sensor

The reading from the moisture sensor is not absolute. It changes based on what the soil is made of and how much water it has. In real use, we must calibrate the sensor to find the point where the soil is considered wet or dry.

How to calibrate:

  1. Upload the code to the Arduino Nano 33 IoT.
  2. Insert the moisture sensor into the soil.
  3. Insert the moisture sensor into the soil.
  4. Slowly water the soil.
  5. Open the Serial Monitor.
  6. Write down the number you see when the soil changes from dry to wet. This number is called THRESHOLD.

Determine if the soil is wet or dry

After calibrating, change the THRESHOLD value you recorded in the code below. This code checks if the soil is wet or dry.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-soil-moisture-sensor */ #define AOUT_PIN A6 // Arduino Nano 33 IoT pin A6 that connects to AOUT pin of moisture sensor #define THRESHOLD 1500 // CHANGE YOUR THRESHOLD HERE void setup() { Serial.begin(9600); } void loop() { int value = analogRead(AOUT_PIN); // read the analog value from sensor if (value > THRESHOLD) Serial.print("The soil is DRY ("); else Serial.print("The soil is WET ("); Serial.print(value); Serial.println(")"); delay(500); }

The result is shown on the serial screen.

COM6
Send
The soil is DRY (2129) The soil is DRY (1941) The soil is DRY (1767) The soil is DRY (1549) The soil is WET (1471) The soil is WET (1419) The soil is WET (1397) The soil is WET (1373) The soil is WET (1264)
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

Function References

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!