0% found this document useful (0 votes)
65 views

Iot Project

Uploaded by

aamai666anil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Iot Project

Uploaded by

aamai666anil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

SMART AGRICULTURE

A MINI PROJECT REPORT

Submitted by

ISSAC NIJISH C
JAIRUS PAUL SAMUEL A
JASWANTH S S
JERISH N
MERGIN M
MICHEAL RAHUL R
MOHAMED ANASH S
NANTHU M
SHAKEEN J H
WINNKO W S
In partial fulfillment for the award of the degree
of

BACHELOR OF ENGINEERING

IN

ELECTRONICS AND COMMUNICATION ENGINEERING

PONJESLY COLLEGE OF ENGINEERING, NAGERCOIL

ANNA UNIVERSITY: CHENNAI 600 025


APRIL 2024
ii
ANNA UNIVERSITY: CHENNAI 600 025

BONAFIDE CERTIFICATE

Certified that this project report “SMART AGRICULTURE”

is the Bonafide work of “ISSAC NIJISH C, JAIRUS PAUL SAMUEL A,


JASWANTH S S, JERISH N, MERGIN M, MICHEAL RAHUL R,
MOHAMED ANASH S, NANTHU M, SHAKEEN J H and WINNKO W
S” who carried out the project work under my supervision.

SIGNATURE OF THE HOD SIGNATURE OF THE SUPERVISOR

Dr. M R GEETHA, Mrs. P SMAILA JOSY,

Professor and Head, Professor,


Department of Electronics and Department of Electronics and
Communication Engineering, Communication Engineering,

Ponjesly College of Engineering, Ponjesly College of Engineering,


Nagercoil-629003. Nagercoil-629003.

iii
ABSTRACT

Smart agriculture is an emerging concept which uses IOT sensors that are

capable of providing information about agriculture fields and then act upon

them based on the user input. The aim of IOT is to propose a technology which

can generate messages to notify farmers. Our project develops a Smart

agriculture System that uses features of a few technologies such as Arduino,

Communication devices and Sensor Network. The project also incorporates

automation techniques for effective functioning. Monitoring environmental

conditions is the major factor to improve the yield of crops.

The project includes development of a system which can monitor

temperature, rain and moisture in agricultural fields through sensors using

Arduino board and display the data to the user using Network connections. The

system will continuously monitor the crops and gather data. This system can

greatly reduce the workload of users.

The system has a duplex communication interface link that allows for

data inspection and manual irrigation. This System dynamically waters the

crops based on the gathered data. The system has the potential to be useful in

water limited and geographically isolated areas.

iv
TABLE OF CONTENTS

CHAPTER NO. TITLE PAGE


NO.
ABSTRACT iii
LIST OF FIGURES v
LIST OF SYMBOLS AND ABBREVIATIONS vi

1 INTRODUCTION 1
1.1 EMBEDDED SYSTEMS 1
1.2 IOT SYSTEMS 4
1.3 IOT EMBEDDED SYSTEMS 9

2 OPERATION 10
2.1 INPUT DEVICES 10
2.2 OUTPUT DEVICES 13
2.3 PROCESSING UNIT 25
2.4 WORKING 27

3 OUTPUTS 20
3.1 DISPLAY 20
3.2 WEB APPLICATION 24

4 CONCLUSION 28
4.1 RESULTS 28
4.2 LIMITATION 29
4.3 SCOPE OF INNOVATIONS 30

APPENDICES 31
APPENDIX-1 31
APPENDIX-2 35
REFERENCE 38

v
LIST OF FIGURES

FIGURE FIGURE NAME PAGE


NO. NO.

1.1 Embedded System 3


1.2 Working of IOT 6
2.1 Capacitive Soil Moisture Sensor 10
2.2 Waterproof Temperature Sensor 11
2.3 Rain Sensor 11
2.4 Ultrasonic Sensor 12
2.5 OLED Display 13
2.6 Submersible Mini Water Pump with Relay 14
2.7 ESP8266 NodeMCU Board 15
2.8 ESP8266 NodeMCU Pin Definition 16
2.9 Integration of Components 27
3.1 Idle State 20
3.2 Rain State 21
3.3 Water Source Limitation 21
3.4 Pump Operation 22
3.5 Idle State (Web) 23
3.6 Rain State (Web) 24
3.7 Water Source Limitation (Web) 35
3.8 Pump Operation (Web) 30

