IOT Projects

IoT Soil Moisture Sensor using ESP8266 & Blynk with Water Pump Control

IoT based Plant watering System using Soil Moisture Sensor

IoT Soil Moisture Sensor:

IoT Soil Moisture Sensor

IoT Soil Moisture Sensor using ESP8266 & Blynk- In this article, you will learn how to convert an ordinary Soil moisture sensor into an IoT Soil Sensor or IoT Moisture Sensor using Nodemcu ESP8266 WiFi module, SSD1306 I2C supported Oled display, a relay module for controlling the water pump, and a smartphone with Blynk application for monitoring the soil moisture and for controlling the water pump.

IoT Soil Moisture Sensor

You don’t have to be worried if you do not have this particular type of Soil Moisture Sensor. You can use other types of Soil Moisture sensors as well. Anyway, personally, I like this type of soil moisture sensor because it can dig deeper into the soil; the sensor probes are waterproofed and are made of highly corrosion-resistant material to ensure long lifetime up to 6 months after being plugged into the soil. Previously I used it with the Arduino and Oled display module. And I practically demonstrated how to make a low-cost yet highly efficient Soil moisture meter. So, if you are just getting started with the Soil moisture sensor and want to learn the extreme basics then I highly recommend you should read my article on Arduino and Soil Moisture Sensor.

IoT Soil Moisture Sensor

Here is my prototype model. As usual, I am using my designed Nodemcu ESP8266 development board along which a Soil Moisture Sensor, Oled display module, a 12V Relay module, and 220Vac light bulb are connected.

IoT Soil Moisture Sensor

I am using a bulb instead of a water pump so that at the time of carrying out a practical demonstration, you can clearly see for yourself how do I turn this bulb ON or OFF. You can also use a 220 Vac water pump and you can also use a DC water pump; it all depends on your choice. If you have to control a large water pump, then you better use a power relay. I have written a separate article on IoT Power Relay, in which I have practically demonstrated how to control a large water pump. Let’s kick off our practical demonstration and afterward I will explain everything else.

Altium Designer + Altium 365 + Octopart:

Arduino LoRa Free SMS

Altium 365 lets you hold the fastest design reviews ever. Share your designs from anywhere and with anyone with a single click. it’s easy, leave a comment tagging your teammate and they’ll instantly receive an email with a link to the design. Anyone you invite can open the design using a web browser. Using the browser interface, you’re able to comment, markup, cross probe, inspect, and more. Comments are attached directly to the project, making them viewable within Altium designer as well as through the browser interface. Design, share, and manufacture, all in the same space with nothing extra to install or configure. Connect to the platform directly from Altium Designer without changing how you already design electronics. Altium 365 requires no additional licenses and comes included with your subscription plan.

Get real-time component insights as you design with Octopart built into Altium 365. Octopart is the fastest search engine for electronic parts and gives you the most up-to-date part data like specs, datasheets, cad models, and how much the part costs at different amounts etc. Right in the design environment so you can focus on your designs. Start with Altium Designer and Activate Altium 365. Search for electronic parts on Octopart.

My IoT Soil moisture monitoring Application and Nodemcu ESP8266 WiFi module are connected to the internet.

IoT Soil Moisture Sensor

You can view the same soil moisture value on the Oled display module and Blynk application. The SV or Set value is basically the soil moisture threshold value that can be adjusted using this slider on the Blynk application.

Since different plants need a different percentage of soil moisture so using this button on the Blynk application you can turn ON and turn OFF the Water Pump at any time from any part of the world. Previously, I made it fully automatic but this time; I decided to give full control to the user.

IoT Soil Moisture Sensor

This IoT soil moisture monitoring system also sends a notification when the moisture drops below the set value or threshold value.

IoT Soil Moisture Sensor

