Self Watering Smart Pot Using NodeMCU

Published  February 9, 2022   0
RAJESH
Author
Self Watering Smart Pot using NodeMCU

Sometimes when we go out of our home for a few days. In this case, we cant give water to our favorite plants or we are busy with other works, so we forget to give water to our plants. Most of the time, we nearly forget about our plants in the mentioned cases. It’s hard to keep our plants alive. Because most of the indoor plants require regular watering. Here I came up with a simple solution. This is just awesome for lazy and busy people like me. My solution is a Self Watering Pot. Any normal pot can be converted into a smart pot. With smart pots, we can make our plants healthy and happy. This Self watering Pot is being made up of NodeMCU ESP8266

First, let’s see the features

Self Watering Smart Pot Features

Smart Pot Features

  • It will automatically give water when the plant needs water
  • It will show the water percentage in the soil through the app (from anywhere under the sun where the internet is available)
  • Also, it will show the temperature and humidity of the plant surroundings
  • The pot also acts as a container for water. This makes some sort of clean (we don’t need to place any bulky water containers near )
  • The sensor will detect the water level and shows in percentage.
  • We can manually give water to plants through the app.
  • There is no chance of over-watering.

Self Watering Smart Pot Working 

Smart Pot Working

In an automatic plant watering system or the smart pot, we are using an ESP microcontroller to control and sense everything. To measure the moisture in the soil and water level, we are using a capacitive soil moisture sensor. With the help of the DHT11 sensor, we can measure the temperature and humidity. After reading these values, we will send these values to the Blynk server (that’s why we are using esp microcontroller.) So that we can monitor the values using a mobile app. We can set the moisture level of the soil to turn on and off the attached water pump. We can also manually control this pump through the mobile application. So this is basically how a smart pot works.

Components Required for Making the Self Watering Smart Pot

  1. ESP8266 NodeMCU*1
  2. Capacitive soil moisture sensor*2
  3. DHT11 sensor module*1
  4. L293d motor driver/ relay*1
  5. 5v mini water pump*1
  6. 1 meter small 1cm hose*1
  7. 7.4 volt battery(9v or 6v)
  8. Female header pins
  9. 1N4007 diodes*2
  10. Common PCB
  11. Wires

ESP8266 NodeMCU

We can use any microcontroller to build an automatic irrigation system. But to convert into smart, of course, we need an internet connection, that is why I am going with the NodeMCU. We can send or receive data using NodeMCU. It has enough digital pins for our application. To know more about this check out ESP8266 NodeMCU projects.

Capacitive Soil Moisture Sensor

The job of a soil moisture sensor is to detect the water content of the soil. When it comes to this category of the sensor, we have two options that are Capacitive Soil Moisture Sensor and Resistive Moisture Sensor. As the name indicates a Capacitive soil moisture sensor is based on capacitance changes. Compared with resistive sensors, capacitive sensors do not require direct exposure of the metal electrodes, which can significantly reduce the corrosion of the electrodes.

A capacitive moisture sensor works by measuring the changes in capacitance caused by the changes in the dielectric. As we know capacitance is proportional to the dielectric medium. The capacitance of the sensor is measured using a NE555 based circuit that produces a voltage proportional to the capacitance. The sensor has 3 pins VCC, GND, and OUT. The output of a capacitive moisture sensor is an analog value. Also, we can use capacitive moisture as a water level sensor.

DHT11

The DHT11 is a commonly used temperature and humidity sensor. The sensor comes with a dedicated NTC to measure temperature the output of the DHT sensor comes as serial data of temperature and humidity. The sensor is much more accurate than other sensors and easy to interface with microcontrollers using the DHT library. The sensor can measure temperature from 0°C to 50°C and humidity from 20% to 90% with an accuracy of ±1°C and ±1%. So this is perfect for our application

Motor Driver/ Relay

We can’t directly connect the motor pump to the microcontroller because pumps will draw more current leading to the destruction of the microcontroller. So to control the pump, I used the L293D IC module, I choose this IC to decrease the size. And this  IC is good for controlling small motors.  You can also use a relay. This module is designed for controlling 2 motors. We need only one side.

Self Watering Smart Pot Circuit Diagram

Self Watering Smart Pot Circuit Diagram

In this section, I will explain all the details circuit diagram. The NodeMCU is the brain of this smart pot project. It reads the values of moisture sensors and DHT module then it sends that’s values to the Blynk server through a wifi connection. Also, It controls the pump according to the moisture in the soil or with the app commands.