vi
LIST OF SYMBOLS AND ABBREVIATIONS

SYMBOLS MEANING

A OUT Analog output from sensors


A0 Analog input pin 0 in ESP8266
S DA Serial Data pin in OLED Display
S CK Serial Clock pin in OLED Display
D0 Digital input pin 0 in ESP8266
D1 Digital input pin 1 in ESP8266
D2 Digital input pin 2 in ESP8266
D4 Digital input pin 4 in ESP8266
D5 Digital input pin 5 in ESP8266
D7 Digital input pin 7 in ESP8266
D8 Digital input pin 8 in ESP8266
D OUT Digital output pin in sensors
T IN Trigger input pin in Ultrasonic sensor
E OUT Echo output pin in Ultrasonic sensor
R IN Signal input pin in relay
Wi-fi Wireless Fidelity
IP Internet Protocol

vii
CHAPTER 1

INTRODUCTION

1.1 EMBEDDED SYSTEMS

System is a set of interrelated parts/components which are


designed/developed to perform common tasks or to do some specific work for
which it has been created.
Embedded means including something with anything for a reason. Or
simply we can say something which is integrated or attached to another thing.
Now after getting what actual systems and embedded mean we can easily
understand what Embedded Systems are.

Embedded System is an integrated system that is formed as a


combination of computer hardware and software for a specific function. It can
be said as a dedicated computer system has been developed for some reason.
But it is not our traditional computer system or general-purpose computers,
these are the Embedded systems that may work independently or attached to a
larger system to work on a few specific functions. These embedded systems
can work without human intervention or with little human intervention.

Three main components of Embedded systems are:


1.Hardware
2.Software
3.Firmware

1
1.1.1 Application areas of Embedded System
Mostly Embedded systems are present everywhere. We use it in our
everyday life unknowingly as in most cases it is integrated into the larger
systems. So, here are some of the application areas of Embedded systems:

 Transportation
 Business sector & offices
 Defense sector
 Agricultural Sector

1.1.2 Important Characteristics of an Embedded System:

a. Performs specific task: Embedded systems perform some specific


function or tasks.
b. Low Cost: The price of an embedded system is not so expensive.
c. Time Specific: It performs the tasks within a certain time frame.
d. Low Power: Embedded Systems don’t require much power to operate.
e. High Efficiency: The efficiency level of embedded systems is so high.
f. Minimal User interface: These systems require less user interface and
are easy to use.
g. Less Human intervention: Embedded systems require no human
intervention or very less human intervention.
h. Highly Stable: Embedded systems do not change frequently, mostly
fixed maintaining stability.
i. High Reliability: Embedded systems are reliable they perform tasks
consistently well.
j. Use microprocessors or microcontrollers: Embedded systems use
microprocessors or microcontrollers to design and use limited memory.

2
1.1.3 Block Structure Diagram of Embedded System:

Figure 1.1: Embedded System

1.1.4 Advantages of Embedded System:


 Small size.
 Enhanced real-time performance.
 Easily customizable for a specific application.
1.1.5 Disadvantages of Embedded System:
 High development cost.
 Time-consuming design process.
 As it is application-specific, low availability in market.
1.1.6 Top Embedded Programming Languages:
Embedded systems can be programmed using different programming
languages like Embedded C, Embedded C++, Embedded Java and Python.

3
1.2 IOT SYSTEMS

IOT stands for Internet of Things. It refers to the interconnectedness of


physical devices, such as appliances and vehicles, that are embedded with
software, sensors, and connectivity which enables these objects to connect and
exchange data. This technology allows for the collection and sharing of data
from a vast network of devices, creating opportunities for more efficient and
automated systems.
Internet of Things (IOT) is the networking of physical objects that
contain electronics embedded within their architecture in order to communicate
and sense interactions amongst each other or with respect to the external
environment. In the upcoming years, IOT-based technology will offer advanced
levels of services and practically change the way people lead their daily lives.
Advancements in medicine, power, gene therapies, agriculture, smart cities, and
smart homes are just a few of the categorical examples where IOT is strongly
established.
IOT is a system of interrelated things, computing devices, mechanical and
digital machines, objects, animals, or people that are provided with unique
identifiers. And the ability to transfer the data over a network requiring human-
to-human or human-to-computer interaction.
Four Key Components of IOT are:
 Device or sensor
 Connectivity
 Data processing
 Interface

