ESP8266 IOT Project | Automatic Plant Watering System using ESP8266 nodeMCU and firebase

     

    

photo by Kaufmann Mercantile 

It always happens that whenever I go for any vacation, my plants die. Because They don’t get proper care, sunlight, and water. So to avoid that I have created this DIY project which allows me to check my plant's moisture status, even when I am not at home, and also automate watering the plant.

In this project, I am using a moisture sensor that captures soil moisture after every 1 sec and sends it to ESP8266 nodeMCU. I am also using the real-time database of firebase to store this data and get the latest data to compare moisture value with a threshold value. If the moisture value is less than the threshold value, esp8266 node MCU starts the water pump for 5 sec and if the value is higher than the threshold value, it does nothing.

Implementing this DIY project, cost me  500-700 bucks. Below I have mentioned the components required for this project. All these components are available on amazon.



Required Component


ESP8266 e-12 nodeMCU



ESP8266 e-12

ESP8266 e-12 NodeMCu development board is very inexpensive system-on-chip (SOC). It has CPU, RAM, and Wifi modules. Pins information of ESP8266 nodeMCU are mentioned below:




water pump

Choose a water pump according to the distance between the water source and plants.  I have used a 3-6V water pump because I have kept both water source and plant side by side. I am using a 9V battery, to power the water pump. 

Wiring 

        Connect the -ve pin of the battery to the -ve pin of the water pump and connect the +ve pin of the battery to the middle pin of the relay and +ve connection of the water pump to the open pin of the relay.

pump connection with battery and 5V single channel relay 




5V single channel Relay

Relay is an electro-mechanical component that acts as a switch. On the left-hand side, it has an output terminal, which is connected to AC/DC load. There are 3 pins in the o/p terminal 

NC (normal close) -  This pin is connected to create a close circuit and its connection break when the signal is sent from the relay signal pin.

COM(Common) pin - This is generally connected with AC/DC load.

NO(normal open) - this pin is generally open and it becomes close when the signal is sent from the relay signal pin

In i/p terminal, which is on the right-hand side has 3 pins - GND, Vcc, and digital pin. In this project, I have connected these pins with ESP8266 GND, 3V3, and D1 pins.




3V moisture sensor
A moisture Sensor is generally used to gauge volumetric water content in the soil. It has 4 pins - GND, Vcc, A0, and D0 pins. The pinout diagram is shown below:

the following formula is used to calculate soil moisture in percentage:
moisture_value = (100- (analogRead(input_sensor)/1023.00)*100);




male and female jumper wires

You can also use wires instead of jumper wires. But with help of jumper wires, it is very easy to connect with all components.




Schematic Diagram & Connection

Schematic diagram of esp8266 connection with moisture sensor and water pump



  Firebase Real-time database


These are the following steps to set up a real-time database in firebase:


1. Sign in to firebase and click on go to the console.



2.  Click on add project.



3. Create a new project and continue



4. Disable google analytics



5.  Select Realtime Database from the Build option mentioned on the left-hand side



6.  Select Realtime Database location and click next



7. Define security rules for your data. For this project, I have selected locked mode and defined read & write condition true

  



FIREBASE_AUTH key

 To access the firebase real-time database in the project requires the FIREBASE_AUTH key. Following are steps to access it:

1.  Click on the setting icon on the left-hand side and select project-setting.



2. Go to Service Account



3. Select Database secrets



4.  Copy the database and secret key and add them to the project



 

  Setup Arduino-Firebase library in Arduino IDE


    To make an API call for getting and sending data to the firebase real-time database from ESP8266 nodeMCU,  I am using 3rd party library - FirebaseArduino. Download this git repo library as a zip file and add in Arduino IDE:


You can find the library location in File >  Preference > Sketch folder

Coding


Copy the following code and execute this in Arduino IDE  and upload it in esp8266 nodeMCU

Post a Comment

Previous Post Next Post