Arduino IOT Project: watering plants and soil moisture monitoring

(Last Updated On: September 12, 2020)

soil moisture

Description:

This is an iot based project designed for monitoring the Soil moisture and controlling the Solenoid valve from anywhere around the world. The soil moisture is monitored using the Blynk application. This project is based on the Nodemcu esp8266 wifi module, soil moisture sensor, Solenoid Valve, and Arduino Uno or Mega.

In this project two-way communication is used, we can monitor the soil moisture and also control the Solenoid valve in Realtime.

If you are working on the moisture sensor for the first time then I recommend you should watch my getting started tutorial on the moisture sensor, in which I explained all the basics, including the moisture sensors modes “digital and analog” , the purpose of the potentiometer and leds, the basic circuit connections and programming explaining everything.

Recently, I posted another advanced level project based on Irrigation. this project I used the Lora transceiver modules with the Nodemcu ESP8266. The Nodemcu ESP8266 module in this project is used as the Wifi Gateway.


The components and tools used in this project can be purchased from Amazon, the components Purchase links are given below:

Arduino Uno:
Mega 2560:
Soil Moisture Sensor:
Nodemcu esp8266 wifi module: Best price:
Other Tools and Components:

Super Starter kit for Beginners

Two Channel / 200 MHz Digital Oscilloscope

Variable Supply:

Digital Multimeter:

Soldering iron kit: “best”

PCB small portable drill machine:

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

IoT Soil Moisture Monitoring Project Circuit Diagram:

soil moisture

9.1.0 version of the cadsoft eagle software is used for making the schematic. The Nodemcu module tx and Rx pins are connected with pin2 and pin3 of the Arduino. while the Vin pin of the Nodemcu module is connected with the output of the voltage regulator. This is a regulated 5v power supply based on the lm7805 voltage regulator. Two 470uf capacitors are connected at the input and output side of the regulator.  A 330-ohm resistor is connected in series with a 2.5v led. This is a current limiting resistor. while J1 is a dc female socket, over here you can connect a 12v adaptor or battery. But you can also power up the Nodemcu module using your laptop USB port. But in my case, I am going to use a 12v adaptor.

The soil moisture Sensor VCC pin is connected with Arduino’s 5v, the ground is connected with the Arduino’s ground while the A0 pin of the moisture sensor which is the analog output pin of the moisture sensor is connected with the Arduino’s analog pin A1. While the digital output pin of the moisture sensor is not connected.  While the remaining two pins are connected with the two-legged lead.

These two relays will be used to control the Solenoid valve and the water pump.


For controlling these relays we will need relay drivers, the relay drivers simply consists of the 2n2222 NPN transistors, 10k  resistors, and diodes. As you can see a 10k resistor is connected with the base of 2n2222 NPN transistor as it’s a BJT “bipolar junction transistor” a current controlled device, that’s why we need a current limiting resistor. We usually use a 10k resistor. The emitter of the 2n2222 NPN transistor is connected with the ground while the collector is connected with one side of the relay coil, while the other side of the relay coil is connected with 12volts. This relay can be energized and de-energized using this transistor.  As you can see this relay consists of 5 pins, two coil pins, common, normally closed and normally open. These three pins have no physical connection with the coil pins…. In my previous tutorial based on home automation using Nodemcu and Blynk application, I have explained this in very detail, and in that tutorial, I also explained how to connect a lamp or any other load with the relays output watch video tutorial on my YouTube channel. All the connections are exactly the same. These are freewheeling diodes, used against back emf protection.

Blynk application Designing for monitoring Soil Moisture:

soil moisture

Follow the following steps or watch video at the end of this Article for the best understanding.

  1. First of all, open the blynk application
  2. set the project name as Soil Moisture.
  3. Click on the choose device and select Nodemcu and make sure you set the connection type to wifi and then click on the create button, an authentication token will be sent on your email id, which will be then used in programming, simply copy and paste it in programming.
  4. Click anywhere on the screen and search for the gauge and add it, click on the gauge and set the name as Soil Moisture. now click on the pin and select virtual and select v2. Set the maximum value to 1023, change the font then click on the push and select 1 second.
  5. now click on the screen and add two numeric input buttons which will be used for controlling the solenoid valve and water pump……click on the numeric input…set the name as solenoid valve….click pin and select the virtual pin10…set the minimum value to 10 and the maximum value to 11.these 10 and 11 values will be used to control the relay connected with pin13 of the Arduino. …now repeat the same steps for other numeric input button.


IoT plants watering system Programming:

In this project two programs are used, one program is written for the Arduino, while another program is written for the Nodemcu esp8266 wifi module.

Soil Moisture Sensor Arduino Programming:

we simply ready the moisture using the analogread function and store the value in variable msvalue. Then using the serial.println function the value is send to the serial monitor for the debugging purposes  and then save the value in variable sdata1. And then add the value of this variable with the cdata and use comma as the delimeter for separating the sensor value. Then we send the complete message to the Nodemcu module and use a delay of 1 second and then at the end empty the cdata variable for storing new values.

Nodemcu esp8266 wifi module programming:

Watch Video Tutorial:

Recommended For You

About the Author: 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...

6 Comments

  1. Pretty element of content. I simply stumbled upon your
    site and in accession capital to say that I get actually
    loved account your weblog posts. Anyway I’ll be subscribing
    in your augment and even I achievement you get admission to constantly quickly.

    1. compilation error

      :0:9: error: expected identifier before numeric constant
      sketch\ESP8266_Lib.h:39:7: note: in expansion of macro ‘ESP8266’
      class ESP8266 {
      ^
      :0:9: error: expected unqualified-id before numeric constant
      sketch\ESP8266_Lib.h:39:7: note: in expansion of macro ‘ESP8266’
      class ESP8266 {
      ^
      In file included from C:\Users\isotec\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkApi.h:17:0,

      C:\Users\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:36:21: error: redefinition of ‘class BlynkTimer’
      #define SimpleTimer BlynkTimer
      ^
      C:\Users\Documents\Arduino\libraries\SimpleTimer-1.0.0/SimpleTimer.h:10:7: note: in expansion of macro ‘SimpleTimer’
      class SimpleTimer {
      ^
      C:\Users\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:36:21: error: previous definition of ‘class BlynkTimer’
      #define SimpleTimer BlynkTimer
      ^
      C:\Users\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:41:7: note: in expansion of macro ‘SimpleTimer’
      class SimpleTimer {
      ^

      Not used: C:\Users\isotec\AppData\Local\Temp\Rar$EXa4860.5689\arduino-nightly\libraries\Blynk
      exit status 1
      Error compiling for board NodeMCU 1.0 (ESP-12E Module).

Leave a Reply