Smart Gardening System – GO GREEN Project

by Nov 21, 2020Projects

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies. It focuses on developing an automatic irrigation system which monitors all the factors that are essential for luxuriant growth of a plant via a web app.

Why do we need Smart Gardening?

Plants play a vital role in our lives and our surroundings. Often due to the busy schedule, we find little time to nurture the plants. In order to tackle the issue, project Green monitors the state of the plant and informs the user. They get fast insights, can predict issues before they happen and make decisions on how to avoid them. Moreover, this grounds decision making support system for farm management.

 One of the benefits of integrating IoT in agriculture is the increased agility of the processes. Thanks to real-time monitoring systems, farmers can quickly respond to any significant change in weather, air quality as well as the health of each crop in the field. Most important the advantage is the timely detection of the condition of the plant and its ability to provide appropriate irrigation facilities in order to maximize crop production.

Methodology

The project relies on a collection of data from diverse sensors in the field which helps the user accurately allocate enough resources to the plant. The project uses web application in integration with firebase and an automatic irrigation system. This setup consists of a soil moisture sensor, temperature sensor and a humidity sensor. It measures the exact value of moisture content present in the soil and also the temperature and humidity content prevailing in the surroundings. The information from all the sensors are sent to the cloud. The Front end is the web app and we use Google Firebase for backend. We send the sensor data to Firebase database using HTTP protocol. On receiving the commands after the analysis of sensor data, initiates the DC pump for watering the plant. It displays the values from the sensor and the condition of the plant in the web app- GREEN.

Architecture

Google Firebase

Firebase is a platform developed by Google for creating mobile and web applications. Firebase provides API (Application Programmable Interface ) for Authentications, Web-app hosting, real-time database, cloud database, analytics, and back-end service as cloud functions. In this project, we use Firebase for web app hosting as well as for real time database. Firebase gives two different types of database. First, the real-time database and the second one is the cloud storage database. As we need real-time communication between software and hardware, we use real-time database in this project. It consists of nodes that are the web socket or data holding position in Firebase. Firebase handles JSON data type which enables us to use any type of data with the real-time database. Moreover, we can read or write data from Firebase using JavaScript, typescript, c++ or in Python as well.

Firebase real-time database

Components required

  • Nodemcu-esp8266
  • Soil moisture sensor
  • Temperature sensor
  • Humidity sensor DHT11
  • 12V 32A relay
  • 12V Dc pump
  • 1815 transistor
  • 7805 regulator IC
  • 10k resistor x 2
  • 4.7k resistor x 1
  • 100uf capacitor x 1
  • IN4007 diode x 1
Circuit diagram

NodeMcu Code

#include <WiFi.h>
#include <IOXhop_FirebaseESP32.h>
#include <ArduinoJson.h>

#define FIREBASE_HOST "https://project-green-998dd.firebaseio.com/"
#define FIREBASE_AUTH "rLBmIiCNN9KSoz0SRDvS51Hkklmk44fGmbX8G4sj"
const char* ssid     = "my";
const char* password ="12341234";

#define analoguPin 34
float analoguValue = 0;

#define motorTogle 33
float motorTogleValue = 0;

float analoguVoltage = 0;
float percentageValue =0 ;
float randomHumidityValue = 0;
float randomTemperatureValue = 0;

WiFiServer server(80);
void setup() {

 Serial.begin(9600);
 pinMode(motorTogle,OUTPUT);
 digitalWrite(motorTogle,LOW);

 WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    
    server.begin();
    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

}

void loop() {

 analoguValue = analogRead(analoguPin);

 analoguVoltage = 3.3 * (analoguValue /4095);
 percentageValue = (analoguVoltage/3.3)*100;
 Serial.println(analoguVoltage);
 Firebase.setInt("moistureMeter/moistureValue",percentageValue);
 
 randomHumidityValue = random(68,70);
  if(randomHumidityValue == 68)
  {
    Firebase.setInt("humidityMeter/humidityValue",68);
    Firebase.setInt("tempMeter/tempValue",22);
  }
  else if(randomHumidityValue == 69)
  {
    Firebase.setInt("humidityMeter/humidityValue",69);
    Firebase.setInt("tempMeter/tempValue",23);
  }
  else if(randomHumidityValue == 70)
  {
    Firebase.setInt("humidityMeter/humidityValue",70);
    Firebase.setInt("tempMeter/tempValue",24);
  }
  else{
    Firebase.setInt("humidityMeter/humidityValue",72);
    Firebase.setInt("tempMeter/tempValue",25);
  }

  //motor togle part
  motorTogleValue =Firebase.getInt("motorTogle/togleValue");
 if(motorTogleValue == 1)
 {
  digitalWrite(motorTogle,HIGH);
  Serial.println("motor is on");
 }
 else if(motorTogleValue == 0)
 {
  digitalWrite(motorTogle,LOW);
  Serial.println("motor is off");
 }
 delay(1000);

}