Unlike other development boards like Arduino, blue pill nodemcu has only one analogue pin. But we have two analogue moisture sensors! So how to read two analogue values using one analogue pin.? In the upcoming paragraph, I am explaining how to read multiple analogue values using only one pin.

Self Watering Smart Pot Circuit

In this circuit diagram, you can see I connected positive terminals of moisture sensors to digital pins 1 and 2, so we can turn on and off each sensor by turning on and off the digital pins. That is if the d1 is on that means sensor one is on. I connected a diode on the outputs of each sensor and the other side of the diode connected to the analogue pin. Here comes the trick first, we turn D1 (that is sensor 1) at the same time we read the analogue value. So we get the analogue value of the first sensor. Next, we turn off D1 and turn on the D2 and read the analogue value so we will get the analogue value of the second sensor. here diode is for isolation between the sensors. check the coding part too for better understanding.

I connected the DHT sensor to digital pin 3 and the motor driver/relay to D4. A 10k resistor is used to pull down the motor pin. This L293D motor driver module has three power pins ground, supply, and a 5v. So I  connected ground to ground supply to the positive side of the battery and 5v to the 3.3v pin of NodeMCU. Also, remember to connect the enable to a 3.3v pin.

To power the circuit, I am using an external Battery. You can use any 6-12v battery(I recommend using an AC adapter for this). The battery is connected to the Vin and ground pins of NodeMCU and we can also connect the motor driver supply to this battery.

Making the Circuit of the Self Watering Smart Pot

I started the circuit building by placing the female and male header pins for NodeMCU and sensors. It's better to use header pins in circuits for easy troubleshooting. Also placed a 3 pin JST connector for the DHT sensor.  Then I soldered all connectors to a common PCB. After that, I connected diodes to sensor connectors and completed the soldering job.

Then I placed the NodeMCU on its socket and placed the motor driver near to the NodeMCU and connected.

Modifying the Normal Pot into Self Watering Smart Pot

This is the pot that I bought from the local market. This is a combination of two pots. The black color pot comfortably fits inside the glazing green pot. As you can see in the image, the green pot has some separating parts. That makes some space in between the two pots. We are going to use this space for storing the water.

Modifying Normal Pot into Self Watering Smart Pot

First, I closed one side of the hose using hot glue and made a small hole (enough to fit the hose) on the black pot, and inserted the hose through that hole. I made a circle using the hose inside the pot. I secured everything with glue. Then I made small holes on the hose using a soldering iron that's it. So this is the time to plant your favorite plant. So, I filled the pot with sand and soil. Then I planted a berry plant. Now I connected the hose end to the motor pump. Remember to connect enough length wire to pump.

Now, in the outer pot place the moisture level sensor on any side. Refer to images for better understanding. There is a line marking on the moisture sensor. So adjust the placing according to the water level. I fixed the moisture sensor using hot glue. Finally step is to fill the water in the outer pot and then dip the pump on water. And finally, place the plant pot. (Refer to the video and images)

Calibration of Moisture Sensor

We have to calibrate the sensors before connecting.  First, I connected one moisture sensor to the circuit. Then I admin/uploaded the calibration code. I used Arduino IDE to admin/upload and edit the code. The following lines are about how the code works.

First I declared the pins, that is the analogue pin and sensor connected digital pin.

int Pin_D2 = 5;

In the setup section, I defined the modes of pins and started the serial communication at a baud rate of 9600.

void setup() {
  Serial.begin(9600);
  pinMode(Pin_D2,OUTPUT);
  pinMode(A0,INPUT);
}

In the loop section first, I turned on the digital that is connected to the sensor. We need only the output analog values so I used the analogRead() function and read the connected sensor values. Then, I printed those values on the serial monitor.

void loop() {
   digitalWrite(Pin_D2,HIGH);
   int sensor = analogRead(A0);
   Serial.println(sensor);
   delay(1);     
} 

After admin/uploading this code to our NodeMCU, open the serial monitor and select the correct baud rate.

Step one

Hold the sensor in the air and note the analogue value. This value is our dry value. In my case, this is around 220.

moisture sensor analog value in air

Step two

Take a glass of water and put the sensor in it remember to not dip the circuit. Again note the value and this is our wet value.  In my case, this is around 600. So this value means the zero percentage  and 100 % moisture

moisture sensor in water

After getting these values connect the circuit to other sensors and the motor. place the soil moisture sensor in the soil.

Smart Pot for self Watering

Customizing the Blynk Application

I choose the blynk application because of these features

  • More customization available
  • Large community support
  • Easy to understand

So first I downloaded the blynk application from the play store and installed it on my android phone. In the app First, you have to sign up with your email. Click on a new project and give a name then choose the device as NodeMCU. Then click create where you will get a pop-up message that tells an authentication token was sent to your email id. Click on the top right corner plus icon. Select the gauge and again click on the gauge. Name the gauge as soil moisture, select pin as virtual pin V6, and in the range section change default values to 0-100. That’s it. This gauge will show the soil moisture reading of our sensor.

Blynk Application Customization

Blynk Application Customize

Same way to create 3 more gauges. The only change is in the virtual pins. You can change the color and make it more attractive. Again click on the plus icon and add level v widget this widget is for showing the water level. So I named it as water level and  I selected the virtual pin V5 also changes the range.

Finally, I added one more button widget and this is for controlling the water pump. In this case, I selected the digital pin 2. That’s all about the setting of the application

Arduino Program of Self Watering Smart Pot

As we are now finished with the build process for our smart pot, we can move on to the programming part. For this project, we are using some libraries for easy programming. Complete code is given at the end of this tutorial. The code is very simple and easy to understand. The explanation of the code is as follows.

I am going to admin/upload code to a NodeMCU board, with Arduino IDE. So, we need to add the ESP Board package in the Arduino IDE. To do this, open your Arduino IDE, then open preference from the file menu. Paste the link given below and press OK.

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Then go to tools->boards->board manager. Now search for ESP and install.

The code uses the ESP8266, Blynk, and DHT libraries. You can download the libraries from the given links. So first, included these libraries and defined the blynk serial print function.

#define BLYNK_PRINT Serial
#include
#include
#include

Since we are using the Blynk Server, the token is necessary to communicate with the server. You can copy the token from the registered email id. Then I give the SSID and password of my hotspot. If you are going to replicate this project then just replace the characters with your token, SSID, and password.

char auth[] = "EqF6GGkVt_kFgBJHIX0v32TrFcc_Wxy5";
char ssid[] = "edison science corner"; 
char pass[] = "eeeeeeee";  

Then I defined all the required integers here I used integers for storing the read value and for storing the converted soil moisture. Then I declared the pins for the sensor and motor. Also, I defined the DHT pin and the sensor type. Finally, I gave the calibrated values in dry and wet integers.

int readD1;
int readD2;
int moisture_sensor1;
int moisture_sensor2;
int Pin_D1 = 5;
int Pin_D2 = 4;
int Pin_D4 = 2;
#define DHTPIN 0
#define DHTTYPE DHT11
const int dry = 600; // value for dry sensor
const int wet = 200; // value for wet sensor
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

In the setup section first, I started the serial communication. This is just for better troubleshooting. Then I defined the modes of a pin here we have 3 outputs and one input. Also, I started the DHT and Blynk communication.

void setup() {
  Serial.begin(9600);
  pinMode(Pin_D1,OUTPUT);
  pinMode(Pin_D2,OUTPUT);
  pinMode(Pin_D4,OUTPUT);
  pinMode(A0,INPUT);
  dht.begin();
  timer.setInterval(1000L, sendSensor);
  Blynk.begin(auth, ssid, pass);
}

In this void, I read the humidity and temperature through DHT sensor and stored that float value in h hand t. Then using the Blynk.virtualWrite function I sent those values to the blynk server. Here V7 and V8 are just virtual pins.

void sendSensor() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Blynk.virtualWrite(V7, t);
  Blynk.virtualWrite(V8 , h);
}

In this loop section, I read the moisture sensor values one after the other. Since our NodeMCU has only one analogue input we have to use some tricks. (See the circuit part first) here we first turn on the D1 (first sensor) at the same time I read the analogue value of that sensor and stored it in readD1. Next, I turned off the first sensor and turned on the digital pin 2 and read the analogue value of the second sensor, and stored it in readD2.