4
1.2.1 Main Components Used in IOT
 Low-power embedded systems: Less battery consumption, high
performance are the inverse factors that play a significant role during the
design of electronic systems.
 Sensors: Sensors are a major part of any IOT application. It is a physical
device that measures and detects certain physical quantities and converts it
into signal which can be provided as an input to processing or control unit
for analysis purposes.
1.2.2 IOT Enablers
 RFIDs: Uses radio waves in order to track physical objects.
 Sensors: Devices that are able to detect changes in an environment.
 Nanotechnology: Using tiny devices with dimensions usually less than
a hundred nanometers.
1.2.3 Working with IOT Devices
 Collect and Transmit Data: For Data collection purposes sensors are
widely used.
 Actuate device based on triggers produced by sensors or processing
devices: If certain conditions are satisfied or according to user’s
requirements if certain trigger is activated then which action to perform
that is shown by Actuator devices.
 Receive Information: From network devices, users or devices can take
certain information also for their analysis and processing purposes.
 Communication Assistance: Communication assistance is the
phenomenon of communication between 2 networks or communication
between 2 or more IOT devices of the same or different networks. This
can be achieved by different communication protocols like: MQTT,
Constrained Application Protocol, ZigBee, FTP, HTTP etc.

5
Figure 1.2: Working of IOT

1.2.4 Characteristics of IOT


 Massively scalable and efficient.
 IP-based addressing will no longer be suitable in the upcoming future.
 An abundance of physical objects is present that do not use IP, so IOT
is made possible.
 Devices typically consume less power. When not in use, they should be
automatically programmed to sleep.
 A device that is connected to another device right now may not be
connected in another instant of time.

6
1.2.5 Desired Quality of any IOT Application
 Interconnectivity: It is the basic first requirement in any IOT
infrastructure. Connectivity should be guaranteed from any devices on
any network then only devices in a network can communicate with each
other.
 Dynamic in Nature: IOT devices should dynamically adapt themselves to
the changing surroundings like different situations and different prefaces.
 Self-adapting and self-configuring technology : For example,
surveillance cameras. It should be flexible to work in different weather
conditions and different light situations (morning, afternoon, or night).
 Intelligence: Just data collection is not enough in IOT, extraction of
knowledge from the generated data is very important. For example, sensors
generate data, but that data will only be useful if it is interpreted properly.
So, intelligence is one of the key characteristics in IOT. Because data
interpretation is the major part in any IOT application because without data
processing we can’t make any insights from data. Hence, big data is also
one of the most enabling technologies in the IOT field.
 Safety: Sensitive personal details of a user might be compromised when
the devices are connected to the Internet. So, data security is a major
challenge. This could cause a loss to the user. Equipment in the huge IOT
network may also be at risk. Therefore, equipment safety is also critical.
 Architecture: It should be hybrid, supporting different manufacturer’s
products to function in the IOT network.
 As a quick note, IOT incorporates trillions of sensors, billions of smart
systems, and millions of applications.

7
1.2.6 Advantages of IOT
 Improved efficiency and automation of tasks.
 Increased convenience and accessibility of information.
 Better monitoring and control of devices and systems.
 Greater ability to gather and analyze data.
 Improved decision-making.
 Cost savings.
1.2.7 Disadvantages of IOT
 Security concerns and potential for hacking or data breaches.
 Privacy issues related to the collection and use of personal data.
 Dependence on technology and potential for system failures.
 Limited standardization and interoperability among devices.
 Complexity and increased maintenance requirements.
 High initial investment costs.
 Limited battery life on some devices.
 Concerns about job displacement due to automation.
 Limited regulation and legal framework for IOT, which can lead to
confusion and uncertainty.

8
1.3 IOT Embedded Systems

Embedded systems and the Internet of Things (IOT) are closely


intertwined, shaping the landscape of modern technology.
Role:

o Foundation: Embedded systems form the foundation for building


IOT devices.
o Data Collection: They collect data from sensors about the physical
world.
o Processing and Transmission: This data is processed and
transmitted to other devices or the cloud for analysis and action.