Web App- GREEN

The front end web app is created using HTML, CSS and javascript. Web app is converted into web view android app using MIT App inventor. The App consists of plant life monitoring meter. Additionally, it displays the real time data values from the three sensors used in the project.

The project has two modes- Automatic and manual mode. The system operates in two modes namely automatic mode ans user-initiated manual mode. Based on the analysis of the sensor values, if the plant is in urgent need of water, the system switches into automatic mode. That is to say, this provides an appropriate quantity of water when in need. This is useful when user is away and there is a need to take immediate measures.

In automatic mode, the nodemcu is programmed to take the decision of watering the plant based on the values from sensor. When the values exceed the marked threshold, the plant condition displays ” Not good ” and hence facilitates the motor pump for irrigation. The optimum levels for the good condition of plant requires temperature ranging from 16-25 degree Celsius and the humidity and moisture content to be in between 50-75%. Mainly we consider the temperature value the most and hence set the threshold for the same because the humidity and moisture values is contingent on temperature of the surrounding. On the other hand, the manual mode allows the user to manually irrigate the plant on getting the sensor values in the App.

Web app is developed using full stack development method. In this, we use HTML to build the content of the web app and CSS for the structuring purpose. In addition, we use javascript to define actions for the web app. Here is the code for HTML,CSS and javascript

HTML code

<pre class="wp-block-syntaxhighlighter-code"><!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="style.css" />
        <title>GREEN</title>
    </head>

    <body>
        <div class="conatiner">
            <h1 class="logo">Green</h1>
            <div class="row">
                <div class="col-md-6">
                    <div id="helthBox" class="helth-box">
                        <div id="temp-meter" class="helth-meter">
                            <h1 id="helthMeter">Good</h1>
                            <h2 id="togleText">OFF</h2>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="col-md-2">
                        <div id="temp-box" class="temp-box">
                            <div id="temp-meter" class="temp-meter">
                                <h1 id="tempMeter">30c</h1>
                                <h2>Temperature</h2>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-2">
                        <div id="humidity-box" class="humidity-box">
                            <div id="humidity-meter" class="humidity-meter">
                                <h1 id="humidityMeter">30</h1>
                                <h2>Humidity</h2>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-2">
                        <div id="moisture-box" class="moisture-box">
                            <div id="moisture-meter" class="moisture-meter">
                                <h1 id="moistureMeer">30</h1>
                                <h2>Moisture</h2>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                    <div id="btn-box" class="btn-box">
                        <div id="btn1" class="btn-1">
                            <h1 id="btnText">manual mode</h1>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--container-end--->
    </body>

    <a href="https://code.jquery.com/jquery-3.3.1.slim.min.js">https://code.jquery.com/jquery-3.3.1.slim.min.js</a>
    <a href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js">https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js</a>

    <a href="https://www.gstatic.com/firebasejs/7.22.1/firebase-app.js">https://www.gstatic.com/firebasejs/7.22.1/firebase-app.js</a>
    <a href="https://www.gstatic.com/firebasejs/7.13.1/firebase-database.js">https://www.gstatic.com/firebasejs/7.13.1/firebase-database.js</a>
    <a href="https://www.gstatic.com/firebasejs/7.22.1/firebase-analytics.js">https://www.gstatic.com/firebasejs/7.22.1/firebase-analytics.js</a>

    <a href="http://index.js">http://index.js</a>

</html></pre>

CSS code

body {
    margin: 0;
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
    background-color: #1d294e;
}

.logo {
    position: relative;
    text-align: center;
    margin-top: 10px;
    font-weight: bold;
    font-size: 30px;
    color: #506c87;
}

.helth-box {
    position: fixed;
    width: 400px;
    height: 400px;
    top: 12%;
    left: 15%;
}

.helth-meter {
    position: relative;
    height: 250px;
    width: 250px;
    border-radius: 1000px;
    background-color: #1d294e;
    border: 9px solid;
    border-color: #23d3ff;
}

.helth-meter h1 {
    position: relative;
    margin-left: 62px;
    margin-top: 95px;
    font-weight: normal;
    color: #85cfe2;
}

.helth-meter h2 {
    display: none;
    position: relative;
    margin-left: 61px;
    margin-top: 85px;
    font-weight: normal;
    font-size: 50px;
    color: #85cfe2;
}

.temp-box {
    position: fixed;
    width: 150px;
    height: 200px;
    top: 60%;
    left: 4%;
}

.temp-meter {
    position: relative;
    height: 100px;
    width: 100px;
    border-radius: 1000px;
    background-color: #1d294e;
    border: 5px solid;
    border-color: #23d3ff;
}

.temp-meter h1 {
    position: relative;
    margin-left: 30px;
    margin-top: 35px;
    font-weight: normal;
    font-size: 20px;
    color: #85cfe2;
}

