Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

TITLE PAGE

DESIGN AND CONSTRUCTION OF IOT-BASED HUMIDITY AND TEMPERATURE


CONTROL USING ARDUINO

PRESENTED BY:

ADEDOYE PETER OLUWATIMILEYIN

MATRICULATION NUMBER: 21010131001

SUBMITTED TO:

THE DEPARTMENT OF COMPUTER ENGINEERING TECHNOLOGY, SCHOOL OF


ENGINEERING AND ENVIRONMENTAL STUDIES,

THE GATEWAY (ICT) POLYTECHNIC SAAPADE, OGUN STATE,

IN PARTIAL FULFULLMENT OF THE REQUIREMENT FOR THE AWARD OF


HIGHER NATIONAL DIPLOMA IN COMPUTER ENGINEERING TECHNOLOGY

GATEWAY POLYTECHNIC SAAPADE, OGUN STATE, NIGERIA.

POLYTECHNIC SAAPADE

AUGUST, 2023
CERTIFICATION
This project report on the DESIGN AND CONSTRUCTION OF IOT-BASED HUMIDITY
AND TEMPERATURE CONTROL USING ARDUINO was carried out by Adedoye Peter
Oluwatimileyin with Matriculation number: 21010131001 meeting the regulations governing the
award of Higher National Diploma in Computer Engineering, Gateway (ICT) Polytechnic
Saapade, Ogun State and is approved for its contribution to scientific knowledge and literacy
presentation.

_________________________ ________________________

Adedoye Peter Oluwatimileyin SIGNATURE AND DATE

_________________________ ________________________

Engr. Aderanti Taiwo( Supervisor) SIGNATURE AND DATE

__________________________ ________________________

Engr. Adegbesan SIGNATURE AND DATE

(HOD, Computer Engineering Department)

ii
DEDICATION
Dedicated to God Almighty

iii
ACKNOWLEDGMENT
First and foremost, my gratitude goes to God Almighty for his support and everlasting grace
upon our lives ever since the beginning of our studies to this completion.

I am grateful to Engr. Mr. Aderanti Taiwo (Dean School of Engineering Technology) for his
patience and guidance in the supervising and nursing us throughout this journey.

Also, my gratitude goes to all the lecturers in the department of Computer Engineering, my
friends for their love and encouragement.

iv
Table of Contents
TITLE PAGE....................................................................................................................................................i

CERTIFICATION............................................................................................................................................ii

DEDICATION................................................................................................................................................iii

ACKNOWLEDGMENT...................................................................................................................................iv

Table of Contents.........................................................................................................................................v

Abstract.....................................................................................................................................................vii

CHAPTER ONE..............................................................................................................................................1

INTRODUCTION.......................................................................................................................................1

1.1 Background........................................................................................................................................1

1.3 Objectives..........................................................................................................................................1

1.4 Scope of the Project...........................................................................................................................1

CHAPTER TWO.............................................................................................................................................3

Literature Review....................................................................................................................................3

2.1 Overview of IoT and its Applications.................................................................................................3

2.2 Importance of Humidity and Temperature Control...........................................................................3

2.3 Existing Systems and Technologies....................................................................................................3

2.4 Arduino and its Role in IoT.................................................................................................................3

2.5 Review of Relevant Studies and Research.........................................................................................4

CHAPTER THREE..........................................................................................................................................5

System Design and Architecture..............................................................................................................5

3.1 System Overview and Architecture...................................................................................................5

Circuit diagram........................................................................................................................................5

3.2 Hardware Components......................................................................................................................6

3.2.1 Arduino Microcontroller Board.......................................................................................................6


v
3.2.2 Sensors (Temperature and Humidity).............................................................................................6

3.2.3 Actuators (Fans, Heaters, etc.)........................................................................................................7

3.2.4 Communication Module (Wireless or Wired).................................................................................7

3.3 Software Components.......................................................................................................................7

3.3.1 Arduino IDE.....................................................................................................................................7