IOT and Embedded Systems, in summary, have a SymbIOTic


Relationship in which Embedded systems enable IOT devices to function
efficiently and reliably thus making them essential for IOT’s success.
Embedded systems serve as the backbone of IOT, enabling connectivity,
communication, and intelligent actions in our interconnected world.

9
CHAPTER 2

OPERATION

2.1 INPUT DEVICES


Input devices are the components that let the system gather information
about the surrounding environment. These devices convert the different stimuli
into signals that can be interpreted by the embedded system. The different input
devices used in the system are Capacitive Soil Moisture sensor, Waterproof
Temperature sensor, Rain sensor and Ultrasonic sensor.
2.1.1 Capacitive Soil Moisture Sensor:

Figure 2.1: Capacitive Soil Moisture Sensor

A capacitive soil moisture sensor measures the moisture content in the


soil by detecting changes in capacitance caused by variations in soil moisture
levels. The sensor utilizes two electrodes to measure the dielectric constant of
the soil, which changes with moisture content. This change in dielectric
constant alters the sensor's capacitance, providing a moisture level reading.
This is commonly used in agriculture and gardening applications to optimize
irrigation, prevent overwatering or underwatering of plants, and monitor soil
conditions for improved plant growth.

10
2.1.2 Waterproof Temperature Sensor:

Figure 2.2: Waterproof Temperature Sensor

A waterproof temperature sensor is designed to measure temperature


accurately even in harsh environments or submerged conditions. The sensor
typically employs a thermistor or a temperature-sensitive resistor to measure
temperature changes. It converts temperature variations into electrical signals
that can be read by a microcontroller.
2.1.3 Rain Sensor:

Figure 2.3: Rain Sensor

A rain sensor detects the presence of moisture from rainfall, enabling


systems to respond accordingly, such as activating irrigation. The sensor
employs conductive plates that detect the presence of water droplets. When rain
fall on the plate, they create a conductive path, triggering the sensor.

11
2.1.4 Ultrasonic Sensor:

Figure 2.4: Ultrasonic Sensor

An ultrasonic sensor measures distance by emitting ultrasonic waves and


detecting the time it takes for the waves to bounce back from an object, such as
the surface of a liquid in a tank. The sensor emits ultrasonic pulses and
measures the time it takes for the pulses to reflect from the liquid surface. This
time is used to calculate the distance to the liquid surface, thus determining the
water level. Used in various industries for non-contact distance measurement,
such as monitoring water levels in tanks, barrels, or reservoirs, and in robotics
for obstacle detection and navigation.

12
2.2 OUTPUT DEVICES

Output devices are the components that let the system provide
information to the user. These devices convert the electrical signals into actions
or provide visualization to the user. The different output devices used in the
system are OLED Display, Submersible Mini Water Pump with Relay.

2.2.1 OLED Display:

Figure 2.5: OLED Display

An OLED display is a type of display technology that uses organic


compounds to emit light when an electric current is applied. Each pixel in an
OLED display consists of organic materials that emit light in response to an
electric current. This allows for high contrast, vibrant colours, and wide viewing
angles.

13
2.2.2 Submersible Mini Water Pump with Relay:

Figure 2.6: Submersible Mini Water Pump with Relay

A submersible mini water pump, controlled by a relay, is employed to


automate the irrigation system in response to moisture levels detected by the
soil moisture sensor. When triggered by the microcontroller based on
predefined moisture thresholds, the relay activates the water pump, delivering
water to the plants as needed.

14
2.3 PROCESSING UNIT
The ESP8266 is a versatile and cost-effective Wi-Fi module that
has gained immense popularity among hobbyists, engineers, and IOT
enthusiasts for its capability to enable wireless communication and
connectivity in various projects.

2.3.1 Microcontroller Unit (MCU):


The ESP8266 board is powered by a Tensilica L106 32-bit
microcontroller unit (MCU), clocked at 80MHz (or higher) with a built-in
2.4 GHz Wi-Fi transceiver.
It features ample processing power and memory resources, making
it suitable for handling various IOT applications and tasks efficiently.

Figure 2.7: ESP8266 NodeMCU Board

2.3.2 Connectivity:
One of the standout features of the ESP8266 is its built-in Wi-Fi
capability, allowing seamless wireless communication with other devices
and networks.
It supports both station (STA) and access point (AP) modes,
enabling it to connect to existing Wi-Fi networks or create its own
network for other devices to connect to.