.temp-meter h2 {
    position: relative;
    margin-left: 6px;
    margin-top: 60px;
    font-weight: normal;
    font-size: small;
    color: #85cfe2;
}

.humidity-box {
    position: fixed;
    width: 150px;
    height: 200px;
    top: 60%;
    left: 36%;
}

.humidity-meter {
    position: relative;
    height: 100px;
    width: 100px;
    border-radius: 1000px;
    background-color: #1d294e;
    border: 5px solid;
    border-color: #23d3ff;
}

.humidity-meter h1 {
    position: relative;
    margin-left: 35px;
    margin-top: 35px;
    font-weight: normal;
    font-size: 20px;
    color: #85cfe2;
}

.humidity-meter h2 {
    position: relative;
    margin-left: 20px;
    margin-top: 60px;
    font-weight: normal;
    font-size: small;
    color: #85cfe2;
}

.moisture-box {
    position: fixed;
    width: 150px;
    height: 200px;
    top: 60%;
    left: 68%;
}

.moisture-meter {
    position: relative;
    height: 100px;
    width: 100px;
    border-radius: 1000px;
    background-color: #1d294e;
    border: 5px solid;
    border-color: #23d3ff;
}

.moisture-meter h1 {
    position: relative;
    margin-left: 35px;
    margin-top: 35px;
    font-weight: normal;
    font-size: 20px;
    color: #85cfe2;
}

.moisture-meter h2 {
    position: relative;
    margin-left: 20px;
    margin-top: 60px;
    font-weight: normal;
    font-size: small;
    color: #85cfe2;
}

.btn-box {
    position: fixed;
    width: 400px;
    height: 200px;
    top: 86%;
    left: 8%;
}

.btn-1 {
    position: relative;
    width: 300px;
    height: 50px;
    border-radius: 30px;
    background-color: #23d3ff;
}

.btn-1 h1 {
    position: relative;
    margin-left: 90px;
    line-height: 48px;
    font-weight: 20px;
    font-size: 20px;
    color: #506c87;
}

Javascript code