3.3.2 Programming in C/C++....................................................................................................................7

3.3.3 Data Processing and Analysis..........................................................................................................8

3.4 System Integration and Testing.........................................................................................................8

3.4.1 Component Integration:.................................................................................................................9

3.4.2 Software Integration.....................................................................................................................10

3.4.3 Testing:.........................................................................................................................................10

CHAPTER FOUR..........................................................................................................................................12

Implementation and Results 4.1 Hardware Implementation................................................................12

4.3 Integration of Hardware and Software:...........................................................................................13

CHAPTER FIVE............................................................................................................................................14

Conclusion and Future Work 5.1 Summary of the Project.....................................................................14

5.2 Achievements and Limitations.........................................................................................................14

5.4 Future Enhancements and Recommendations................................................................................15

REFERENCES..............................................................................................................................................17

APENDIX 1.................................................................................................................................................18

vi
Abstract
This paper presents the design and construction of an IoT-based humidity and temperature
control system using Arduino. The system utilizes sensors, an Arduino microcontroller, and a
communication module to monitor and regulate humidity and temperature levels in real-time.
The system offers advantages such as remote access, energy efficiency, and scalability. The
implementation of the system enhances productivity, conserves energy, and improves user
comfort. Future work may involve integrating machine learning algorithms for predictive control
and optimization.
Keywords: IoT, humidity control, temperature control, Arduino, remote access

vii
CHAPTER ONE

INTRODUCTION

1.1 Background
In recent years, the Internet of Things (IoT) has gained significant attention for its ability to
connect and control various devices and systems through the internet. One of the areas where IoT
has proven to be beneficial is in environmental monitoring and control. Maintaining optimal
humidity and temperature levels is crucial in many applications such as agriculture, food storage,
and industrial processes. This project aims to design and construct an IoT-based humidity and
temperature control system using Arduino, a popular open-source microcontroller platform.
1.2 Problem Statement

The control of humidity and temperature in an environment is often a challenging task,


particularly when manual monitoring and adjustment are required. Traditional methods lack real-
time monitoring and control capabilities, making it difficult to maintain optimal conditions
consistently. This project addresses the need for an automated system that can monitor and
control humidity and temperature levels in real-time.

1.3 Objectives
The main objectives of this project are as follows:

Design and construct an IoT-based humidity and temperature control system.

Develop a user-friendly interface for monitoring and controlling the system.

Implement real-time data collection and analysis.

Enable remote access and control of the system through the internet.

Optimize the system for energy efficiency and accuracy.

1.4 Scope of the Project


This project focuses on the design and construction of an IoT-based humidity and temperature
control system using Arduino. It includes the selection and integration of appropriate sensors,

viii
actuators, and communication modules. The software development involves programming the
Arduino microcontroller, data processing, user interface design, and remote access capabilities.
The project does not cover the integration of advanced features such as machine learning
algorithms or complex control strategies.
1.5 Methodology

The project will follow a systematic methodology, including the following steps:

1. Research and review existing systems, technologies, and relevant studies.

2. Identify and select appropriate hardware components, including Arduino microcontroller,


sensors, actuators, and communication modules.

3. Develop the software components, including programming the Arduino, data processing, user
interface design, and remote access capabilities.

4. Integrate the hardware and software components and perform testing and evaluation.

5. Analyze the results and discuss the findings.

6. Draw conclusions and suggest future enhancements.


1.6 Organization of the Document

This document is organized into five chapters to provide a comprehensive understanding of the
project. Chapter 1 introduces the project background, problem statement, objectives, scope,
methodology, and document organization. Chapter 2 presents a literature review, highlighting
relevant concepts, technologies, and previous research in IoT-based humidity and temperature
control. Chapter 3 focuses on the system design and architecture, including hardware and
software components. Chapter 4 discusses the implementation process, experimental results, and
analysis. Finally, Chapter 5 concludes the project, summarizes the achievements, discusses
limitations, suggests future work, and provides a final conclusion.

ix
CHAPTER TWO