15
2.3.3 GPIO Pins:
The ESP8266 board typically comes with a number of General-
Purpose Input/Output (GPIO) pins, which can be configured and
programmed for various tasks such as reading sensor data, controlling
actuators, or interfacing with other peripherals.
These GPIO pins provide flexibility and expandability, allowing
the board to interface with a wide range of sensors, actuators, and
external modules.

Figure 2.8: ESP8266 NodeMCU Pin Definition

16
2.3.4 Programming Interface:
Programming the ESP8266 board can be done using a variety of
development environments and programming languages, including
Arduino IDE, MicroPython, Lua, and more.
The availability of extensive documentation, tutorials, and
community support makes it relatively easy for beginners to get started
with programming and development

2.3.5 Power Consumption:


The ESP8266 is known for its low power consumption, making it
suitable for battery-operated or energy efficient IOT applications.
Various power-saving modes are available, allowing the board to
minimize power consumption during idle or low activity periods.

2.3.6 Form Factor:


ESP8266 boards come in various form factors and configurations,
ranging from standalone modules to development boards with integrated
peripherals such as USB-to-serial converters, voltage regulators, and
more.
This versatility makes it easy to integrate the ESP8266 into
different projects and prototypes without the need for extensive hardware
design or modification.

2.3.7 Community Support:


The ESP8266 has a large and active community of developers,
hobbyists, and enthusiasts who contribute to the ecosystem by sharing
code, libraries, tutorials, and troubleshooting tips.

17
2.4 WORKING

The Arduino board is the most important part of this Embedded System.
They perform processing function. It takes the data from different sensors and
operates on the information provided by them. The block diagram of the circuit
connections can be seen below.

Figure 2.9: Integration of Components

The Soil moisture Sensor’s A OUT pin is connected to the Arduino board’s
A0 pin. The power supply is provided to the Soil Moisture sensor from the
Arduino. The Soil moisture Sensor will transmit the current level of moisture to
the Arduino using the analog connection.

18
The display derives the power from Arduino board. The S pin from the
DA

display is connected to the D1 pin of Arduino. The S pin from the display is
CK

connected to the D2 pin of the Arduino board. It presents various information


about the field to the user visually.

The Rain sensor obtains power supply from the Arduino board. The D OUT

pin from the Rain sensor is connected to the D 0 pin in the Arduino. The Rain
sensor will notify the Arduino if there is a certain amount of rain in the field.

The Ultrasonic sensor draws power from the Arduino board for operation.
T IN pin of the Ultrasonic sensor is connected to the D 4 pin of the Arduino
similarly the E OUT pin of the Ultrasonic sensor is connected to the D 5 pin of the
Arduino board. The Ultrasonic sensor transmits the water level data of the water
source to the Arduino board.

The Temperature sensor receives power from the Arduino board. The D OUT

pin from the Temperature sensor is connected to the D 7 pin in the Arduino
board. The Temperature sensor will provide field temperature data to the
Arduino board.

The Water Pump is connected to the power supply by means of a relay


circuit the R pin of relay is connected to the to the D 8 pin of the Arduino to
IN

control the power supply to the Water Pump. When input signal is provided
from the Arduino the Water Pump will start to irrigate the field.

19
The Arduino will continuously get the data from the input devices namely
Soil Moisture sensor, Rain sensor, Ultrasonic sensor and Temperature sensor.
These data are displayed visually to the user with the help of the display device.
The same data is processed in order to transmit to web application. Transfer of
data is done with the help of the integrated Wi-Fi module present in the Arduino
board.

We can access the field data from afar by simply connecting to the IP
address provided by the Arduino board. In addition to monitoring the data, we
can also control the operation of Water pump from far away using the switch in
the web application.

20
CHAPTER 3

OUTPUTS

3.1 DISPLAY

There are various situations that may arise in the implementation of the
System. The following images show the different output seen on the display in
different scenarios.

3.1.1 Idle State:

In the idle state the field has no rain. The level at the water source in idle
state is sufficient for irrigation. The water pump is in off state. The following
figure shows the state of the display during idle state.

Figure 3.1: Idle State

