Arduino Nano 33 IoT - Soil Moisture Sensor Pump

In this guide, we'll learn how to use the Arduino Nano 33 IoT to control a pump based on the reading from a soil moisture sensor.

Arduino Nano 33 IoT soil moisture sensor controls Pump

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×Capacitive Soil Moisture Sensor
1×Relay
1×12V Pump
1×Vinyl Tube
1×12V Power Adapter
1×Optionally, DC Power Jack
1×Breadboard
1×Jumper Wires
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 and Pump

If you're new to using the soil moisture sensor, Pump, and Arduino Nano 33 IoT, please check out these tutorials:

These tutorials explain how soil moisture sensor and Pump work, their pinouts, how to connect them to the Arduino Nano 33 IoT, and how to program Arduino Nano 33 IoT to work with the soil moisture sensor and Pump.

How It Works

Arduino Nano 33 IoT regularly checks the reading from the capacitive soil moisture sensor. Depending on how wet the soil is, it will perform these actions:

  • If the soil moisture is lower than a certain level, the Arduino Nano 33 IoT automatically turns on a relay to start the pump. Otherwise, it automatically turns off the relay to stop the pump.

Wiring Diagram

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

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-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); }

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.
  • Do a calibration to find the right wet-dry threshold. You can see how in Arduino Nano 33 IoT - Soil Moisture Sensor tutorial.
  • Change the calibrated value to THRESHOLD in the code.
  • Open the Serial Monitor in the Arduino IDE.
  • Upload the code to your Arduino Nano 33 IoT.
  • Look at the result on the Serial Monitor.
COM6
Send
The soil moisture is DRY => activate the pump The soil moisture is DRY => activate the pump The soil moisture is DRY => activate the pump The soil moisture is DRY => activate the pump The soil moisture is WET => deactivate the pump The soil moisture is WET => deactivate the pump The soil moisture is WET => deactivate the pump The soil moisture is WET => deactivate the pump
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Code Explanation

Read the explanation in each comment line of the source code!

Video Tutorial

※ 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!