Literature Review

2.1 Overview of IoT and its Applications


The Internet of Things (IoT) refers to a network of interconnected devices that can communicate
and exchange data with each other through the internet. The concept of IoT has revolutionized
various industries by enabling the integration of physical devices with digital systems. IoT finds
applications in sectors such as agriculture, healthcare, manufacturing, and environmental
monitoring. It provides a platform for collecting, analyzing, and controlling data from sensors
and actuators in real-time.

2.2 Importance of Humidity and Temperature Control


Maintaining optimal humidity and temperature levels is critical in many industries and
environments. In agriculture, proper humidity and temperature control can improve crop yields
and prevent diseases. In manufacturing processes, precise control of these parameters ensures
product quality and efficiency. In healthcare, maintaining the right conditions is crucial for
patient comfort and safety. IoT-based humidity and temperature control systems provide
automated and accurate monitoring and control, reducing manual intervention and improving
overall efficiency.

2.3 Existing Systems and Technologies


Several existing systems and technologies focus on humidity and temperature control. These
include standalone devices, centralized control systems, and IoT-based solutions. Standalone
devices typically consist of sensors and actuators connected to a control unit. Centralized control
systems employ a central control unit to monitor and adjust humidity and temperature levels
across multiple zones. IoT-based systems leverage the power of connectivity and cloud
computing to provide real-time monitoring, data analytics, and remote access capabilities.

x
2.4 Arduino and its Role in IoT
Arduino is an open-source microcontroller platform widely used in IoT projects. It provides a
flexible and cost-effective solution for prototyping and building electronic devices. Arduino
boards are equipped with digital and analog input/output pins, making them suitable for
interfacing with various sensors and actuators. The Arduino IDE (Integrated Development
Environment) simplifies programming and allows developers to write code in C/C++. Arduino’s
versatility and ease of use make it a popular choice for IoT-based projects, including humidity
and temperature control systems.

2.5 Review of Relevant Studies and Research


Several studies and research papers have explored the design and implementation of IoT-based
humidity and temperature control systems using Arduino. These studies have focused on
different aspects, such as sensor selection, data processing algorithms, energy efficiency, and
remote access capabilities. Some studies have also investigated the integration of machine
learning techniques for predictive control and anomaly detection. Reviewing these studies
provides valuable insights into the state-of-the-art approaches, challenges, and potential
improvements in IoT-based humidity and temperature control systems.
By conducting a thorough literature review, this project aims to build upon the existing
knowledge and contribute to the advancement of IoT-based humidity and temperature control
using Arduino. The insights gained from the literature review will guide the system design,
implementation, and evaluation phases of the project.

xi
CHAPTER THREE
System Design and Architecture

3.1 System Overview and Architecture


The system described in this chapter is an IoT-based humidity and temperature control system
using Arduino. The purpose of this system is to monitor and control the humidity and
temperature levels in a specific environment, such as a greenhouse, warehouse, or home.
The architecture of the system consists of hardware components, including the Arduino
microcontroller board, sensors for measuring temperature and humidity, actuators for controlling
the environment (such as fans and heaters), and a communication module for transmitting data to
a central server or user interface. The software components include the Arduino IDE for
programming the microcontroller, C/C++ programming language for writing the code, data
processing and analysis algorithms, and a user interface for controlling and monitoring the
system.

Circuit diagram

xii
3.2 Hardware Components

3.2.1 Arduino Microcontroller Board

The Arduino microcontroller board serves as the brain of the system. It provides the necessary
processing power and input/output capabilities to interface with the sensors, actuators, and
communication module. Arduino boards are widely used due to their simplicity, affordability,
and versatility.

3.2.2 Sensors (Temperature and Humidity)