21
3.1.2 Rain State:
When there is rain in the field the System does not need to water the
plants. The following figure shows the display when there is rain in the field.

Figure 3.2: Rain State

3.1.3 Water Source Limitation:


When there is not sufficient water in the water source turning on the
water pump is not desirable. The following figure shows the display when there
is low water level at the source.

Figure 3.3: Water Source Limitation

22
3.1.4 Pump Operation:

The user might need to know if the water pump is turned on. This will
help the user monitor the operation of the System. The following figure shows
the display when there is low water level at the source.

Figure 3.4: Pump Operation

23
3.2 WEB APPLICATION
The web application helps the user access and monitor the data about the
field. The following images show the different output seen on the display in
different scenarios.

3.2.1 Idle State (Web):


Similar to that of the actual display the user can access the data about the
idle state of the system using the web application. The following figure shows
the web application in the idle state.

Figure 3.5: Idle State (Web)

24
3.2.2 Rain State (Web):

Similar to that of the actual display the user can access the data about the
rain state of the system using the web application. The following figure shows
the web application in the rain state.

Figure 3.6: Rain State (Web)

25
3.2.3 Water source Limitation (Web):

Similar to that of the actual display the user can access the data about the
water source of the system using the web application. The following figure
shows the web application displaying water source level alert.

Figure 3.7: Water Source Limitation (Web)

26
3.2.4 Pump operation (Web):

Similar to that of the actual display the user can access the data about the
pump operation of the system using the web application. The following figure
shows the web application displaying the pump operation.

Figure 3.8: Pump Operation (Web)

27
CHAPTER 4

CONCLUSION

4.1 RESULTS

From the above instances we can see that the Smart Agriculture
System can be used for real-time agriculture purposes. When it is raining
in the field the system will avoid irrigating the field, conserving Energy.
If the soil moisture falls below the threshold level the system will
automatically water the crops thus ensuring that the crop has sufficient
moisture level at all times. The System will make sure that the water
source has sufficient water for irrigation.

This System is very convenient to use. They can help the user to
increase the crop yield. It reduces overall costs and improves the quality
and quantity of products. It Increases the control over production, leading
to improved cost management and waste reduction. It eliminates the risk
of losing yields by tracing anomalies in crop growth.

28
4.2 LIMITATIONS

Although there are a lot of features in the system provided, there


are certain limitations to it. They are provided below:

 Internet Connectivity: Smart agriculture relies on


continuous internet availability, which can be a challenge in
rural areas of developing countries with slower connections.

 Manual Login: The user needs to access the web


application manually thus there may be delay in the
notification of important data.

 Hardware Handling: The hardware might be damaged due


to heat and humidity in the atmosphere of the field.

 Crop Health: The System does not monitor the health of the
crops and the nutrients in the soil.

29
4.3 SCOPE OF INNOVATIONS

The provided system is very extensible and hence can be easily supplemented
with other functionalities some of the possible enhancements are as follows:

 Dynamic Notification: The dynamic notification allows the important


data to be observed by the user without the need to login onto the
website.

 Solar Energy: The Hardware system can be operated with solar


energy with the help of solar cells and solar panels. This will decrease
the Energy consumption.

 Segmentation: The current system is scaled for a single crop, but we


can segment the field into a number of sections, each for different
crops. Each of these sections will be calibrated for a particular crop.
This will provide a more favorable environment for the crops

 Crop Data: Improvements to the current system can allow the user to
monitor the rate of growth of the crop, the current stage of crop life
cycle, estimated time for harvest, etc.

30
APPENDICES

Appendix – 1

Arduino Program for Operation

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define SCREEN_WIDTH 128


#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH,SCREEN_HEIGHT,&Wire,
OLED_RESET);

const int soilMoisturePin = A0;


const int pumpPin = D8; // Pin connected to water pump
const int airValue = 720; // Replace with your air value
const int waterValue = 300; // Replace with your water value
const int minMoisture = 30; // Define the range of soil moisture to control motor pump
const int maxMoisture = 70; // Adjust as needed

const int rain_POWER_PIN = D0;


const int rain_DO_PIN = D6;

const int trigPin = D4; // Pin connected to the trigger pin of HC-SR04
const int echoPin = D5; // Pin connected to the echo pin of HC-SR04

const int temperatureSensorPin = D7; // Pin connected to DS18B20 temperature sensor