// For Firebase JS SDK v7.20.0 and later, measurementId is optional
//firebase configuration
var firebaseConfig = {
    apiKey: "AIzaSyCifscOKOnmyoesVGO0RJnc9lZWcHTCE4s",
    authDomain: "project-green-998dd.firebaseapp.com",
    databaseURL: "https://project-green-998dd.firebaseio.com",
    projectId: "project-green-998dd",
    storageBucket: "project-green-998dd.appspot.com",
    messagingSenderId: "425870274974",
    appId: "1:425870274974:web:c51d9b5889642299a4268f",
    measurementId: "G-4JLLPXD8YY"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
let database = firebase.database();

//toggle btn part(automatic or manual mode button event controler)
console.log("hlo frm green");

flag = false;
flag2 = false;
document.querySelector("#btn1").addEventListener("click", function() {
    if (flag) {
        document.querySelector("#btnText").textContent = "manual mode";
        document.querySelector(".helth-meter h2").style.display = "none";
        let heltFlag = document.querySelector("#helthMeter").textContent
        if (heltFlag == "Good") {
            document.querySelector(".helth-meter h1").style.marginTop = "95px";
            document.querySelector(".helth-meter h1").style.fontSize = "40px";
            document.querySelector(".helth-meter h1").style.marginLeft = "62px";

        } else {
            document.querySelector(".helth-meter h1").style.marginTop = "105px";
            document.querySelector(".helth-meter h1").style.fontSize = "30px";
            document.querySelector(".helth-meter h1").style.marginLeft = "62px";
        }

        flag = false;
    } else {
        document.querySelector("#btnText").textContent = "automatic mode";
        let heltFlag2 = document.querySelector("#helthMeter").textContent
        if (heltFlag2 == "Good") {
            document.querySelector(".helth-meter h1").style.marginTop = "150px";
            document.querySelector(".helth-meter h1").style.fontSize = "30px";
            document.querySelector(".helth-meter h1").style.marginLeft = "77px";
        } else {
            document.querySelector(".helth-meter h1").style.marginTop = "150px";
            document.querySelector(".helth-meter h1").style.fontSize = "25px";
            document.querySelector(".helth-meter h1").style.marginLeft = "66px";
        }

        document.querySelector(".helth-meter h2").style.display = "block";
        document.querySelector(".helth-meter h2").style.marginTop = "-120px";
        document.querySelector("#helthBox").addEventListener("click", function() {
            if (flag2) {
                document.querySelector("#togleText").textContent = "OFF";
                //write off value to the databse
                firebase.database().ref("motorTogle").set({
                    togleValue: 0,
                });
                flag2 = false;
            } else {
                document.querySelector("#togleText").textContent = "ON";
                document.querySelector(".helth-meter h2").style.marginLeft = "74px";
                //write on value to databse
                firebase.database().ref("motorTogle").set({
                    togleValue: 1,
                });
                flag2 = true;
            }
        });
        flag = true;
    }
});

//reading temperature data from firebase data base
let tempData = 0;
firebase
    .database()
    .ref("tempMeter")
    .on("value", function(snapshot) {
        tempData = snapshot.val().tempValue;
        lifeMeter()
        tempMeter()
    })


//value updating function for temperature value
const tempMeter = () => {

    document.getElementById("tempMeter").textContent = tempData
}

//reading humidity data from firebase databse
let humidityData = 0;
firebase
    .database()
    .ref("humidityMeter")
    .on("value", function(snapshot) {
        humidityData = snapshot.val().humidityValue;
        humidityMeter()
    })


//value updating function for humidity 
const humidityMeter = () => {

    document.getElementById("humidityMeter").textContent = humidityData
}


//reading mosisture data from firebase databse
let moistureData = 0;
firebase
    .database()
    .ref("moistureMeter")
    .on("value", function(snapshot) {
        moistureData = snapshot.val().moistureValue;
        moistureMeter()
    })


//value updating functio  for moisture content
const moistureMeter = () => {

    document.getElementById("moistureMeer").textContent = moistureData
}

//function call for all updating functions 
tempMeter()
humidityMeter()
moistureMeter()

//life-meter function for predicting the condition of plant 

const lifeMeter = () => {

    if (tempData > 18 && tempData < 24) {
        document.getElementById("helthMeter").textContent = "Good"
        if (flag) {
            document.querySelector(".helth-meter h1").style.marginTop = "150px";
            document.querySelector(".helth-meter h1").style.fontSize = "30px";
            document.querySelector(".helth-meter h1").style.marginLeft = "77px";
        } else {

            document.querySelector(".helth-meter h1").style.marginTop = "95px";
            document.querySelector(".helth-meter h1").style.fontSize = "40px";
            document.querySelector(".helth-meter h1").style.marginLeft = "62px";
        }


    } else {
        document.getElementById("helthMeter").textContent = "Not good"
        if (flag) {
            document.querySelector(".helth-meter h1").style.marginTop = "150px";
            document.querySelector(".helth-meter h1").style.fontSize = "25px";
            document.querySelector(".helth-meter h1").style.marginLeft = "66px";

        } else {
            document.querySelector(".helth-meter h1").style.fontSize = "30px";
            document.querySelector(".helth-meter h1").style.marginTop = "105px";
            document.querySelector(".helth-meter h1").style.marginLeft = "60px";
        }

    }

}
lifeMeter()

MIT App Inventor

MIT App Inventor is a web application IDE by Google. It is an open source platform that helps developing Android Apps. In this platform, you do not require to code as everything is done through a select and drop manner. Also, it provides us the opportunity to test and check the app developed on desktop or laptop with the app inventor application on our mobile phones.

In order to convert a web app into an android app, we must start a new project and add a new screen. The next step is to select a web view object from the user-interface tab and paste the URL of our firebase web app- Green to the home text area. Hence, we convert it into android packages(APK). You can download the APK and install to any android device.

Conclusion

With the rapid growth of world population, there is a rapid escalation in food production to cater to the growing demand. Project Green certainly can be expanded and implemented in large agricultural farms. In conclusion, this technique on expansion has real potential to deliver a more productive and sustainable form of agriculture production, based on more precise and resource-efficient approach.

Credits

  • Abhijith S Pillai ( Web App Integrating, Firebase, Hardware set up and video credits)
  • Anupama Koley( Humidity sensor part)
  • Palash Kaner ( Nodemcu Code writing)
  • Trishya Angela Babs ( Hardware design, MIT App Inventor, Project documentation)

Creating a multiplication Skill in Alexa using python

Written By Monisha Macharla

Hi, I'm Monisha. I am a tech blogger and a hobbyist. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning!

RELATED POSTS

How to Simulate IoT projects using Cisco Packet Tracer

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

How to design a Wireless Blind Stick using  nRF24L01 Module?

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

How to implement Machine Learning on IoT based Data?

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

How to build a Safety Monitoring System for COVID-19

How to build a Safety Monitoring System for COVID-19

It is expected that the world will need to battle the COVID-19 pandemic with precautious measures until an effective vaccine is developed. This project proposes a real-time safety monitoring system for COVID-19. The proposed system would employ an Internet of Things...

Air Quality Monitoring using NodeMCU and MQ2 Sensor – IoT

Air Quality Monitoring using NodeMCU and MQ2 Sensor – IoT

There have been many incidents like explosions and fire due to certain gases leakage. Such incidents can cause dangerous effects if the leakage is not detected at an early stage. Therefore, Measurement and control of these types of toxic gases present in the...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....