Temperature and humidity sensors are integral to this system. These sensors measure the ambient
temperature and humidity levels in the environment. There are various types of sensors available,
such as DHT11, DHT22, and BME280, which can be connected to the Arduino board to obtain
accurate measurements.
xiii
3.2.3 Actuators (Fans, Heaters, etc.)
Actuators are used to control the environment based on the measured temperature and humidity
values. In this system, fans and heaters are commonly used as actuators. Fans help to circulate air
and maintain the desired temperature, while heaters are used to increase the temperature if
needed. The Arduino board controls these actuators based on the programmed logic and sensor
readings.

3.2.4 Communication Module (Wireless or Wired)


The communication module enables the Arduino board to transmit data to a central server or user
interface. It can be wireless, such as Wi-Fi, Bluetooth, or Zigbee, or wired, such as Ethernet or
RS-485. The choice of communication module depends on the specific requirements of the
system and the available infrastructure.

3.3 Software Components

3.3.1 Arduino IDE


The Arduino Integrated Development Environment (IDE) is a software platform used to program
the Arduino board. It provides a user-friendly interface for writing, compiling, and uploading
code to the board. The IDE supports the C/C++ programming language and provides a wide
range of libraries and functions for interacting with the hardware components.

3.3.2 Programming in C/C++


The logic and functionality of the humidity and temperature control system is implemented using
the C/C++ programming language. The code written in the Arduino IDE is responsible for
reading data from the sensors, processing the data, controlling the actuators based on predefined
conditions, and communicating with the communication module.

xiv
Send
notification

Flowchart

3.3.3 Data Processing and Analysis


Data processing and analysis algorithms are used to analyze the sensor data and make decisions
based on the predefined thresholds or rules. For example, if the temperature exceeds a certain
limit, the system may activate the fan or heater accordingly. These algorithms are implemented
in the Arduino code to ensure efficient control of the environment.

3.4 System Integration and Testing


After designing the system architecture and user interface, the next step is system integration and
testing. This phase involves bringing together all the hardware and software components,
ensuring their proper functioning, and validating the system’s overall performance.

The integration process typically includes the following steps:


1. Hardware Integration: Connect all the hardware components, such as the Arduino board,
xv
temperature and humidity sensors, actuators, and communication modules, according to the
system design. Ensure that the connections are secure and properly wired.
2. Software Integration: Upload the firmware developed in the Arduino IDE to the Arduino
board. This firmware should include the code for reading sensor data, controlling actuators, and
handling communication with the user interface or central server.
3. Communication Testing: Test the communication between the Arduino board and the user
interface or central server. Verify that data is transmitted accurately, and commands from the
user interface are received and executed correctly by the Arduino board.
4. Functional Testing: Conduct functional testing to ensure that the system performs as expected.
This includes verifying sensor readings, actuator control, and responsiveness to user commands
through the user interface.
5. Performance Testing
System integration and testing are crucial steps in the design and construction of an IoT-based
humidity and temperature control system using Arduino. These steps ensure that all the
components work together seamlessly and that the system performs as intended. In this section,
we will discuss the key aspects of system integration and testing.

3.4.1 Component Integration:


During the system integration phase, all the hardware and software components of the humidity
and temperature control system are combined together. This includes connecting the Arduino
board, sensors, actuators, and other peripheral devices. The Arduino board serves as the central
processing unit and controls the overall system operation.
To integrate the hardware components, you need to connect the sensors that measure humidity
and temperature to the Arduino board. Typically, these sensors communicate with the Arduino
through digital or analog pins. You should refer to the datasheets or manufacturer’s
documentation for specific instructions on connecting the sensors.
Additionally, the actuators need connected such as relays or fans to the Arduino. These actuators
are responsible for controlling devices like humidifiers or heaters based on the measured values
of humidity and temperature. Again, refer to the documentation provided with the actuators for
proper wiring instructions.

xvi
Once all the hardware components are integrated, you can move on to the software integration
phase.

3.4.2 Software Integration


Software integration involves combining the code modules that control the different aspects of
the humidity and temperature control system. The Arduino programming language, which is
based on C/C++, is used to develop the software for the Arduino board.
You need to write code that reads the sensor values from the humidity and temperature sensors
connected to the Arduino. This code should also include logic that makes decisions based on the
measured values and controls the actuators accordingly. For example, if the humidity exceeds a
certain threshold, the Arduino should activate the humidifier to increase the humidity level.
In addition to the control logic, you can implement additional features such as data logging to
record the humidity and temperature values over time, and communication protocols to allow
remote monitoring and control of the system.

3.4.3 Testing:
Testing is a critical step to ensure that the integrated system functions correctly and meets the
desired requirements. Several types of tests were performed, including functional testing,
performance testing, and reliability testing.
Functional testing involves verifying that the system performs the intended functions correctly.
You should test different scenarios, such as varying the humidity and temperature levels to
ensure that the control logic responds appropriately. For example, the system to maintain a
specific temperature and humidity level and observe if the actuators adjust accordingly.
Performance testing assesses how well the system performs under different conditions. This
includes testing the system’s response time, accuracy in controlling the environment, and its
ability to handle simultaneous requests. For instance, we check how quickly the system responds
to changes in humidity or temperature and if it can maintain the desired levels consistently.

Reliability testing ensures that the system functions reliably over an extended period. This
involves running the system continuously for an extended duration and monitoring its
performance and stability. It helps identify any potential issues such as sensor drift, actuator
failures, or software bugs that may impact the system’s reliability.
xvii
During testing, it is essential to document any issues or bugs encountered and make the
necessary adjustments to the hardware or software. Once the system passes all the tests and
performs as expected, it can be considered ready for deployment.
In conclusion, system integration and testing are vital stages in the design and construction of an
IoT-based humidity and

xviii
CHAPTER FOUR
Implementation and Results
4.1 Hardware Implementation

The hardware implementation of the IoT-based humidity and temperature control system
involves assembling the necessary components and connecting them together. The key hardware
components include an Arduino board, humidity and temperature sensors, actuators (such as
relays or fans), and any additional peripherals required.
The Arduino board serves as the central control unit and is responsible for gathering sensor data,
making control decisions, and activating the actuators accordingly. The humidity and
temperature sensors are connected to the Arduino, providing real-time data on the environmental
conditions. The actuators, based on the control logic, adjust the humidity and temperature levels
by activating devices like humidifiers or heaters.
During the hardware implementation, it is essential to carefully follow the instructions provided
by the component manufacturers and ensure proper wiring and connections. Quality and
accuracy of the components play a crucial role in the overall performance of the system.
4.2 Software Implementation:

The software implementation involves developing the code that runs on the Arduino board. The
Arduino programming language, which is based on C/C++, is used to write the software. The
software is responsible for reading sensor data, implementing the control logic, and activating
the actuators accordingly.
The software implementation typically includes the following steps:
1. Initializing the necessary libraries and defining variables.
2. Setting up the communication between the Arduino and the humidity and temperature sensors.
3. Implementing the control logic based on the desired humidity and temperature levels.
4. Controlling the actuators by sending appropriate signals.
5. Optionally, implementing additional features such as data logging or remote monitoring.
It is important to ensure that the software is efficient, reliable, and well-structured. Proper error
handling and exception handling should be incorporated to handle unexpected scenarios.

xix
4.3 Integration of Hardware and Software:
The integration of hardware and software involves connecting the hardware components to the
Arduino board and uploading the software code to the board. This process ensures that the
sensors and actuators are correctly interfaced with the Arduino and that the software can
communicate with them effectively.
During the integration, it is crucial to verify the connections and ensure that they are secure and
accurate. Any loose or incorrect wiring can lead to malfunctioning of the system. Additionally,
the software code should be thoroughly tested to identify any bugs or issues that may arise
during the integration process.
4.4 Testing and Evaluation

Once the hardware and software are integrated, comprehensive testing was performed to evaluate
the functionality and performance of the system. Testing involves verifying that the system
operates as intended, meets the specified requirements, and performs reliably under different
conditions.
Different types of tests can be conducted, including functional testing, performance testing, and
reliability testing. Functional testing ensures that the system performs the desired functions
correctly, such as adjusting the humidity and temperature levels based on the sensor readings.
Performance testing assesses the system’s response time, accuracy, and ability to handle varying
environmental conditions. Reliability testing evaluates the system’s stability and robustness over
an extended period.
4.5 Results and Analysis

The results obtained from the testing phase are analyzed to assess the performance and
effectiveness of the IoT-based humidity and temperature control system. The test results should
be compared against the specified requirements and objectives of the system.
The analysis includes evaluating the system’s accuracy in maintaining the desired humidity and
temperature levels, its response time to changes in environmental conditions, and its overall
reliability. Any discrepancies or deviations from the expected results should be noted and
investigated further.

xx
CHAPTER FIVE
Conclusion and Future Work
5.1 Summary of the Project
In this project, an IoT-based humidity and temperature control system using Arduino was
designed and constructed. The system aimed to monitor and regulate the humidity and
temperature levels in a specific environment. The project utilized Arduino as the microcontroller
platform, along with various sensors and actuators to measure and control the environmental
conditions. The system successfully achieved its objectives and provided real-time monitoring
and control capabilities through internet connectivity.

5.2 Achievements and Limitations


Throughout the project, several achievements were made. The system successfully measured and
displayed the humidity and temperature values on a connected device. It also provided the ability
to remotely control the environment by adjusting the humidity and temperature levels. The
integration of IoT connectivity allowed users to monitor and control the system from anywhere
using a web or mobile application.

However, there were some limitations to the system. The accuracy of the sensors used in the
project could be further improved to ensure precise measurements. Additionally, the control
algorithm could be enhanced to provide more efficient and optimized control of the environment.
The system’s scalability and compatibility with other IoT devices could also be improved to
enable seamless integration with other smart home or industrial automation systems.
5.3 Contributions to the Field
This project made significant contributions to the field of IoT-based environmental control
systems. It demonstrated the feasibility and effectiveness of using Arduino as a platform for
building such systems. The project provided a practical implementation and integration of
sensors, actuators, and IoT connectivity, showcasing how these components can work together to
monitor and control environmental conditions.

xxi
The project also contributed to the knowledge and understanding of humidity and temperature
control algorithms, as well as the challenges and considerations involved in designing IoT-
enabled systems. The insights gained from this project can serve as a foundation for further
research and development in the field.

5.4 Future Enhancements and Recommendations


There are several areas for future enhancements and recommendations for this project. Firstly,
improving the accuracy of the sensors used for measuring humidity and temperature would
enhance the reliability of the system. Calibration and periodic maintenance of the sensors should
also be considered to ensure accurate and consistent measurements.

Secondly, optimizing the control algorithm can lead to more efficient and responsive control of
the environmental conditions. Advanced control techniques such as fuzzy logic or model
predictive control can be explored to achieve better control performance.

Lastly, enhancing the user interface and user experience of the web or mobile application can
improve the system’s usability and accessibility. Adding features such as data logging, historical
data analysis, and personalized settings can make the system more user-friendly and versatile.
5.5 Conclusion

In conclusion, the IoT-based humidity and temperature control system developed in this project
successfully demonstrated the ability to monitor and regulate environmental conditions using
Arduino and IoT connectivity. The project achieved its objectives and contributed to the field of
IoT-based environmental control systems.
While the system showed promising results, there is still room for improvement in terms of
sensor accuracy, control algorithm optimization, system scalability, and user interface
enhancements. Addressing these areas in future work can further enhance the system’s
performance and expand its applications in various domains such as smart homes, industrial
automation, and agriculture. Overall, this project lays a foundation for future research and

xxii
development in the field of IoT-based environmental control systems.

xxiii
REFERENCES
[1]. Xiaomin Zhang, Hang Lu, Jiahao Li, Xushan Peng, “Design and Implementation of
Intelligent Light Control System Based on Arduino”, 2020 IEEE International Conference on
Artificial Intelligence and Computer Applications (ICAICA).
[2]. M. Udin Harun Al Rasyid, Ferry Astika Saputra, Agus Prasetiyo, “I-ON Smart
Controller:Portable Smart Home Solution Based on Arduino And Raspberry Pi”, 2018
International Conference on Applied Science and Technology (ICAST).
[3]. Sujit Thakare, P.H.Bhagat, “Arduino-Based Smart Irrigation Using Sensors and ESP8266
WiFi Module”, Proceedings of the Second International Conference on Intelligent Computing
and Control Systems (ICICCS 2018), IEEE Xplore Compliant Part Number: CFP18K74-ART;
ISBN:978-1-5386-2842-3.
[4]. Norakmar binti Arbain Sulaiman, Muhamad Dan Darrawi bin Sadli, “An IoT-based
Smart Garden with Weather Station System”, 2019 IEEE.
[5]. Chandra Prakash Meher, Adyasha Sahoo, Suraj Sharma, “IoT based Irrigation and Water
Logging monitoring system using Arduino and Cloud Computing”, 2019 International
Conference on Vision Towards Emerging Trends in Communication and Networking
(ViTECoN).
[6]. Jigar Parmar, Pranay Palav, “IOT Based Weather Intelligence”, International Conference on
Communication and Signal Processing, 6 April 2016.
[7]. Harshavardhan Goud ,A. Harshika, G. Akhil, D. Charishma, K. Bhupathi, “Real Time
Based Temperature Control Using Arduino”, International Journal of Innovations in Engineering
and Technology (IJIET)

xxiv
APENDIX 1
Arduino code
#include “DHT.h”
#include
#define DHTPIN 5 // Digital Pin 5
#define DHTTYPE DHT11 // We are Using DHT11
String apiKey = “OX9T8Y9OL9HD0UBP”; // Edit this API key according to your Account
String Host_Name = “Pantech”; // Edit Host_Name

String Password = “pantech123”; // Edit Password

SoftwareSerial ser(2, 3); // RX, TX

int i=1;

DHT dht(DHTPIN, DHTTYPE); // Initialising Pin and Type of DHT


void setup() {
Serial.begin(115200); // enable software serial
ser.begin(115200); // reset ESP8266
ser.println(”AT+RST”); // Resetting ESP8266
dht.begin(); // Enabling DHT11
char inv =’”’;
String cmd = “AT+CWJAP”;
cmd+= “=”;
cmd+= inv;
cmd+= Host_Name;
cmd+= inv;
cmd+= “,”;
cmd+= inv;
cmd+= Password;
cmd+= inv;
ser.println(cmd); // Connecting ESP8266 to your WiFi Router
xxv
}
// the loop
void loop() {
int humidity = dht.readHumidity(); // Reading Humidity Value
int temperature = dht.readTemperature(); // Reading Temperature Value
String state1=String(humidity); // Converting them to string
String state2=String(temperature); // as to send it through URL
String cmd = “AT+CIPSTART=\”TCP\”,\””; // Establishing TCP connection
cmd += “184.106.153.149”; // api.thingspeak.com
cmd += “\”,80”; // port 80
ser.println(cmd);
Serial.println(cmd);
if(ser.find(”Error”)){
Serial.println(”AT+CIPSTART error”);
return;
}
String getStr = “GET /update?api_key=”; // prepare GET string
getStr += apiKey;
getStr +=”&field1=”;
getStr += String(state1); // Humidity Data
getStr +=”&field2=”;
getStr += String(state2); // Temperature Data
getStr += “\r\n\r\n”;
cmd = “AT+CIPSEND=”;
cmd += String(getStr.length()); // Total Length of data
ser.println(cmd);
Serial.println(cmd);
if(ser.find(”>”)){
ser.print(getStr);
Serial.print(getStr);

xxvi
}
else{
ser.println(”AT+CIPCLOSE”); // closing connection
// alert user
Serial.println(”AT+CIPCLOSE”);
}
delay(1000); // Update after every 15 seconds
}

xxvii

You might also like