As you can see (watch video given at the end of this article), as I move the slider the SV value on the Oled display module also changes. If the soil moisture is less than the set value then the buzzer is also turned ON. And at the same time a notification message is also sent to the Blynk application. This buzzer will only turn OFF when the soil moisture will increase above the set value. So, after selecting the threshold value. Next, I can go ahead and start watering the plant.

Now, if I press the button, the light will turn ON, which will indicate that the motor has turned ON.

IoT Soil Moisture Sensor

After adding the water, Soil moisture increased above the SV value, I stopped receiving the notification messages and also the buzzer turned OFF. Finally, I pressed the button on the Blynk application to turn OFF the Water Pump( presented by a Blub). It is so simple, isn’t it? All we need is to read the soil moisture value on the Blynk application and then accordingly control the water pump on the remote side.

I am sure by now, you might have got an idea of how does this system work. So, without any further delay let’s get started!!!

Amazon Links:

ESP8266 D1 Mini

ESP8266 Nodemcu

5V buzzer

Soil moisture sensor

12v DC water Pump

5V relay Module

SSD1306 Oled display Module

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Soil Moisture Sensor:

IoT Soil Moisture Sensor

Here is my Soil moisture detection kit. Let’s first take a look at the interface circuit. The board is provided with this blue color potentiometer which is used to adjust the sensitivity.  This board is also provided with the most stable LM393 comparator chip and with On-board power and signal indicator LEDs to display the module working status. The working voltage of this module is from 3.3V to 12 volts. Because of this wide input voltage range, this Soil moisture sensor can be used with 3.3V and 5V compatible controller boards.

All the 4 headers are clearly labeled. The first pin is the Analog output pin and it should be connected with the Analog pin on the Arduino. The 2nd pin is the digital output put pin which can be connected with any digital pin on the Arduino or any other controller board. 3rd pin is the ground pin and the last pin is the VCC pin which you can connect with 3.3V or 5V.

The sensor probes are waterproofed and are made of highly corrosion-resistant material to ensure long lifetime up to 6 months after being plugged into the soil. The Sensor Cable length is 1.3 meters.


Working Voltage: DC 3.3-12V

Working Current: <20m(Output Current:<30mA)

Module Size: 36X15X6mm

Sensor Pin Pitch:5mm

Sensor Cable Length:1.3meter/3.94ft

Sensor Connecting Port: XH2.54 2P

Nodemcu ESP8266:

ESP8266 is a highly integrated chip designed for the needs of a new connected world. It offers a complete and self-contained Wi-Fi networking solution, allowing it to either host the application or to offload all Wi-Fi networking functions from another application processor.
ESP8266 has powerful on-board processing and storage capabilities that allow it to be integrated with the sensors and other application specific devices through its GPIOs with minimal development up-front and minimal loading during runtime. Its high degree of on-chip integration allows for minimal external circuitry, and the entire solution, including front-end module, is designed to occupy minimal PCB area.

IoT Soil Moisture Sensor


  • Serial/UART baud rate: 115200 bps
  • Input power: 3.3V
  • I/O voltage tolerance: 3.6V Max
  • Flash Memory Size: 1MB (8Mbit)
  • WiFi security modes: WPA, WPA2

IoT Soil Moisture Sensor Circuit Diagram:

IoT Soil Moisture Sensor

The VCC and GND pins of the Soil Moisture Sensor and Oled display module are connected with 3.3V and GND pins of the Nodemcu ESP8266 WiFi module. The analog output pin of the Soil moisture sensor interface circuit is connected with the A0 pin of the Nodemcu module. The SCK or SCL and SDA pins of the Oled display module are connected with the D1 and D2 pins. D1 is the SCL and D2 is the SDA.

Digital pin D0 on the Nodemcu module is used to control the relay module which is used to control the Water pump. And digital pin D4 is used to control the 5V buzzer. The Red wire of the buzzer is connected with the 5 volts while the GND wire of the buzzer is connected with the collector of the 2n2222 NPN transistor. The emitter of the transistor is connected with the GND while the base is connected with the pin D4 through a 10K ohm resistor. The 2n2222 NPN transistor and 10k ohm resistor make the driver circuit.

