Smart Farming
Smart Farming
Smart Farming
A PROJECT REPORT
Submitted by
BACHELOR OF ENGINEERING
IN
MAY-2024
i
R.M.K. ENGINEERING COLLEGE
(An Autonomous Institution)
R.S.M. Nagar, Kavaraipettai - 601206.
BONAFIDE CERTIFICATE
Certified that this project report titled “SMART FARMING” is the
bonafideworkof.K.MANASA(111721104065),K.AKHILA(111721104174),
CH.CHARISHMA(111721104301), D.POOJITHA( 111721104302) who
carried out the work under my supervision.
SIGNATURE SIGNATURE
Dr. T.Suresh, M.E., Ph.D Ms.Dr.A.Merline, M.E.,(Ph.D)
PROFESSOR AND HEAD SUPERVISOR
OF THE DEPARTMENT ASSISTANT PROFESSOR
Department of Electronics and Department of Electronics and
Communication Engineering Communication Engineering
We would like to express our heartfelt thanks to the Almighty, our beloved
parents for their blessings and wishes for successfully doing this project.
We are grateful to our Project coordinators and all the department staff
members for their intense support.
iii
ABSTRACT
Smart homes refers to energy efficient, time saving includes reduces the
human efforts. The objective of key providers was to reduce the server rental
cost by accessing through the efficient and inexpensive ESP8266 chip to the
cloud platforms on which dynamic server provisioning to reduce the server
rental cost which was the key objective for content providers. In this paper we
addressed the challenges of reducing the cost of accessing the cloud platforms.
We present the construction of ESP8266 with the Arduino or microcontroller
are attached to get the smart television, where all our choice of videos can be
stored and retrieved at any time. Through the software development kit (SDK)
in ESP8266 that allow the chip to be programmed which remove the need of
the microcontroller.
iv
Generally accessing cloud facility will produce high cost but in this paper
gives the replacement of the accessing the cloud with the ESP8266 serial chip
which operated in low power consumption with the low cost because it has
the three configurable sleep modes .Blynk was designed for the Internet of
Things.It can control hardware remotely, it can display sensor data, it can store
data, vizualize it and do many other cool things. Blynk App - allows to you
create amazing interfaces for your projects using various widgets we provide
.Normal way of controlling the IOT devices by developing the website. In
that, it has the functions like light, humidity, and temperature control. With
the help of these functions we can check and also check the status based on
our wishes. The server and sensors together used in the distributed automation
system. The control of the sensor and monitors are done with the various
sensors. Wi-Fi technology connects server and the sensors, used to improve
security, mobility and scalability.
v
TABLE OF CONTENTS
CHAPTER TITLE PAGE NO.
NO.
ACKNOWLEDGEMENT III
ABSTRACT IV
LIST OF FIGURES VIII
LIST OF TABLES IX
1 INTRODUCTION 1
1.1 Applications 2
1. 2 Advantages 2
2 PROPOSED SYSTEM 3
2.1 Existing Method 3
2.2 Implementation 3
3 METHODOLOGY 4
3.1 Hardware Setup 4
3.2 Software Development 4
3.3 Cloud Configuration 5
4 BLOCK DIAGRAM 6
4.1 DESCRIPTION 6
5 HARDWARE COMPONENTS 8
5.1 NodeMCU ESP8266 8
5.2 RELAY MODULE 12
5.3 Soil Moisture Sensor 13
5.4 BMP180 14
5.5 DHT11 Sensor: 15
5.6 External Motor Connection 16
5.7 CIRCUIT DIAGRAM OF POWER SUPPLY 15
6 CLOUD CONFIGURATION 19
6.1 ThingSpeak 19
6.2 Blynk 20
7 WORKING AND RESULT 21
7.1 WORKING 21
7.2 RESULT 22
vi
8 CONCLUSION AND FUTURE WORK 24
8.1 CONCLUSION 24
8.2 FUTURE WORK 25
9 REFERENCES 27
10 ANNEXURE 29
vii
LIST OF FIGURES
FIGURE PAGE
NO. TITLE NO.
4.1 BLOCK DIAGRAM 6
5.1 NodeMCU ESP8266 8
5.2 ESP 8266 10
viii
LIST OF TABLES
TABLE PAGE
NAME
NO NO
5.1 FEATURES OF NODE MCU ESP 8266 9
ix
CHAPTER 1
INTRODUCTION
1
1.1 Applications
• Soil moisture monitoring: IoT sensors can be used to monitor the moisture
content of soil, which is critical for crop growth. This data canbe used to
optimize irrigation and prevent over-watering or under- watering.
• Climate monitoring: IoT sensors can be used to monitor temperature,
humidity, and other climate conditions in the farm environment. This data
can be used to predict weather patterns and adjust farming practices
accordingly.
• Livestock monitoring: IoT sensors can be used to monitor the health and
well-being of livestock, including tracking their location, activity level,
and vital signs.
• Crop monitoring: IoT sensors can be used to monitor the growth and health
of crops, including detecting pests and diseases.
1. 2 Advantages
• Improved crop yield: By monitoring soil moisture, climate conditions,and
crop growth, farmers can make data-driven decisions to optimize their
farming practices and improve crop yield.
• Reduced waste: By optimizing irrigation and fertilization, farmers can
reduce waste and minimize the environmental impact of their farming
practices. Cost savings: By using IoT sensors to monitor farm conditions,
farmers can reduce labor costs and optimize the use of resources like water
and fertilizer. Predictive maintenance: IoT sensors can be used to detect
issues with equipment before they become major problems, allowing
farmers to perform maintenance before a breakdown occurs.
• Real-time monitoring: IoT sensors provide real-time data about the farm
environment, allowing farmers to make quick decisions and adjust their
farming practices accordingly.
2
CHAPTER 2
PROPOSED SYSTEM
2.1 Existing Method
In the existing agriculture system the specification such as temperature,
moisture, humidity are detected manually which increases the labor cost,
time and also monitoring cannot be done continuously. In this paper irrigation
process is done automatically using different sensors which reduces the
manual labor. Here a system is proposed to monitor crop-field using sensors
for soil moisture, humidity and temperature. By monitoring all these
parameters the irrigation can be automated with the use of raspberry pi.
2.2 Implementation
• The new developments of smart farming With use of IOT.
3
CHAPTER 3
METHODOLOGY
3.1 Hardware Setup
4
3.3 Cloud Configuration
The cloud configuration involved the following steps:
a. Setting up a ThingSpeak account
A ThingSpeak account was created and the necessary channels were
created to receive data from the NodeMCU.
b. Configuring the NodeMCU to send data to ThingSpeak
The NodeMCU was configured to send data to the appropriate
ThingSpeak channel using the channel ID and API key.
c. Visualizing the data
The data received by ThingSpeak was visualized using charts and
graphs to provide insights into crop growth, soil moisture levels,
temperature, and other key parameters.
5
CHAPTER 4
BLOCK DIAGRAM
4.1 DESCRIPTION
The block diagram for smart farming using IoT with NodeMCU and
ThingSpeak consists of several components that work together to monitor and
control various environmental parameters in a farm. The following is a
description of each component…,
Sensors: The sensors used in the system include the DHT11 sensor for
measuring temperature and humidity, soil moisture sensor for measuring soil
moisture levels, and other sensors to measure environmental parameters such
as light, pH levels, etc. The sensors are connected to the NodeMCU using
appropriate interfaces.
6
NodeMCU: The NodeMCU is an open-source development board that is used
to control and communicate with the sensors and actuators in thesystem. It is
based on the ESP8266 Wi-Fi module, which provides wireless connectivity to
the internet. The NodeMCU reads data from the sensors and sends it to
ThingSpeak over Wi-Fi.
Actuators: The actuators in the system include water pumps or sprinklers,
which are used to control irrigation based on real-time data. The actuators are
connected to the NodeMCU using appropriate interfaces.
Wi-Fi Module: The Wi-Fi module provides wireless connectivity between
the NodeMCU and ThingSpeak over the internet. The NodeMCU sends data
to ThingSpeak over Wi-Fi, and ThingSpeak receives and stores the data in its
cloud server.
ThingSpeak: ThingSpeak is an open-source IoT platform that is used to
receive and store data from the NodeMCU. The platform provides various
features such as real-time data visualization, data analytics, and alerts.
Farmers can use the data provided by ThingSpeak to make informed decisions
regarding crop management and environmental conditions.
Cloud Server: The cloud server is a central location where all the data
received from the NodeMCU is stored. The cloud server can be accessed
remotely from any location with an internet connection.
User Interface: The user interface provides farmers with access to the data
collected by the system. The data is displayed in an intuitive and user- friendly
format, making it easy for farmers to make informed decisions about crop
management and environmental conditions.
7
CHAPTER 5
HARDWARE COMPONENTS
Hardware component
• NodeMCU ESP8266
• Relay Module
• Soil Moisture Sensor
• BMP180
• DHT11
• External Motor Connection
• Power Supply
8
The prototyping hardware typically used is a circuit board functioning as a
dual in-line package (DIP) which integrates a USB controller with a smaller
surface-mounted board containing the MCU and antenna.
Developer ESP8266 Open-source Community
Type Single-board microcontroller
Introductory price 300-400 Rs
Operating system XTOS
CPU ESP8266
Memory 128kBytes
Storage 4Mbytes
Power USB
5.1 FEATURES OF NODE MCU ESP 8266
SPECIFICATIONS
• Voltage: 3. 3V.
• Wi-Fi Direct (P2P), soft-AP.
• Current consumption: 10uA~170mA.
• Flash memory attachable: 16MB max (512K normal).
• Integrated TCP/IP protocol stack.
• Processor: Tensilica L106 32-bit.
• Processor speed: 80~160MHz.
• RAM: 32K + 80K.
• GPIOs: 16 (multiplexed with other functions).
• Analog to Digital: 1 input with 1024 step resolution.
• +19.5dBm output power in 802.11b mode.
• 802.11 support: b/g/n.
• Maximum concurrent TCP connections: 5.
9
PIN DIAGRAM / PIN LOYOUT OF Node MCU ESP8266
Node MCU pin ESP 8266 pin Node MCU pin ESP 8266 pin
D0 GPIO 16 D7 GPIO 13
D1 GPIO 5 D8 GPIO 15
D2 GPIO 4 D9 GPIO 3
D3 GPIO 0 D10 GPIO 1
D4 GPIO 2 D11 GPIO 9
D5 GPIO 14 D12 GPIO 10
D6 GPIO 12
5.2 NODE MCU ESP 8266 GPIO PIN FOR LUA
ESP8266 MODULE
10
The ESP8266 is a low-cost Wi-Fi microchip, with a full
TCP/IP stack and microcontroller capability, produced by Espressif Systems
in Shanghai, China.The chip first came to the attention of Western makers in
August 2014 with the ESP-01 module, made by a third-party manufacturer Ai-
Thinker. This small module allows microcontrollers to connect to a Wi-Fi
network and make simple TCP/IP connections using Hayes-style commands.
However, at first there was almost no English- language documentation on the
chip and the commands it accepted The very low price and the fact that there
were very few external components on the module, which suggested that it
could eventually be very inexpensive in volume, attracted many hackers to
explore the module, the chip, and the software on it, as well as to translate the
Chinese documentation.The ESP8285 is an ESP8266 with 1 MiB of built-in
flash, allowing the building of single-chip devices capable of connecting to
Wi-Fi.These microcontroller chips have been succeeded by the ESP32 family
of devices, including the pin-compatible ESP32-C3.
11
6. RST, Reset
7. CH_PD, Chip power-down
8. TX, Transmit data out, also GPIO1.
12
PIN DESCRIPTION
1. Input: 0-5 V
2. VCC: Positive supply voltage
3. GND: Ground
4. IN1--IN4: Relay control port
5. Output: supports various types of loads
6. Connect a load, DC 30V/10A,AC 250V/10A
FEATURES
1. Size: 75mm (Length) * 55mm (Width) * 19.3mm (Height)
2. Weight: 61g
3. PCB Color: Blue
4. There are four fixed screw holes at each corner of the board, easy for install
and fix. The diameter of the hole is 3.1mm.
5. High quality Single relay is used with single pole double throw, a common
terminal, a normally open terminal, and a normally closed terminal
6. Optical coupling isolation, good anti-interference.
7. Closed at low level with indicator on, released at high level with indicator
off .
8. VCC is system power source, and JD_VCC is relay power source. Ship
5V relay by default. Plug jumper cap to use .
9. The maximum output of the relay: DC 30V/10A, AC 250V/10A.
5.3 Soil Moisture Sensor
The soil moisture sensor is an electronic device that is designed to measure
the amount of moisture present in the soil. It works by measuring the
resistance of the soil, which is dependent on the amount of moisture in the
soil. The sensor usually consists of two probes that are inserted into the soil,
and a circuit that measures the resistance between the probes. The resistance
13
of the soil varies with the amount of moisture present, so the sensor can
determine the soil moisture content.
14
Fig 5.6 BMP180 SENSOR
The BMP180 sensor is very accurate and reliable, and is capable of measuring
pressure with a resolution of 0.01 hPa. It is also very small and lightweight,
making it ideal for use in portable devices and remote monitoring applications.
5.5 DHT11 Sensor
15
The DHT11 sensor is very accurate and reliable, and is capable of measuring
temperature with a resolution of 1°C and humidity with a resolution of 1%
RH. It is also very small and lightweight, making it ideal for use in portable
devices and remote monitoring applications. The sensor is commonly used in
weather stations, greenhouse monitoring systems, and other applications
where temperature and humidity control are important.
5.6 External Motor Connection
• An external motor connection using a relay module in IoT involves
using a relay to control a motor from a remote location through an
internet-connected device. This allows for convenient and flexible
control of the motor, as the user can turn it on or off and adjust its speed
or direction from a smartphone, tablet, or computer.
• To implement this type of system, a relay module with appropriate
voltage and current ratings is connected to the motor's power supply
circuit. The relay is then wired to an IoT device, such as a Raspberry
Pi or Arduino board, which is programmed to communicate with a
cloud-based server or a mobile app.
• The user can then use the app or a web interface to send commands to
the IoT device, which in turn activates the relay and powers the motor.
The user can also receive feedback on the motor's status, such as its
current speed or whether it's running or not.
5.7 Circuit Diagram Of Power Supply
Today almost every electronic device needs a DC supply for its smooth
operation and they need to be operated within certain power supply limits.
This required DC voltage or DC supply is derived from single phase ac mains.
It the Rectifier AC to DC converter. A regulated power supply can convert
unregulated an AC (alternating current or voltage) to a constant DC (direct
current or voltage).
16
Fig 5.8 CIRCUIT DIAGRAM OF POWER SUPPLY
Today almost every electronic device needs a DC supply for its smooth
operation and they need to be operated within certain power supply limits.
This required DC voltage or DC supply is derived from single phase ac mains.
It the Rectifier AC to DC converter. A regulated power supply can convert
unregulated an AC (alternating current or voltage) to a constant DC (direct
current or voltage).
DESCRIPTION
The basic building blocks of a regulated DC power supply are as follows:
1. A step down transformer
2. A rectifier
3. A DC filter
4. A regulator
Step Down Transformer : A step down transformer will step down the
voltage from the ac mains to the required voltage level. The turn’s ratio of the
transformer is so adjusted such as to obtain the required voltage value. The
output of the transformer is given as an input to the rectifier circuit.
17
Rectification : Rectifier is an electronic circuit consisting of diodes which
carries out the rectification process. Rectification is the process of converting
an alternating voltage or current into corresponding direct (DC) quantity. The
input to a rectifier is ac whereas its output is unidirectional pulsating DC.
Usually a full wave rectifier or a bridge rectifier is used to rectify both the half
cycles of the ac supply (full wave rectification). Figure below shows a full
wave bridge rectifier.'
DC Filtration : The rectified voltage from the rectifier is a pulsating DC
voltage having very high ripple content. But this is not we want, we want a
pure ripple free DC
Regulation : This is the last block in a regulated DC power supply. The output
voltage or current will change or fluctuate when there is change in the input
from ac mains or due to change in load current at the output of the regulated
power supply or due to other factors like temperature changes. This
problem can be eliminatedby using a regulator.
A regulator will maintain the output constant even when changes at the
input or any other changes occur. Transistor series regulator, Fixed and
variable IC regulators or a zener diode operated in the zener region can be
used depending on their applications. IC’s like 78XX and 79XX are used to
obtained fixed values of voltages at the output. waveform. Hence a filter is
used. Different types of filters are used such as capacitor filter, LC filter,
Choke input filter, π type filter.
18
CHAPTER 6
CLOUD CONFIGURATION
6.1 ThingSpeak
ThingSpeak is a cloud-based IoT platform that allows users to connect devices
and sensors to the internet and collect data in real-time. It provides a wide
range of tools for analyzing and visualizing data, including customizable
charts and graphs, real-time maps, and data analytics tools. ThingSpeak is built
on an open-source framework and can be integrated with a variety of sensors
and devices.
Customization
ThingSpeak is highly customizable and can be tailored to meet the specific
needs of different IoT projects. Users can create custom visualizations, set
up alerts and notifications, and integrate with third-party services.
Collaboration: ThingSpeak allows users to collaborate on IoT projects by
sharing data and visualizations with other users. It also includes tools for
managing user access and permissions.
Advantages
• Open-source: ThingSpeak is built on an open-source framework, which
means that users can modify and customize the platform to meet their
specific needs.
• Easy to use: ThingSpeak provides a user-friendly interface that makes it
easy for users to set up and manage IoT projects.
• Cost-effective: ThingSpeak is a cost-effective solution for IoT projects, as
it is available as a free or low-cost subscription.
• Integration: ThingSpeak can be integrated with a wide range of sensors and
devices, making it a versatile platform for IoT projects.
• Collaboration: ThingSpeak includes tools for collaboration, which makes
it easier for users to work together on IoT projects.
19
Features
• Data collection: ThingSpeak allows users to collect data from a variety of
sensors and devices in real-time. The platform supports a wide range of
protocols, including HTTP, MQTT, and HTTPS.
• Data visualization: ThingSpeak provides a range of tools for visualizing
data, including customizable charts and graphs, real-time maps, and data
analytics tools. Users can create custom dashboards to display data in a
way that is easy to understand.
• Data analysis: ThingSpeak includes a range of data analytics tools,
including MATLAB analytics, which allows users to perform advanced
analytics on their data.
6.2 Blynk
Blynk have been used to collect all the data. Firstly, the user need to sign up
to make an account. Next, Blynk will send the Auth Token to the email that
have been register. After the Auth Token have been send, the user can use the
application and can make their own data such as graph, display value, button,
table and others. The Figure 10 below shows the Blynk Application interface.
To control the IoT base project outputs.
20
CHAPTER 7
WORKING AND RESULT
7.1 WORKING
The working diagram for smart farming using IoT with NodeMCU
and ThingSpeak explains how the system operates to monitor and
control various environmental parameters in a farm.
Sensor Data Collection: The sensors in the system collect data on
various environmental parameters such as temperature, humidity,
soil moisture levels, etc.
Data Processing: The NodeMCU receives the data from the sensors
and processes it before sending it to ThingSpeak. The data is
converted into a format that can be transmitted over Wi-Fi and sent
to ThingSpeak.
Data Transmission: The NodeMCU sends the processed data to
ThingSpeak over Wi-Fi using the internet. The Wi-Fi module in the
NodeMCU connects to the Wi-Fi network, and the data is
transmitted to the ThingSpeak cloud server.
Data Storage: The ThingSpeak cloud server receives the data
transmitted by the NodeMCU and stores it in its cloud storage. The
data is stored in a format that can be easily accessed and analyzed
by farmers.
Data Visualization: The data collected by the system is visualized
using charts and graphs, making it easier for farmers to interpret and
analyze the data. The data visualization can be accessed through the
ThingSpeak user interface.
21
7.2 RESULT
22
DEMO MODULE
23
CHAPTER 8
CONCLUSION AND FUTURE WORK
8.1 CONCLUSION
In conclusion, our project "Smart Farming Using IOT with NodeMCU and
ThingSpeak" has been a success in achieving its objectives of improving
farming operations using IoT technology. Through our project, we have
demonstrated how the use of sensors and machine learning algorithms can
provide valuable insights into crop growth, enabling farmers to optimize their
farming operations.
The machine learning algorithms used in our project analyzed the data
collected from the sensors and provided insights into the optimal conditions
for crop growth. This data could be accessed remotely through a mobile
application, which would provide farmers with real-time updates on their
crops, enabling them to take action if necessary.
25
Blockchain technology: The use of blockchain technology in
agriculture can provide greater transparency and traceability in the
supply chain. By using smart farming systems to collect data on crop
production and supply chain logistics, blockchain can be used to
verify the authenticity and quality of agricultural products.
Integration with other technologies: Smart farming using IoT can
be integrated with other emerging technologies such as robotics,
drones, and precision agriculture. These technologies can work
together to provide a more comprehensive view of the farm
environment and optimize farming practices.
In conclusion, smart farming using IoT has a bright future with
numerous possibilities for further development and innovation. As
the technology continues to evolve, it has the potential to transform
the agriculture industry by improving efficiency, reducing waste,
and optimizing resource usage. The future of smart farming using
IoT is exciting, and there is much to look forward to in the years
ahead.
26
CHAPTER 9
REFERENCES
1. Kumar, Pardeep, et al. "A review of wireless communication using
IoT in precision agriculture." In 2017 International Conference on
Advances in Computing, Communications and Informatics
(ICACCI), pp. 1214-1218. IEEE, 2017.
27
7. J. M. Aznar, J. M. Pérez-Solano. "Smart agriculture monitoring by
using internet of things." In 2015 International Conference on
Intelligent Networking and Collaborative Systems (INCoS), pp.
123-130. IEEE, 2015.
28
CHAPTER – 10
ANNEXURE
PROGRAM 1 (Motor & Nodmcu 4)
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "EDyNsFE_bIGJzVmTKCOgqfj8tk6VDYkx"; //You will get
this Auth Token in Gmail if you signin Blynk app with your Gmail ID
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXXX"; //Enter your WIFI Name
char pass[] = "XXXXXXXXXX";//Enter your WIFI Password
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(D5,OUTPUT);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
digitalWrite(D5,HIGH);
digitalWrite(D1,HIGH);
digitalWrite(D2,HIGH);
digitalWrite(D3,HIGH);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
29
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}
void loop()
{
Blynk.run();
}
30
Program 2 (Soil Moisture )
#include <Adafruit_ADS1X15.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
WiFiClient client;
String thingSpeakAddress= "http://api.thingspeak.com/update?";
String writeAPIKey;
String tsfield1Name;
String request_string;
HTTPClient http;
Adafruit_ADS1115 ads;
void setup()
{
Serial.begin(115200);
delay(3000);
WiFi.disconnect();
Serial.println("START");
WiFi.begin("DIVIYA","123456789"); // Wifi ("ID","Password")
while ((!(WiFi.status() == WL_CONNECTED))){
delay(300);
Serial.println("...");
}
Serial.println("I AM CONNECTED");
Serial.println("Hello!");
Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015,
0.1875mV/ADS1115)");
ads.begin();
}
31
void loop()
{
int16_t adc0, adc1, adc2, adc3;
Serial.println(" ");
adc0 = ads.readADC_SingleEnded(0);
adc0 = adc0 / 25;
adc1 = ads.readADC_SingleEnded(1);
adc1 = adc1 / 25;
adc2 = ads.readADC_SingleEnded(2);
adc2 = adc2 / 25;
adc3 = ads.readADC_SingleEnded(3);
adc3 = adc3 / 25;
Serial.print("SOIL MOISTURE in persent 1% : "); Serial.println(adc0);
Serial.print("SOIL MOISTURE in persent 2% : "); Serial.println(adc1);
Serial.print("SOIL MOISTURE in persent 3% : "); Serial.println(adc2);
Serial.print("SOIL MOISTURE in persent 4% : "); Serial.println(adc3);
Serial.println(" ");
http.GET();
http.end();
}
delay(10);
if (client.connect("api.thingspeak.com",80))
{
request_string = thingSpeakAddress;
request_string += "key=";
request_string += "BOYR02FIDI281SYE";
request_string += "&";
request_string += "field3";
request_string += "=";
32
request_string += adc2;
http.begin(request_string);
http.GET();
http.end();
}
delay(10);
if (client.connect("api.thingspeak.com",80))
{
request_string = thingSpeakAddress;
request_string += "key=";
request_string += "BOYR02FIDI281SYE";
request_string += "&";
request_string += "field4";
request_string += "=";
request_string += adc3;
http.begin(request_string);
http.GET();
http.end();
}
delay(10);
}
33
Program 3 (DH11)
#include <ESP8266WiFi.h>
#include <Adafruit_Sensor.h>
#include <ESP8266HTTPClient.h>
String thingSpeakAddress= "http://api.thingspeak.com/update?";
String writeAPIKey;
String tsfield1Name;
String request_string,request_string1;
HTTPClient http;
#include <DHT.h> // Including library for dht
// library
// https://github.com/adafruit/DHT-sensor-library
#include <ESP8266WiFi.h>
String apiKey = "BOYR02FIDI281SYE"; // Enter your Write API key
from ThingSpeak
const char *ssid = "DIVIYA"; // replace with your wifi ssid and wpa2 key
const char *pass = "123456789"; // WIFI Password
const char* server = "api.thingspeak.com";
#define DHTPIN 0 //pin D3 where the dht11 is connected
DHT dht(DHTPIN, DHT11);
WiFiClient client;
void setup()
{ dht.begin();
Serial.begin(115200);
delay(3000);
WiFi.disconnect();
Serial.println("START");
WiFi.begin("DIVIYA","123456789");
34
while ((!(WiFi.status() == WL_CONNECTED))){
delay(300);
Serial.println("...");
}
Serial.println("I AM CONNECTED");
}
void loop()
{
if (client.connect("api.thingspeak.com",80))
{
request_string = thingSpeakAddress;
request_string += "key=";
request_string += "BOYR02FIDI281SYE";
request_string += "&";
request_string += "field5";
request_string += "=";
request_string += analogRead(A0);
http.begin(request_string);
http.GET();
http.end();
}
delay(10);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
35
if (client.connect(server,80)) // "184.106.153.149" or
api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field6=";
postStr += String(h);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-
urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.print(" Soil Sensor ");
Serial.print(A0);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
36
// thingspeak needs minimum 15 sec delay between updates
delay(10);
}
void loop() {
// Read temperature and pressure from the BMP180 sensor
float temperature = bmp.readTemperature();
float pressure = bmp.readPressure() / 100.0F; // Convert Pa to hPa
// Print the values on the serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
// Send data to ThingSpeak
ThingSpeak.setField(1, temperature);
ThingSpeak.setField(2, pressure);
int response = ThingSpeak.writeFields(1, apiKey.c_str());
37
Prgroam 4 (BMP180)
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>
// WiFi credentials
const char* ssid = "DIVIYA";
const char* password = "123456789";
// ThingSpeak credentials
const char* server = "api.thingspeak.com";
const String apiKey = "8UBDLK6RNR2EUBXD";
// Create an instance of the BMP180 sensor
Adafruit_BMP085 bmp;
// Initialize WiFi client
WiFiClient client;
void setup() {
// Start the serial communication
Serial.begin(9600);
// Connect to WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
// Initialize ThingSpeak
ThingSpeak.begin(client);
// Initialize the BMP180 sensor
if (!bmp.begin()) {
38
Serial.println("Could not find a valid BMP180 sensor, check wiring!");
while (1) {}
}
}
void loop() {
// Read temperature and pressure from the BMP180 sensor
float temperature = bmp.readTemperature();
float pressure = bmp.readPressure() / 100.0F; // Convert Pa to hPa
// Print the values on the serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
// Send data to ThingSpeak
ThingSpeak.setField(1, temperature);
ThingSpeak.setField(2, pressure);
int response = ThingSpeak.writeFields(1, apiKey.c_str());
// Check for successful upload to ThingSpeak
if (response == 200) {
Serial.println("Data sent to ThingSpeak successfully!");
} else {
Serial.println("Error sending data to ThingSpeak!");
}
// Wait for 15 seconds before sending the next set of data
delay(15000);
}
39