void loop() {
   Blynk.run();
  digitalWrite(Pin_D1, HIGH);
  delay(100);                 
  readD1 = analogRead(0);  
  digitalWrite(Pin_D1, LOW);   
  delay(100); 
  digitalWrite(Pin_D2, HIGH);  
  delay(100);                    
  readD2 = analogRead(0);   
  digitalWrite(Pin_D2,LOW);    
  delay(100);

So after getting the analogue values of sensors we have to convert that into a percentage. Because the analogue values vary from 0 to 1023. For that, I used the map function. A map function has 3 parts the first one is the input in this case that is the analogue value. next is the maximum and minimum values of readings here we already read those values. And finally, the conversion values here that are from 0-100

  moisture_sensor1=map(readD1, wet, dry, 100, 0);
  moisture_sensor2=map(readD2, wet, dry, 100, 0);
  Serial.print("sensor 1 = ");  
  Serial.print(readD1);
  Serial.print(" / sensor 2 = ");  
  Serial.println(readD2);

Using if conditions here I give conditions for turning on / off of motor according to the soil moisture. The first motor will turn on if the soil moisture goes below 50%  and the motor will turn off if the soil moisture is  above 50%

if (moisture_sensor2<=50) {
    digitalWrite(Pin_D4,HIGH);
    delay(10);
}
if (moisture_sensor2>50) {
    digitalWrite(Pin_D4,LOW);
    delay(10);
}

Finally,  I send the moisture level and water level values to blynk server.

  Blynk.virtualWrite(V5, moisture_sensor1);  // to Blynk server
  Blynk.virtualWrite(V6, moisture_sensor2);  // to Blynk server
  timer.run(); 
}

Note: There is no code needed for controlling the motor through the application. we can simply set that in the blynk application.

Conclusion

Self Watering Smart Pot

After completing the code connect nodemcu to the computer and admin/upload the code. Now turn on your wifi hotspot and open the blynk app. now we can monitor and control our plant health from anywhere in the world. If you are confused with any steps you can refer to the making video also you can ask the doubts in the comment section or forum. Hope you learned something.Thanks for reading...

Code
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
char auth[] = "EqF6GGkVt_kFgBJHIX0v32TrFcc_Wxy5"; // blynk token
char ssid[] = "edison science corner";   //ssid
char pass[] = "eeeeeeee";    //password
int readD1;
int readD2;
int moisture_sensor1;
int moisture_sensor2;
int Pin_D1 = 5;
int Pin_D2 = 4;
int Pin_D4 = 2;
#define DHTPIN 0 
#define DHTTYPE DHT11 
const int dry = 600; // value for dry sensor
const int wet = 200; // value for wet sensor
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
const int dry = 600; // value for dry sensor
const int wet = 200; // value for wet sensor
void setup() 
{ 
  Serial.begin(9600);
  pinMode(Pin_D1,OUTPUT);
  pinMode(Pin_D2,OUTPUT);
  pinMode(Pin_D4,OUTPUT);
  pinMode(A0,INPUT);  
  dht.begin();
  timer.setInterval(1000L, sendSensor);
  Blynk.begin(auth, ssid, pass);
}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  Blynk.virtualWrite(V7, t);
  Blynk.virtualWrite(V8 , h);
}
void loop() 
{
   Blynk.run();
  //for first sensor
  digitalWrite(Pin_D1, HIGH);     //Turn D1 On
  delay(100);                     
  readD1 = analogRead(0);       //Read Analog value of first sensor
  digitalWrite(Pin_D1, LOW);      //Turn D1 Off
  delay(100);   
 //for second sensor
  digitalWrite(Pin_D2, HIGH);     //Turn D2 On
  delay(100);                     
  readD2 = analogRead(0);       //Read Analog value of second sensor
  digitalWrite(Pin_D2, LOW);      //Turn D2 Off
  delay(100); 
  moisture_sensor1=map(readD1, wet, dry, 100, 0);
  moisture_sensor2=map(readD2, wet, dry, 100, 0);
  //to the serial monitor
  Serial.print("sensor 1 = ");   
  Serial.print(readD1);
  Serial.print(" / sensor 2 = ");   
  Serial.println(readD2);
  if (moisture_sensor2<=50)
   {
    digitalWrite(Pin_D4,HIGH);
    delay(10);
    }
if (moisture_sensor2>50)
   {
    digitalWrite(Pin_D4,LOW);
    delay(10);
    }
  Blynk.virtualWrite(V5, moisture_sensor1);  // to Blynk server
  Blynk.virtualWrite(V6, moisture_sensor2);  // to Blynk server
  timer.run();  
}
Video

Have any question realated to this Article?

Ask Our Community Members