On the left side is the 5V regulated power supply which is based on the LM7805 linear voltage regulator. The 7805 regulator accepts a wide range of input voltages between 7 and 28 voltages. As a precaution do not use voltages above 25 volts. So, it doesn’t matter if you power up your project using a 9v or 12v battery, or if you plan to use a solar panel, or 12 to 25 volts DC adaptor. The 7805 regulator will step down this voltage and outputs regulated 5 volts.

You can see the output of the 7805 voltage regulator is connected with the Vin pin of the Nodemcu ESP8266 WiFi module. And don’t forget to add these 470uF decoupling capacitors with the input and output legs of the voltage regulator.  So, that’s all about the circuit diagram. Now, let’s work on the Blynk application follow the same exact steps.

IoT Soil moisture monitoring Blynk App:

First open the Blynk application and click on the New Project.

IoT Soil Moisture Sensor

Enter the project name in my case “iot soil moisture”. Next, click on the CHOOSE DEVICE and select ESP8266. Finally, click on the Create button.

IoT Soil Moisture Sensor

The authorization code will be sent on your registered email id.

Once the App is opened, click anywhere on the screen, search for the gauge in the widgets list and add it to the screen.

IoT Soil Moisture Sensor

After adding the gauge set its perimeter give a name to the gauge as “Soil moisture” and set the pin to V1 and set the limit value from 0 to 100.

IoT Soil Moisture Sensor

Next, add a slider in the same as you added the Gauge.

IoT Soil Moisture Sensor

Now, click on the slider and set its properties; enter the name, set pin to V2 and set the limit from 0 to 100.

IoT Soil Moisture Sensor

Now, again click on the screen and this time add a button. We will use this button to control a relay. Set the pin to digital GP0.

IoT Soil Moisture Sensor

Again click on the blank area and this time select the notification widget from the list and add it to the screen.

IoT Soil Moisture Sensor

The Blynk application is ready. If you click on the play button it will look something like this.

IoT Soil Moisture Sensor

You can see that red error sign, it means right now it’s not connected with the Nodemcu ESP8266, because right now my Nodemcu module is OFF.

Required Arduino Libraries:

Before, you start the programming, first of all, make sure you download all the necessary libraries.

Download: Adafruit_GFX.h

Download: Adafruit_SSD1306.h

The Adafruit_GFX.h and Adafruit_SSD1306.h libraries I have been using for quite a long time and I have already explained how to download and use these libraries.

I have also a very detailed getting started tutorial on the ESP8266 WiFi module, in which I have explained how to install the ESP8266 using the Boards manager URL link. And how to use Blynk application. You will also learn how to download and install BlynkSimpleEsp8266.h.

IoT Soil Moisture Sensor Programming:

IoT Soil Sensor code explanation:

This is the authorization code that is sent while making the blynk application. So, simply copy your authorization code and paste it over here.

Next, enter your WiFi credentials, your WiFi router name or your smartphone Hotspot name, and the password.

These lines of codes are used with the Oled display module.

Next, I defined some variables.

Inside the setup() function, I activated the Serial communication, Blynk, and Oled display, and also told the controller which pins are going to be used as the input and output. The rest of the code is pretty straightforward.

We simply run the Blynk, read the soil moisture sensor, map the moisture value to display the soil moisture value in percentage. Finally, we print the values on the Oled display module and also send the values to the Blynk application through virtual pin V1.

We use this if condition to check if the soil moisture is dropped below the setmoisture value which is the set value and then the controller accordingly sends the notification message and controls the buzzer.

If you remember, I was using a slider on the Blynk application to set the moisture level. The value from the slider is sent to the Nodemcu ESP8266 WiFi module through this virtual pin V2. So, that’s all about the programming.

Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Back to top button
%d bloggers like this: