SuperKitz.com Project Manual
Automatic Watering System IoT using Soil Moisture Sensor NodeMCU(ESP8266) DIY Kit
Real-Time soil moisture monitoring and autonomous watering system
Plants require water on a regular basis for their proper growth and existence. This project is based on the Real-Time soil moisture monitoring and autonomous watering system using Node MCU, soil moisture sensor. The Soil sensor senses the moisture level of the soil. If the soil gets dry, the sensor senses a low moisture level, and the water supply is turned ON. The water pump gets automatically turns OFF when the sensor senses high moisture in the soil.
For this project, we will be using NodeMCU, soil moisture sensor, relay module, and BLYNK IOT dashboard.
Components
NodeMCU ESp8266
Breadboard
Single channel relay Module
Jumper wires
Soil moisture Sensor
HARDWARE
NODE MCU esp8266
Node mcu is a micro controller which is made under the LUA based firmware and architecture made for IOT application . It also includes expressif systems and hardware firmware ,which is based on the ESP-12 module. It is a very capable microcontroller which can be used easily for IOT applications with the blynk-app . The features are :
- The operating voltage is 5V
- The input voltage is between 7-12 v
- Digital input/output pins are 16
- Analog i/p pins is 1
- Flash Memory is 4 MB
- SRAM is 64 KB
- CLK Speed is 80 MHz
What is Blynk?
Blynk is an app made for smartphones to communicate with Arduino and Raspberry pi. It has a very neat graphical interface which makes it very easy to control and use. We use this with the NODE MCU esp8266.
Pin out diagram
ESP8266
Single-channel Relay Module
The single-channel 5V relay high-level trigger ac power relay board is used to control high voltage, a high current load such as motor, solenoid valves, lamps, and AC load and can be controlled directly by microcontrollers This relay is mainly designed for Arduino, PIC, AVR, DSP, and ARN and can be accessed easily using the screw terminals. This module can handle up to 2A of current. This relay works as Single Pole Double Throw (SPDT) switch with common (C), normally open (NC), normally closed (NC) pin connected to screw terminal.
Circuit Diagram
STEP1: CONNECTING MOISTURE SENSOR TO NodeMCU
Wire up the soil moisture Module
With ESP8266
Connections Explained:-
Moister Sensor VCC -> NodeMCU Vcc
Moister Sensor GND -> NodeMCU GND
Moister Sensor DO -> NodeMCU Analogy AO
- Vcc of moisture sensor is connected to Vin of the NodeMCU. The term VCC refers to the collector power supply for a transistor and the input voltage to the Arduino board when it’s using an external power source.You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.
- Gnd pin of the NodeMCU is connected to the Gnd of the NodeMCU. Gnd pin stands for Ground.
- A0 pin of the Moisture sensor can be connected to any of the analog pins of the NodeMCU, here it is connected to pin A0 of NodeMCU
- A0 pin in NodeMCU is the pin which is used for only reading analog input.Here the analog value from sensor is read through this pin.
STEP2: CONNECTING RELAY TO THE NodeMCU
Wire up the Relay Module
With ESP8266
- In the relay module, the pin marked “G” or GND indicates that it is the Ground pin, which has to be connected to the Gnd pin of the NodeMCU
- VIN or “S” in the relay module is the Signal input pin used to trigger the relay, so this pin has to be connected to the digital pin of the NodeMCU.
- Voltage pin V connected to the Vin pin of the NodeMCU.
STEP3:CONNECTING PUMP TO THE RELAY MODULE
Setting up the Blynk App : IoT Dashboard
The first step is to install the Blynk App on your smartphone inorder to monitor the sensor values
Soon after the code has been uploaded to the NodeMCU,following steps are to be performed on the Blynk App.
Step 1: Create a Blynk account and>select add new project>add project title >select nodeMCU
Step 2:Create a new project, and select your hardware as soon as you create the new account
Step 3:Select the hardware as NodeMCU
Step 4: Navigate to project settings and copy Auth Token to clipboard -or- will be sent to your email account.
A unique authentication code is sent for every new project you created by the Blynk app. In order to connect your smartphone to the hardware, you need this code. The authentication code will be sent to the email address you used at the time of registration.
Step 5: To control the digital pin, add widget “Button”
Add Labeled Value widgets to monitor the soil moisture levels from the empty canvas shown below
Step 6: Choose Virtual pin as V3
Step 7 : Program on NodeMCU and choose the Run button on the BLYNK App.
PROGRAMMING
The NodeMCU programming is the same as that of Arduino except for the distribution of pins in the Nodemcu board. Follow the below steps for programming NodeMCU & Arduino IDE
Step 1: Install the Arduino IDE 1.6.4 or Greater
Download Arduino IDE from Arduino.cc (1.6.4 or greater) –never use 1.6.2! Use your existing IDE in case if you have already installed it. In case of the proxy is giving you any problem, try downloading the ready-to-go package from the ESP8266-Arduino project
Note: In case if your board is not detected by the computer, check whether the USB data cable connection is damaged or not and if still the problem exists check if the correct driver is installed( follow step 2 to install the driver).
In order to upload code to the ESP8266 and use the serial console, connect any data-capable micro USB cable to ESP8266 IOT Board and the other side to your computer’s USB port.
The new version NodeMCUv1.0 comes with the CP2102 serial chip, you can download (also provided with the kit) and install the driver from https://www.silabs.com/products/development-tools/…. The NodeMCUv0.9 comes with the CH340 serial chip, you can download and install the driver from: https://github.com/nodemcu/nodemcu-devkit/tree/mas…
Step 2: Installing NodeMCU package for Arduino IDE
Paste the copied link(givenbelow) and insert it(add. boad Manager URL) in Arduino IDE using the following sequence->File menu -> Preferences-> Paste copied link into the area shown in the black box in the above image. Close and restart the Arduino IDE.
The link should look something like this:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Choose File menu -> select Preferences-> Paste copied link into the area shown in the black box in the above image. Then Close and restart the Arduino IDE.
Select Tools -> Boards manager and search for ESP8266 and install the libraries/files given under the heading ESP8266 by ESP community.
Restart the Arduino IDE
Scroll down, Install “esp8266 by ESP8266 Community”, from the ESP8266 board menu as shown below.
Select NodeMCU 1.0 ( ESP-12EModule), from the list of boards in Tool-Boards menu
Choose connected NodeMCU port number and the rest of the settings values can be left to default values
Install Blynk Library for Arduino IDE
Install Blynk as ZIP file in Arduino IDE
Blynk library is available as a downloadable ZIP. install 3rd party libraries in the IDE, starting with Arduino IDE version 1.0.5.
Download Blynk Library from the given below link Download Blynk Library, you should never unzip the downloaded library, leave it as is.
Download the Blynk Library
- In the Arduino IDE, select to Sketch > Include Library > Add .ZIP Library from the drop-down list in menu
- Choose the library zip file you have already downloaded.
- Return to the Sketch > Include Library menu at the bottom of the drop-down menu. Now it’s ready to be used in your sketch. In your Arduino sketches directory, the zip file will already have been expanded in the libraries folder.
Press CNTRL + A & press DELETE to clear the Arduino IDE page
Copy paste the code and click upload
Arduino Code
Download the Arduino source code.
Blynk App has two functions to send data. The first function sends water and soil moisture levels.
virtualWrite ( ) option in the Arduino Blynk library is used to write the sensor reading into virtual pins we have already configured in our Blynk app.
Before sending the values, we must configure the Wi-Fi settings
#include <BlynkSimpleEsp8266.h>
/* download the libraries only if you have not installed it before */
#define BLYNK_PRINT Serial
/* download link: https://www.superkitz.com/libraries/blynk-library-master.zip */
//node mcu
char auth[] = "h-hKQY_7iqV_RVkx6lPwfCgPRPHs42eq"; // paste the token
char ssid[] = "OnePlus 6"; //provide your ssid
char pass[] = "renjiths";//provide your hotspot password
int soilmoisture;
int analogInput = A0;
int relay = D3; //gpio pin 16 = D0
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // assigning incoming value from pin A0 to a variable
// process received value
}
void setup() {
pinMode(analogInput, INPUT);
pinMode(relay, OUTPUT);
digitalWrite(relay,HIGH);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
soilmoisture = analogRead(analogInput);
Serial.println(soilmoisture);
Blynk.virtualWrite(V0,soilmoisture);
if(soilmoisture>=750)
{
digitalWrite(relay,LOW);
}
else if(soilmoisture<750)
{
digitalWrite(relay,HIGH);
}
}
Running the System
Press the Run button to start the Blynk App. You can see that your gauges will start to display the sensor readings
The values sent to blynk cloud can be monitored via your blynk app. When the value of the monitored soil resistance (VO) becomes less than a particular value it turns on the relay and pump.