const float tankHeight = 50.0; // Height of the tank in centimeters


const float maxDistance = 200.0; // Maximum distance sensor can detect in centimeters

OneWire oneWire(temperatureSensorPin);
DallasTemperature sensors(&oneWire);

void setup() {
pinMode(pumpPin, OUTPUT);
digitalWrite(pumpPin, LOW); // Ensure pump is initially off

pinMode(rain_POWER_PIN, OUTPUT); // pin configure for rain sensor


pinMode(rain_DO_PIN, INPUT);

pinMode(trigPin, OUTPUT); //tank water level

31
pinMode(echoPin, INPUT);
Serial.begin(9600);
sensors.begin(); // Initialize temperature sensor

if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
}

void loop() {

int soilMoistureValue = analogRead(soilMoisturePin);


int moisturePercent = map(soilMoistureValue, airValue, waterValue, 0, 100);

// Display soil moisture level


display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Soil Moisture = ");
display.print(moisturePercent);
display.println("%");

// Control the water pump based on soil moisture level


if (moisturePercent < minMoisture) {
digitalWrite(pumpPin, HIGH); // Turn on the pump
display.setCursor(0, 10);
display.print("Pump Status = ON ");
} else if (moisturePercent > maxMoisture) {
digitalWrite(pumpPin, LOW); // Turn off the pump
display.setCursor(0, 10);
display.print("Pump Status = OFF");
}

// Display rain status


digitalWrite(rain_POWER_PIN, HIGH); // Turn the rain sensor's power ON
delay(10);
int rain_state = digitalRead(rain_DO_PIN);
digitalWrite(rain_POWER_PIN, LOW); // Turn the rain sensor's power OFF

display.setCursor(0, 20);
display.print("Rain Status : ");
if (rain_state == HIGH){
display.println("\n < No rainfall >");
} else {
display.println("\n < rainy >");
}

32
// Display tank water level
float duration, distance, percentage;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
if (distance <= tankHeight) {
percentage = ((tankHeight - distance) / tankHeight) * 100.0;
} else {
percentage = 0.0; // Tank is empty
}
display.setCursor(0, 40);
display.print("Water Level = ");
display.print(percentage);
display.println("%");

// Read temperature from DS18B20 sensor


// Define a correction factor
float correctionFactor = -8; // Example correction factor, adjust as needed

// Read temperature from DS18B20 sensor


sensors.requestTemperatures(); // Send the command to get temperatures
float temperatureC = sensors.getTempCByIndex(0);

// Check if the temperature reading is valid


if (temperatureC != DEVICE_DISCONNECTED) {
// Apply correction factor
temperatureC += correctionFactor;

// Display the adjusted temperature


display.setCursor(0, 50);
display.print("Temperature = ");
display.print(temperatureC);
display.println("C");
} else {
// Display error message if reading failed
display.setCursor(0, 50);
display.println("Error reading temperature");
}

display.display();

33
// Display sensor readings on Serial Monitor
Serial.print("Soil Moisture = ");
Serial.print(moisturePercent);
Serial.println("%");
Serial.print("Water Level = ");
Serial.print(percentage);
Serial.println("%");
Serial.print("Temperature = ");
Serial.print(temperatureC);
Serial.println("C");

delay(1000); // Adjust delay as needed


}

34
Appendix – 2

Arduino Program for Web Implementation

Integrate the following code to merge the web application

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

const char *ssid = "redmi";


const char *password = "123456789";

ESP8266WebServer server(80);
String rain_status = "NO RAIN"; // Initialize rain status

// Global variables to store sensor readings


int moisturePercentGlobal;
String rainStatusGlobal;
float waterLevelGlobal;
float temperatureCGlobal;

void readSensorValues() {
// Read soil moisture value
int soilMoistureValue = analogRead(soilMoisturePin);
moisturePercentGlobal = map(soilMoistureValue, airValue, waterValue, 0, 100);

// Read rain status


int rain_state = digitalRead(rain_DO_PIN);
rainStatusGlobal = (rain_state == HIGH) ? "RAINY" : "NO RAIN";

// Read tank water level


float duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
waterLevelGlobal = distance;

// Read temperature from DS18B20 sensor


sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
float correctionFactor = -8; // Example correction factor, adjust as needed
temperatureCGlobal = (temperatureC != DEVICE_DISCONNECTED_C) ? temperatureC +
correctionFactor : DEVICE_DISCONNECTED_C;
}

