This build pairs the Arduino Nano 33 IoT with a capacitive soil moisture sensor and a relay-driven 12V pump, so your plant waters itself instead of waiting on you. It's a nice first physical-computing project if you're used to writing code but haven't closed the loop with a sensor and an actuator before.

The full tutorial, with every detail and the line-by-line code explanation, is on our site: Arduino Nano 33 IoT - Soil Moisture Sensor Pump

What you need

Wiring

Arduino Nano 33 IoT - Soil Moisture Sensor Pump wiring diagram

The soil moisture sensor's analog output (AOUT) connects to pin A2 on the Arduino Nano 33 IoT. The relay's control pin connects to pin 2. The relay itself sits between the 12V power adapter and the pump, acting as a switch that the Arduino can flip with a digital signal, since the Nano's pins can't drive a pump directly. A vinyl tube carries water from the pump to the soil.

How it works

The Arduino regularly checks the reading from the capacitive soil moisture sensor. If the soil moisture reading is below a certain level, meaning the soil is dry, the Arduino turns the relay on to start the pump. Once the soil is wet enough, it turns the relay off to stop the pump. This keeps watering tied directly to actual soil conditions instead of a fixed timer.

Code

The sketch reads the analog value from the sensor on A2 with analogRead() and compares it against a THRESHOLD constant. If the value is above the threshold, the soil is considered dry, so it sets RELAY_PIN HIGH to activate the pump; otherwise it sets it LOW to deactivate it. Each reading and the resulting action gets printed to the Serial Monitor, and the loop repeats every second.

arduino-nano-33-iot-soil-moisture-sensor-pump.ino

/* * 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-pump */ #define RELAY_PIN 2 // The Arduino Nano 33 IoT pin that connects to relay #define SENSOR_PIN A2 // The Arduino Nano 33 IoT pin that connects to AOUT pin of moisture sensor #define THRESHOLD 1500 // => CHANGE YOUR THRESHOLD HERE  void setup() { Serial.begin(9600); pinMode(RELAY_PIN, OUTPUT); } void loop() { int value = analogRead(SENSOR_PIN); // read the analog value from soild moisture sensor if (value > THRESHOLD) { Serial.print("The soil moisture is DRY => activate pump"); digitalWrite(RELAY_PIN, HIGH); } else { Serial.print("The soil moisture is WET => deactivate the pump"); digitalWrite(RELAY_PIN, LOW); } Serial.print(" ("); Serial.print(value); Serial.println(")"); delay(1000); } 

Things that go wrong

Many capacitive soil moisture sensors on the market are unreliable regardless of version; the tutorial recommends the DIYables sensor with the TLC555I chip, which tested reliably. Before relying on the pump, calibrate your sensor to find the correct wet-dry threshold for your soil, and update THRESHOLD in the code with that value, otherwise the pump may run too often or not at all.

Full tutorial

The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-soil-moisture-sensor-pump