35
void handleRoot() {
Serial.println(waterLevelGlobal);
String page = "<html><head><title>SMART AGRICULTURE</title>";
page += "<style>body { font-family: Arial, sans-serif; margin: 20px; background-color:
#f2f2f2; }";
page += "h1 { text-align: center; } .sensor-container { border: 2px solid #ccc; padding:
20px; ";
page += "border-radius: 10px; margin-bottom: 20px; background-color: #fff; box-shadow: 0
4px 8px 0 rgba(0, 0, 0, 0.2); }";
page += ".sensor-container p { margin-bottom: 10px; } .status { color: green; font-weight:
bold; }";
page += ".status.rainy { color: red; } .reading { font-size: 20px; } .meter { width: 100px;
height: 100px; ";
page += "border-radius: 50%; background: conic-gradient(#4caf50 0% " +
String(moisturePercentGlobal) + "%, #f0f0f0 " + String(moisturePercentGlobal) + "%
100%);";
page += "border: 5px solid #ccc; margin: 0 auto; position: relative; } .meter:after { content:
''; position: absolute;";
page += "top: 50%; left: 50%; transform: translate(-50%, -50%); width: 90px; height: 90px;
border-radius: 50%; background-color: #fff; }";
page += ".meter-value { position: absolute; top: 50%; left: 0; transform: translate(0, -50%);
width: 100%; text-align: center; ";
page += "font-size: 18px; color: #333; }</style><script>function updateMeters() {";
page += "var meters = document.getElementsByClassName('meter');";
page += "for (var i = 0; i < meters.length; i++) {";
page += "var meter = meters[i];";
page += "var reading = meter.dataset.reading;";
page += "var percentage = parseFloat(reading);";
page += "var meterValue = meter.querySelector('.meter-value');";
page += "meter.style.background = 'conic-gradient(#4caf50 0% ' + percentage + '%, #f0f0f0
' + percentage + '% 100%)';";
page += "meterValue.textContent = reading + '%'; } } setInterval(updateMeters,
200);</script></head><body>";
page += "<h1>Sensor Readings</h1>";
page += "<div class='sensor-container'>";
page += "<p><span class='reading'><strong>Soil Moisture:</strong></span> <span
class='reading'>" + String(moisturePercentGlobal) + "%</span></p>";
page += "<div class='meter' data-reading='" + String(moisturePercentGlobal) + "'><div
class='meter-value'>" + String(moisturePercentGlobal) + "%</div></div>";
page += "<p><span class='reading'><strong>Rain Status:</strong></span> <span
class='status reading'>";
page += rainStatusGlobal + "</span></p>";
page += "<p><span class='reading'><strong>Water Level:</strong></span> <span
class='reading'>" + String(waterLevelGlobal) + "%</span></p>";
page += "<div class='meter' data-reading='" + String(waterLevelGlobal) + "'><div
class='meter-value'>" + String(waterLevelGlobal) + "%</div></div>";
page += "<p><span class='reading'><strong>Temperature:</strong></span> <span
class='reading'>" + String(temperatureCGlobal) + "C</span></p>";
page += "<div class='meter' data-reading='" + String(temperatureCGlobal) + "'><div
class='meter-value'>" + String(temperatureCGlobal) + "C</div></div>";

36
page += "</div></body></html>";
server.send(200, "text/html", page);
}
void setup(){

// code to setup different components connected to the board

WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");

server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
Serial.println(WiFi.localIP());
}

void loop(){

readSensorValues();

// code to present the data on the display


// code to run the features of the system

server.handleClient();

37
REFERENCE

Connecting components to the Arduino board:

23 Sensors for Arduino: Uses, Costs and How to Connect – Chip Wired

Arduino - Rain Sensor | Arduino Tutorial (arduinogetstarted.com)

Arduino - Relay | Arduino Tutorial (arduinogetstarted.com)

Arduino - OLED | Arduino Tutorial (arduinogetstarted.com)

Code for System Operation:

Arduino Project Hub

Code for Merging Web Application:

How to Show Arduino Sensor Data on a Web Page - Circuit Basics

38

You might also like