0% found this document useful (0 votes)
236 views61 pages

IoT Home Automation With HMI

Uploaded by

Cnp1 Cnp1
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)
236 views61 pages

IoT Home Automation With HMI

Uploaded by

Cnp1 Cnp1
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/ 61

IoT Based Home Automation with

HMI
This paper has been submitted to the department of Electrical &
Electronic Engineering of European University of Bangladesh in partial
fulfillment of the requirement for the degree of Bachelor of Science in
Electrical and Electronic Engineering.

SUBMITTED BY:

Name: Nayon Kumar Pal I.D.: 180116456


Name: Md Monir Bepari I.D.: 180116471
Name: Tanmoy Barai I.D.: 170216541
Name: Milon Malakar I.D.: 180116462

SUPERVISED BY:

Asrafun Nushra Oishi


Lecturer
Department of Electrical and Electronic Engineering

EUROPEAN UNIVERSITY OF BANGLADESH


March 2021
Letter of Transmittal

01st March, 2021

To
The Supervisor
Department of EEE
European University of Bangladesh
Mirpur-2, Dhaka-1216.

Subject: Submission of Project/Thesis/Internship report.

Dear Sir,
Please find enclosed the project report entitled IoT Based Home
Automation with HMI. The study has been carried out in partial fulfillment
of the requirements for the degree of Bachelor of Science in Electrical &
Electronic Engineering.

In carrying out the study, I/we have followed supervisor’s advice and
collected required information from several text books, reference books, web
sites and other sources. I/we think you will find it useful and informative.
I/we would be glad to furnish you further explanations or clarifications if
required.
Sincerely yours,
______________
Nayan Kumar Pal
I.D: 180116456

______________
Md Monir Bepari
I.D: 180116471

______________
Tanmoy Barai
I.D: 170216541

______________
Milon Malakae
I.D: 180116462

Declaration
ii
We do hereby solemnly declare that the work presented in this report entitled
IoT Based Home Automation with HMI has been carried out by me/us and
has not been previously submitted to any other university, college or
organization for an academic qualification, certificate or diploma/degree.

I/We hereby warrant that the work that has been presented here does not
breach any existing copyright. I/We further undertake to indemnify the
university against any loss or damage arising from breach of the foregoing
obligations.

Author/s

______________
Nayan Kumar Pal
I.D: 180116456

______________
Md Monir Bepari
I.D: 180116471

______________
Tanmoy Barai
I.D: 170216541

______________
Milon Malakae
I.D: 180116462

EUROPEAN UNIVERSITY OF BANGLADESH


Certificate

iii
This is to certify that the report entitled IoT Based Home Automation with
HMI is the valid record of the work done by _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ for partial fulfillment of the requirement of the degree
of B.Sc. in Electrical and Electronic Engineering (EEE) from European
University of Bangladesh.

This work has been carried out under my guidance and is a bonafide record
of valid works carried out successfully.

Faculty Guide

___________________
Ashrafun Nushara Oishi
Lecturer
Department of Electrical and Electronic Engineering

Acknowledgement

iv
I/We would like to express my/our greatest gratitude to the people who helped and
supported me/us throughout this work. First and foremost I/we would like to thank my/our
honorable supervisor, Ashrafun Nushara Oishi, Lecturer, Department of EEE, for giving
me/us enormous support, advices and valued guidance concerning this thesis.
I/We am/are grateful to A. O. M. Abdul Ahad, honorable Chairman, Department of EEE,
Faculty of Engineering, European University of Bangladesh (EUB) for his comments,
encouragement and support.
I/We am/are grateful to my/our respected coordinator Sourav Barua, Lecturer,
Department of EEE, Faculty of Engineering, European University of Bangladesh (EUB)
for kindly agreeing to examine my thesis.
Next, I/We would like to thank my/our family and friends for their valuable support to
complete this thesis.
Finally, I/we would like to express my/our heartiest gratefulness to Almighty Allah for His
heavenly blessings. Without his blessings it would not possible to complete my/our work
successfully.

Thank you all


Author/s

Executive Summary

v
Home automation needs to make use of modern technologies to reduce human efforts as
well as save energy. This paper focuses on the development of an embedded system for
home automation system that use standard remote controller, temperature, humidity and
touch screen as a user input device. The inconvenience in controlling the home devices has
been solved by this home automation system. In this proposed home automation system
different attractive features are combined together which is not found very often in other
home automation system. This offers a low cost, complete and efficient system for remote
operation of a room. Furthermore, this system can be applied to control all kinds of
appliances automatically installed within buildings, companies, schools, hospitals and so
on.

Table of Contents

Letter of Transmittal II
Declaration III
Certificate IV

vi
Acknowledgement V
Executive Summary VI
List of Figures X
List of Tables XI

Chapter 1 Introduction 1-5

1.1 Introduction 1
1.2 Historical Background 1
1.3 Home Automation 3
1.4 IoT Based Home Automation 4
1.5 Objectives 4
1.6 Literature Review 4
1.7 Project Book Outline 5

Chapter 2 IoT Technology 7-11

2.1 Intoduction 7
2.2 Working Procedure of IoT 7
2.3 Advantages of IoT 8
2.4 Application of IoT 10
2.5 Summary 11

Chapter Hardware and Software 12-23

3
3.1 Introduction 13
3.2 Required Components 13
3.3 Arduino Uno 13
3.3.1 Features 13
3.3.2 Pin Configuration 14
3.4 Esp8266 15
3.4.1 Features 16
3.4.2 Pin Configuration 16
3.5 3.5 Inch Touch Screen Display 17
3.5.1 Features 18
3.5.2 Pin Configuration 19
3.6 4 Channel Relay Module 20
3.6.1 Features 20
3.6.2 Pin Configuration 21
3.7 12V Power Supply 21
3.8 Arduino IDE 22
3.9 Blynk App 23

Chapter 4 System Design 25-27

vii
4.1 Introduction 25
4.2 Block Diagram 25
4.3 Flowchart 26
4.4 Circuit Diagram 27

Chapter Final Result 29-30

5
5.1 Introduction 29
5.2 Result 29
5.3 Project Outlook 29
5.4 Advantages 29
5.7 Cost Analysis 30

Chapter Discussion and Conclusions 32-32

6
6.1 Discussion 32
6.2 Future Work 32
6.3 Conclusions 32

References 33-33

Appendix I 34-38
Appendix II 39-50

viii
LIST OF FIGURES

Figure 1.1 Home Automation 3


Figure 1.2 IoT Based Home Automation 4
Figure 3.1 Arduino UNO 13
Figure 3.2 ESP 8266 15
Figure 2.5 3.5 Inch Display 17
Figure 2.6 4 Channel Relay Module 20
Figure 2.7 12V DC Power Supply 21
Figure 2.8 Arduino IDE 22
Figure 2.9 Blynk App Interface 23
Figure 2.10 Block Diagram 25
Figure 3.1 Flow Chart 26
Figure 3.2 Circuit Diagram 27
Figure 5.1 Project Outlook 29

ix
LIST OF TABLES

Table 3.1 Arduino Uno Features 12


Table 3.2 Arduino Uno Pins 14
Table 3.3 ESP 8266 Pins 17
Table 3.4 Features of 3.5 Inch Display 18
Table 3.5 Pins of 3.5 Inch Display 19
Table 3.6 Pins of 4 Channel Relay Module 21
Table 5.1 Cost Analysis 30

x
Chapter 01

Introduction

1
1.1 Introduction

Nowadays home automation system is being widely used to control devices around the
home. A variety of home devices can be controlled with the help of a home automation
system. All kinds of home appliances like doors, lights, fan, electric heater, surveillance
systems, and consumer electronics belong to the home automation system devices [1].
Home automation system is adopted by using the technology available for the purpose of
controlling the devices as well as the systems used in the home automatically. The system
used for improving the quality of resident’s life is regarded as home automation system.
Actually home automation system is a house or living environment. To support the elderly
and the disabled people; remote and local control are useful to ease human effort [2]. For
making the home automation easy, the control of all the devices should be brought in one
place. To do this several works have been done. But there are some obstacles to be
overcome for making the home automation system easier and popular; these are high cost
of ownership, inflexibility, poor manageability, and difficulty in achieving security [3].In
Java based home automation system, a complex and costly installation and is needed. The
requirement of a high end PC makes the system expensive. In this system, remote control
of the devices is provided through integration with a personal computer (PC) based web
server, in which with all the devices an embedded board is physically connected. For this
individual connection the system becomes intrusive although it provides a safe solution
[4]. In a Bluetooth based home automation system, a primary controller and a number of
Bluetooth sub-controllers are used. The physical connection is needed between the local
Bluetooth and sub-controller. The devices to be controlled make their communication
with sub controller via a wired media. The problem of this system is the time delay,
because of the sharing a single Bluetooth module by many devices to be controlled [5]. In
a phone based remote controller for home and office automation, the system suffers from
the problem of flexibility. Because users have to remember an access code. In a control
network, using hand gestures, the controller uses a glove to relay hand gestures to the
system. The problem of this kind of system is the lack of security. In the 21st century the
use of the remote controller has been increased in a wide range because of the convenience
and easiness of its use. The use of remote controller has been started to most of all the
devices in the home or in the industrial devices. In addition, for home automation such as
lighting and temperature control, door management, and security, remote controllers have
been developed. The convenience of controlling the home devices without remote
controller cannot be imagined. So here in this paper we designed and implemented a
remote controlled home automation system with different features [6]. In this paper, we
present a home automation system which is remote controlled as well as touch screen
controlled. Besides normal load on/off, regulation of the load, control of temperature and
humidity are the major concerns of our work. For saving the energy, automatic load off is
done by sensing the presence of personal. Through this system, we could open and close
the door automatically. Overall, the system is able to overcome the usual four obstacles in
the home automation system.

1.2 Historical Background

Home automation is building mechanization for a home, called a smart home. It includes
the control and computerization of lighting, warming, (for example, brilliant indoor
regulators), ventilation, aerating and cooling (HVAC), and security, and also home
machines, for example, washer/dryers, stoves or fridges/coolers. Wi-Fi is regularly utilized

2
for remote checking and control. Home devices, when remotely observed and controlled
through the Internet, are an essential constituent of the Internet of Things. Smart homes
constitute a branch of ubiquitous computing that involves incorporating smartness into
dwellings for comfort, healthcare, safety, security, and energy conservation. Early home
automation began with labour-saving machines. Self-contained electric or gaspowered
home appliances became viable in the 1900s with the introduction of electric power
distribution [1] and led to the introduction of washing machines (1904), water heaters
(1889), refrigerators, sewing machines, dishwashers, and clothes dryers. In 1975, the main
broadly useful home computerization arrange innovation, X10, was created. X10 is a
communication protocol for electronic devices. It basically utilizes electric power
transmission wiring for flagging and control, where the signs include brief radio
recurrence blasts of advanced information, and remains the most broadly available. [2] By
1978, X10 items incorporated a 16channel charge support, a light module, and an
apparatus module. Not long after came the divider switch module and the primary X10
clock. By 2012, in the United States, as indicated by ABI Research, 1.5 million home
mechanization frameworks were installed. [3] As per Li et al. (2016) there are three
generations of home automation: [4] First generation: remote innovation with intermediary
server, e.g. ZigBee robotization. Second generation: artificial brainpower controls
electrical devices, e.g. Amazon Echo; Third generation: robot buddy who associates with
human, e.g. Robot Rovio, Roomba. Smart homes enhance traditional security and safety
mechanisms by using intelligent monitoring and access control. According to the World
Health Organization (WHO), 650 million people live with disabilities around the world
[5]. It is not possible or logical to support all of these patients in medical centre or nursing
homes for an uncertain period of time. The solution is to accommodate healthcare services
and assistive technologies in patients’ home environment. This paper is a survey on smart
home projects, which are arranged according to their intended services. It also discusses
the significance and limitations of smart home components and the various technologies
used in home automation. It explains the current trends of smart home research and future
challenges that must be overcome to design a feasible smart home.

1.3 Home Automation

Home automation or domotics is building automation for a home, called a smart home or
smart house. A home automation system will monitor and/or control home attributes such
as lighting, climate, entertainment systems, and appliances. It may also include home
security such as access control and alarm systems.

Figure 1: Home Automation

3
1.4 IoT Based Home Automation

The IoT devices in Home Automation have the maximum applications in energy. The
home heating devices are able to control the temperature with the devices like laptops,
tablets or smart phones and all of these appliances, systems, and devices contain sensors
that connect them to a network.

Figure 1.2: IoT Based Home Automation

1.5 Objective

The main objective of this Paper is to design and implement a control and monitor system
for smart house. Smart house system consists of many systems that controlled by Lab
VIEW software as the main controlling system in this paper. Also, the smart house system
was supported by remote control system as a sub controlling system. The system also is
connected to the internet to monitor and control the house equipment’s from anywhere in
the world using Lab VIEW.

1.6 Literature Review

In IoT based home automation with HMI system the home appliances are connected to the
Arduino board at input output ports using relay. The program of Arduino board is based
on high level interactive C language of microcontrollers; the connection is made via Wi-Fi
using Wi-Fi Module. The password protection is provided so only authorized user is
allowed to access the appliances. The Bluetooth connection is established between
Arduino board and phone for wireless communication. One circuit is designed and
implemented for receiving the feedback from the phone, which indicate the status of the
device.

4
1.7 Project Book Outline

This book consists of six chapters.

Chapter 1:
Gives a brief discussion of the project introduction, project objectives, project motivation
and history.

Chapter 2:
Focuses on the technology we used.

Chapter 3:
Focuses on hardware we used, their theoretical background and applications. Each
hardware’s detail. How the hardware works. How the hardware can be implementation.

Chapter 4: Focus on system design and simulations.

Chapter 5:
Focuses on experimental result. How we gave our best result from our project that
described in this chapter. Also we showed all the results visual here.

Chapter 6:
Concludes overall the project. And advantages of this project. How this project will give
it’s best in our daily life.

5
Chapter 02

IoT Technology

6
2.1 Introduction

Presently there is a globally growing demand across all industries for small and portable
electronic devices which feature Internet connectivity. This is largely due to their ease of
use provided by robust interoperability and feasibility in almost any scenario. Internet of
Things (IoT) can be a great tool to achieve this goal of connecting people and devices
everywhere all the time. IoT is a network of various types of devices connected together to
seamlessly data transfer without any computer or human interaction. IoT can be defined as
a network consisting of many small sensor nodes whose main purpose is to collect data
from surrounding environment and then forward to the base station.

1.2 Working Procedure of IoT

A complete IoT system integrates four distinct components: sensors/devices, connectivity,


data processing, and a user interface. Below I will briefly explain each component and
what it does.
1) Sensors/Devices First, sensors or devices collect data from their environment. This
could be as simple as a temperature reading or as complex as a full video feed. I use
“sensors/devices,” because multiple sensors can be bundled together or sensors can be part
of a device that does more than just sense things. For example, your phone is a device that
has multiple sensors (camera, accelerometer, GPS, etc), but your phone is not just a
sensor. However, whether it’s a standalone sensor or a full device, in this first step data is
being collected from the environment by something.
2) Connectivity Next, that data is sent to the cloud (what’s the cloud?), but it needs a way
to get there! The sensors/devices can be connected to the cloud through a variety of
methods including: cellular, satellite, WiFi, Bluetooth, low-power wide-area networks
(LPWAN), or connecting directly to the internet via ethernet. Each option has tradeoffs
between power consumption, range and bandwidth (here’s a simple explanation).
Choosing which connectivity option is best comes down to the specific IoT application,
but they all accomplish the same task: getting data to the cloud.
3) Data Processing Once the data gets to the cloud, software performs some kind of
processing on it. This could be very simple, such as checking that the temperature reading
is within an acceptable range. Or it could also be very complex, such as using computer
vision on video to identify objects (such as intruders in your house). But what happens
when the temperature is too high or if there is an intruder in your house? That’s where the
user comes in.
4) User Interface Next, the information is made useful to the end-user in some way. This
could be via an alert to the user (email, text, notification, etc). For example, a text alert
when the temperature is too high in the company’s cold storage. Also, a user might have
an interface that allows them to proactively check in on the system. For example, a user
might want to check the video feeds in their house via a phone app or a web browser.
However, it’s not always a one-way street. Depending on the IoT application, the user may
also be able to perform an action and affect the system. For example, the user might
remotely adjust the temperature in the cold storage via an app on their phone. And some
actions are performed automatically. Rather than waiting for you to adjust the temperature,
the system could do it automatically via predefined rules. And rather than just call you to
alert you of an intruder, the IoT system could also automatically notify relevant
authorities.

7
2.3 Advantages of IoT

Let’s look at several ways SMBs can leverage the future of the Internet of Things and its
cutting-edge technology to improve critical aspects of business.

1. Cost reduction: The more businesses use IoT devices to streamline operations and
increase profitability, the more Internet of Things technologies will be tailored to
help those businesses succeed. From cybersecurity to workplace efficiency, IoT
devices are already making an impact on companies’ bottom lines. Maintenance
costs can be positively impacted when IoT devices are used with sensors to keep
business equipment running at peak efficiency. On-the-fly troubleshooting of
office equipment catches problems before they impact staff and employees, saving
the hassle and costs of large repairs. This minimizes costly extended downtime for
repairs—just one of the benefits the Internet of Things brings to your operations
and maintenance workflow. As you can imagine, this technology is extremely
useful to businesses in the manufacturing, logistics, and food and beverage sectors
to name a few. There are also numerous ways to use IoT technology to favorably
impact your bottom line through streamlining common working processes, a top
driver of IoT investment for many companies. What the stats say about cost
reduction Cost reduction as a result of Internet of Things implementation is most
prevalent in certain industries, particularly manufacturing. For example, a study by
Deloitte found that predictive maintenance (PdM) can reduce the time required to
plan maintenance by 20–50%, increase equipment uptime and availability by 10–
20%, and reduce overall maintenance costs by 5–10%. Naturally, for a
manufacturer, cutting costs in this manner is exceptionally beneficial, and while
these types of industries are benefitting the most from IoT adoption, there are also
clear benefits for the vast majority of SMBs, regardless of industry. This is often
the case when it comes to reducing labor costs by improving process efficiencies.
83% of organizations that have introduced IoT technology have improved their
efficiency by doing so, reducing their expenditures and bettering output from
employees. McKinsey estimates that activity monitoring can improve productivity
by 10-12%, essentially meaning more bang for the business’ buck. Number of
Internet of Things devices worldwide in billions.

2. Efficiency & productivity: Efficiency is the basis for the kind of improved
productivity that boosts revenue for SMBs. One way to leverage the power of IoT
to increase company efficiency is to use it to cut down on repetitive or time-
consuming tasks. An example IoT function for this strategy would be an automated
PDF conversion and creation tool that removes the obstacles to PDF editing and
archiving, increasing communication and documentation speeds. These IoT tools
increase the kind of inter/intra-office communication that results in better
productivity. In fact, according to a survey conducted by Harvard Business
Review, 58% of companies are seeing increased collaboration through the use of
IoT devices. In the work environment, IoT can be used to optimize an office floor
plan and mobilize company resources—like copiers, printers, and WiFi bandwidth
—for a better workflow and a more streamlined and effective approach to
management. Finally, using big data analytics through IoT can provide an
overview of employee productivity and help determine what tasks are improving
the function of your business—and which are impairing it. Big data can also be

8
instrumental in tracking efficiency for manufacturing supply chains. You can
follow delivery systems and monitor products and inventory to stay ahead of
demand. Related Post: Supply Chain Disruption: Mitigating Threats Effectively
with Analysis Additionally, you ensure that your hardware and software are
appropriately connected to provide service without lag time to employees and
customers. What the stats say about efficiency As we previously mentioned, many
of the benefits IoT implementation delivers has knock-on effects—improving your
workforce’s productivity means reducing overall labor costs. A study by Aruba
found that 46% of businesses that adopted IoT strategies experienced efficiency
gains, despite the fact that only 29% expected such gains in the first place. While
those figures may seem low, it’s worth noting that many of these businesses may
not have anticipated the efficiency gains they reported, and their initial intentions
for implementation were more aligned with general modernization of their
processes rather than a specific focus on improving the efficiency of a particular
task. In other words, the efficiency benefits gained can be unintended
consequences of upgrading organizational processes, but are very welcome
nonetheless. 78% say the introduction of IoT in the workplace has improved the
effectiveness of their IT team, and 75% find it has increased profitability. IoT is
widely adopted and beneficial

3. Business opportunities: While many businesses strive to access the revenue-


producing power of digital services, most lack a cohesive strategy for pursuing this
avenue. IoT is a game-changer in this respect, as advanced analytics, artificial
intelligence, and smart utility grids make it easy for SMBs to collect actionable
data needed to provide the value their customers are seeking. These analytics
provide new insights that are not only being utilized to create new business
models, but completely redefining traditional industries. For example, IoT sensors
on automobiles that can track speed and driving habits help insurers optimize rates
on automobile insurance. Retailers can use IoT to measure in-store foot traffic to
optimize displays for maximum impact based on customer habits. The use of IoT
has so much impact on business systems that 36% of companies are considering
new directions in business thanks to their IoT initiatives. As a result of IoT’s
ability to connect products and services as they relate to customer behaviors, more
businesses are delivering new or updated products and services to an expanded
customer base. With more data available through IoT devices than ever before on
customer preferences and product performance over time, businesses are able to
use this and predict behavior patterns and needs of consumers better than ever.

4. Customer experience: While IoT technology has so far mostly influenced back-end
processes because of its relatively new presence, today’s IoT has meant that omni-
channel strategies have completely upended the way consumers approach their
relationships with businesses. Front-end customer engagement has become a
priority for organizations as they look to engage better with their audiences,
usually through IoT devices. Customers in 2020 have an expectation towards
businesses that must be met; namely that they want to be able to interact with you
through their phone, whether that’s using an automated chatbot or dedicated app.
40% of consumers do not care whether a chatbot or a real human helps them, as
long as they are getting the help they need. Because of this, forward-thinking
businesses are using new technology and combining it with the IoT to better serve
their customers.

9
2.4 Applications of IoT

1. Wearables. Virtual glasses, fitness bands to monitor for example calorie


expenditure and heart beats, or GPS tracking belts, are just some examples of
wearable devices that we have been using for some time now. Companies such as
Google, Apple, Samsung and others have developed and introduced the Internet of
Things and the application thereof into our daily lives. These are small and energy
efficient devices, which are equipped with sensors, with the necessary hardware for
measurements and readings, and with software to collect and organize data and
information about users.

2. Health. The use of wearables or sensors connected to patients, allows doctors to


monitor a patient's condition outside the hospital and in real-time. Through
continuously monitoring certain metrics and automatic alerts on their vital signs,
the Internet of Things helps to improve the care for patients and the prevention of
lethal events in high-risk patients. Another use is the integration of IoT technology
into hospital beds, giving way to smart beds, equipped with special sensors to
observe vital signs, blood pressure, oximeter and body temperature, among others.

3. Traffic monitoring. The Internet of things can be very useful in the management of
vehicular traffic in large cities, contributing to the concept of smart cities. When
we use our mobile phones as sensors, which collect and share data from our
vehicles through applications such as Waze or Google Maps, we are using the
Internet of Things to inform us and at the same time contribute to traffic
monitoring, showing the conditions of the different routes, and feeding and
improving the information on the different routes to the same destination, distance,
estimated time of arrival.

4. Fleet management. The installation of sensors in fleet vehicles helps to establish an


effective interconnectivity between the vehicles and their managers as well as
between the vehicles and their drivers. Both driver and manager/ owner can know
all kinds of details about the status, operation and needs of the vehicle, just by
accessing the software in charge of collecting, processing and organizing the data.
Even, receive alarms in real time of maintenance incidents without having been
detected by the driver. The application of the Internet of Things to fleet
management assists with geolocation (and with it the monitoring of routes and
identification of the most efficient routes), performance analysis, telemetry control
and fuel savings , the reduction of polluting emissions to the environment and can
even provide valuable information to improve the driving of vehicles.

5. Agriculture. Smart farms are a fact. The quality of soil is crucial to produce good
crops, and the Internet of Things offers farmers the possibility to access detailed
knowledge and valuable information of their soil condition. Through the
implementation of IoT sensors, a significant amount of data can be obtained on the
state and stages of the soil. Information such as soil moisture, level of acidity, the

10
presence of certain nutrients, temperature and many other chemical characteristics,
helps farmers control irrigation, make water use more efficient, specify the best
times to start sowing, and even discover the presence of diseases in plants and soil.

2.5 Summary

The term Internet of Things generally refers to scenarios where network connectivity


and computing capability extends to objects, sensors and everyday items not normally
considered computers, allowing these devices to generate, exchange and consume data
with minimal human intervention.

11
Chapter 03

Hardware
And
Software

12
3.1 Introduction

In this chapter we are going to describe our all equipment. Which we have used in our
project.

3.2 Required Components

1. Arduino Uno
2. ESP 8266
3. 3.5 Inch TFT Display with Touch Screen
4. 4 Channel Relay Module
5. 12V Power Supply

3.3 Arduino UNO

Arduino Uno is a microcontroller board based on 8-bit ATmega328P microcontroller.


Along with ATmega328P, it consists other components such as crystal oscillator, serial
communication, voltage regulator, etc. to support the microcontroller. Arduino Uno has 14
digital input/output pins (out of which 6 can be used as PWM outputs), 6 analog input
pins, a USB connection, A Power barrel jack, an ICSP header and a reset button.

Fig. 3.1: Arduino UNO

3.3.1 Arduino UNO Feature

13
Microcontroller ATmega328P – 8 bit AVR family
microcontroller

Operating Voltage 5V

Recommended Input 7-12V


Voltage

Input Voltage Limits 6-20V

Analog Input Pins 6 (A0 – A5)

Digital I/O Pins 14 (Out of which 6 provide PWM output)

DC Current on I/O Pins 40 mA

DC Current on 3.3V Pin 50 mA

Flash Memory 32 KB (0.5 KB is used for Bootloader)

SRAM 2 KB

EEPROM 1 KB

Frequency (Clock Speed) 16 MHz

Table 3.1: Specifications of Arduino UNO

3.3.2 Arduino UNO Pin Configurations

Pin Category Pin Name Details


Power Vin, 3.3V, 5V, GND Vin: Input voltage to
Arduino when using an
external power source.
5V: Regulated power
supply used to power

14
microcontroller and other
components on the board.
3.3V: 3.3V supply
generated by on-board
voltage regulator.
Maximum current draw is
50mA.
GND: ground pins.
Reset Reset Resets the
microcontroller.
Analog Pins A0 – A5 Used to provide analog
input in the range of 0-5V
Input/Output Pins Digital Pins 0 - 13 Can be used as input or
output pins.
Serial 0(Rx), 1(Tx) Used to receive and
transmit TTL serial data.
External Interrupts 2, 3 To trigger an interrupt.
PWM 3, 5, 6, 9, 11 Provides 8-bit PWM
output.
SPI 10 (SS), 11 (MOSI), 12 Used for SPI
(MISO) and 13 (SCK) communication.
Inbuilt LED 13 To turn on the inbuilt
LED.
TWI A4 (SDA), A5 (SCA) Used for TWI
communication.
AREF AREF To provide reference
voltage for input voltage.

Table 3.2: Pins of Arduino UNO

3.4 ESP 8266

ESP8266 is a low-cost open source IoT platform. It initially included firmware which runs
on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which was based on
the ESP-12 module. Later, support for the ESP32 32-bit MCU was added.

15
Figure 3.2: ESP 8266

3.4.1 Specifications & Features

 Microcontroller: Tensilica 32-bit RISC CPU Xtensa LX106


 Operating Voltage: 3.3V
 Input Voltage: 7-12V
 Digital I/O Pins (DIO): 16
 Analog Input Pins (ADC): 1
 UARTs: 1
 SPIs: 1
 I2Cs: 1
 Flash Memory: 4 MB
 SRAM: 64 KB
 Clock Speed: 80 MHz
 USB-TTL based on CP2102 is included onboard, Enabling Plug n Play
 PCB Antenna
 Small Sized module to fit smartly inside your IoT projects

3.4.2 NodeMCU Development Board Pinout Configuration

Pin Category Name Description


Power Micro-USB, 3.3V, Micro-USB:
GND, Vin NodeMCU can be
powered through the
USB port

3.3V: Regulated 3.3V


can be supplied to this
pin to power the board

GND: Ground pins

Vin: External Power


Supply
Control Pins EN, RST The pin and the button
resets the
microcontroller

16
Analog Pin A0 Used to measure
analog voltage in the
range of 0-3.3V
GPIO Pins GPIO1 to GPIO16 NodeMCU has 16
general purpose input-
output pins on its
board
SPI Pins SD1, CMD, SD0, CLK NodeMCU has four
pins available for SPI
communication.
UART Pins TXD0, RXD0, TXD2, NodeMCU has two
RXD2 UART interfaces,
UART0 (RXD0 &
TXD0) and UART1
(RXD1 & TXD1).
UART1 is used to
upload the
firmware/program.
I2C Pins NodeMCU has I2C
functionality support
but due to the internal
functionality of these
pins, you have to find
which pin is I2C.

Table 3.3: Pins of ESP 8266

3.5 3.5 Inch Touch Screen Display

A 3.5” TFT LCD module consists of a bright backlight (4 white LEDs) and a colourful
480X320 pixels display. It also features individual RGB pixel control giving a much better
resolution than the black and white displays. A resistive touch screen comes pre-installed
with the module as a bonus and hence you can easily detect your finger presses anywhere
on the screen.

17
Figure 3.3: 3.5 Inch Display

3.5.1 Features

Name Parameter

Display Color RGB 65K color

SKU MAR3501

Screen Size  3.5(inch)

Type TFT

Driver IC ILI9486

Resolution 480*320 (Pixel)

Module Interface 8-bit parallel interface

Active Area  73.44*48.96(mm)

Module PCB Size 85.49*55.63(mm)

Operating Temperature -20℃~70℃

18
Storage Temperature -40℃~70℃

Operating Voltage 5V/3.3V

Power Consumption TBD

Table 3.4: Features of 3.5 Inch Display


3.5.1 Pins

Number Pin Label Pin Description

1 LCD_RST LCD bus reset signal, low level reset

2 LCD_CS LCD bus chip select signal, low level enable

LCD bus command / data selection signal,


3 LCD_RS
low level: command, high level: data

4 LCD_WR LCD bus write signal


5 LCD_RD LCD bus read signal
6 GND Power ground
7 5V 5V power input
8 3V3 3.3V power input, this pin can be disconnected
9 LCD_D0 LCD 8-bit data Bit0
10 LCD_D1 LCD 8-bit data Bit1
11 LCD_D2 LCD 8-bit data Bit2
12 LCD_D3 LCD 8-bit data Bit3
13 LCD_D4 LCD 8-bit data Bit4
14 LCD_D5 LCD 8-bit data Bit5
15 LCD_D6 LCD 8-bit data Bit6
16 LCD_D7 LCD 8-bit data Bit7
17 SD_SS SD card SPI bus chip select signal, low level enable
18 SD_DI SD card SPI bus MOSI signal
19 SD_DO SD card SPI bus MISO signal

19
20 SD_SCK SD card SPI bus clock signal

Table 3.5: Pins of 3.5 inch Display

3.6 4 Channel Relay Module

The four-channel relay module contains four 5V relays and the associated switching and
isolating components, which makes interfacing with a microcontroller or sensor easy with
minimum components and connections. The contacts on each relay are specified for
250VAC and 30VDC and 10A in each case, as marked on the body of the relays.

Figure 3.4: 4 Channel Relay Module

3.6.1 Features

 Supply voltage – 3.75V to 6V


 Trigger current – 5mA
 Current when the relay is active - ~70mA (single), ~300mA (all four)
 Relay maximum contact voltag
 e – 250VAC, 30VDC
20
 Relay maximum current – 10A

3.6.2 Pin Configuration

Pin Number Pin Name Description


1 GND Ground reference for the module
2 IN1 Input to activate relay 1
3 IN2 Input to activate relay 2
4 IN3 Input to activate relay 3
5 IN4 Input to activate relay 4
6 VCC Power supply for the relay module
7 VCC Power supply selection jumper
8 JD-VCC Alternate power pin for the relay module

Table 2.5: Pins of 4 Channel Relay Module

3.7 2 12V DC Power Supply

12V power supplies (or 12VDC power supplies) are one of the most common power
supplies in use today. Linear regulated 12VDC power supplies regulate the output using a
dissipative regulating circuit. They are extremely stable, have very low ripple, and have no
switching frequencies to produce EMI.

21
Fig. 2.14: 12VDC Power Supply

3.8 Arduino IDE Installation


Now one after another the Arduino software and the USB driver for the board have to be
installed.
1. We have downloaded the Arduino software from www.arduino.cc and installed it on the
computer (This was NOT connected to the PC). After that we opened the software file and
installed the program named arduino.exe.
Two set ups on the program are important and should be considered.
a) The board that we want to connect has to be selected on the arduino software. The
“Arduino Uno” is here known as “Arduino / Genuino Uno and NodeMCU”.
b) We have to choose the right “Serial-Port”, to let the Computer know to which port the
board has been connected. That is only possible if the USB driver has been installed
correctly. It can be checked this way:

Figure 3.3: Arduino IDE

22
At the moment the Arduino wasn’t connected to the PC. If we now choose “Port”, under
the field “Tool”, we will already see one or more ports here (COM1/ COM2/ COM3…).
The quantity of the shown ports doesn't depend on the quantity of the USB ports on the
computer. When the board gets connected to the computer, we will find one more port.

3.9 Blynk Android App


Blynk is a new platform that allows you to quickly build interfaces for controlling and
monitoring your hardware projects from your iOS and Android device. After downloading
the Blynk app, you can create a project dashboard and arrange buttons, sliders, graphs, and
other widgets onto the screen

23
Figure 3.3: Blynk App Interface

Chapter 04

System Design

24
4.1 Introduction

In This chapter we are going to describe how we designed our project. And also showing
or diagrams like circuit diagram, flow chart, block diagram.

4.2 Block Diagram

Figure 4.1: Block Diagram of IoT Based Home Automation With HMI

25
4.3 Flow Chart

Figure 4.2: Flow Chart of IoT Based Home Automation with HMI

26
4.4 Circuit Diagram

Figure 4.2: Circuit Diagram of IoT Based Home Automation with HMI

27
Chapter 05

Final Result

28
5.1 Introduction
In this chapter we are going to show our final result of this project and advantages of our
project and cost analysis of our project.

5.2 Result
Our final result is now we are able to control any electrical load through our mobile phone
over internet from anywhere. Also at the same time if we want then we can control them
using HMI (Human Machine Interface). HMI is basically a touch screen display.

5.3 Project Outlook

5.4 Advantages
29
1. Smart Home
2. Save Electricity
3. Safety from electrical shock
4. Protection from any electrical accident
5. Save time.
6. Save electric bill.

5.5 Cost Analysis


No Equipment Name Price
1 Arduino Uno 660
2 ESP 8266 440
3 3.5 Inch Touch Display 3300
4 4 Channel Relay 260
Module
5 12V Power Supply * 2 390
6 Others 1200
Total 6250 TK

Table 5.1: Cost Analysis

30
Chapter 06

Discussion
And
Conclusions

31
6.1 Discussion
Home Automation System (HAS) gains popularity due to communication technology
advancement. Smart home is one of the Internet of Things (IoT) applications that
facilitates the control of home appliances over the Internet using automation system. This
paper proposes a low-cost Wi-Fi based automation system for Smart Home (SH) in order
to monitor and control home appliances remotely using Android-based application. An
Arduino Uno microcontroller provided with Wi-Fi module is utilized to build the
automation system. A relay board is exploited to connect the HAS with home under
controlled appliances. The proposed automation system, can easily and efficiently control
the electrical appliances via touch screen and Wi-Fi and Blynk mobile application.

6.2 Future Work


1. In future we will add AI (Artificial Intelligence) so this project will more efficient
and accurate.
2. We will add some sensors like temperature, humidity, motion sensor for observing
the home.
3. We will add some security device for making secure our home.

6.3 Conclusion
This research project has proposed, designed and fabricated a low cost Wi-Fi based
Automation System for Smart Home prototype using Arduino and Android smartphone
and HMI. It enables the control all the electrical appliances such as the bulb and fan at
home easily and efficiently via Wi-Fi. The sensor can monitor the motion, humidity and
temperature of the house. Buzzer will be ON when there is a motion detected in the house.
The Smart Home Automation System provide a comfortable, intelligence, good security
and improve the quality of life. By using this smart home system, electric bill can be
reduced because the user can control the electrical appliances anytime without using
human energy. The next step of our research will be enabling the remote control of the
developed system based on IoT concept so that the user can control it using webserver
even when they are not around their house. We are going to increase the number and
variety of sensors for more safety and security in addition to provide option for the fully-
automated of home appliances. We will implement a gateway to connect all sensors to an
IoT platform and we may replace some sensors with a wireless sensor to overcome some
wiring problems. Our final product should be a compact box which is easy to be integrated
to an existing switching board of real houses appliances via relay board and provide safer
control.

32
Reference
[1] W. A. Jabbar, M. Ismail, and R. Nordin, "Evaluation of energy consumption in
multipath OLSR routing in Smart City applications," in Communications (MICC), 2013
IEEE Malaysia International Conference on, 2013, pp. 401-406.

[2] K.-M. Lee, W.-G. Teng, and T.-W. Hou, "Point-n-Press: An Intelligent Universal
Remote Control System for Home Appliances," IEEE Transactions on automation science
and engineering, vol. 13, pp. 1308-1317, 2016.

[3] P. P. Gaikwad, J. P. Gabhane, and S. S. Golait, "A survey based on Smart Homes
system using Internet-of-Things," in Computation of Power, Energy Information and
Commuincation (ICCPEIC), 2015 International Conference on, 2015, pp. 0330-0335.

[4] W. A. Jabbar, M. Ismail, and R. Nordin, "MBA-OLSR: a multipath battery aware


routing protocol for MANETs," in Intelligent Systems, Modelling and Simulation (ISMS),
2014 5th International Conference on, 2014, pp. 630-635: IEEE

[5] T. Song, R. Li, B. Mei, J. Yu, X. Xing, and X. Cheng, "A privacy preserving
communication protocol for IoT applications in smart homes," IEEE Internet of Things
Journal, vol. 4, pp. 1844-1852, 2017.

[6] D. Acharjya, M. K. Geetha, and S. Sanyal, Internet of Things: novel advances and
envisioned applications vol. 25: Springer, 2017.

[7] R. Piyare and M. Tazil, "Bluetooth based home automation system using cell phone,"
in Consumer Electronics (ISCE), 2011 IEEE 15th International Symposium on, 2011, pp.
192-195.

[8] W. A. Jabbar, M. Ismail, R. Nordin, and S. Arif, "Power-efficient routing schemes for
MANETs: a survey and open issues," Wireless Networks, pp. 1-36, 2016.

[9] S. Wu, J. B. Rendall, M. J. Smith, S. Zhu, J. Xu, H. Wang, et al., "Survey on


prediction algorithms in smart homes," IEEE Internet of Things Journal, vol. 4, pp. 636-
644, 2017.

[10] O. T. Algoiare, "Design and implementation of intelligent home using gsm network,"
2014.

33
[11] R. Kazi and G. Tiwari, "IoT based Interactive Industrial Home wireless system,
Energy management system and embedded data acquisition system to display on web page
using GPRS, SMS & E-mail alert," in Energy Systems and Applications, 2015
International Conference on, 2015, pp. 290-295.

Appendix I
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Blynk.h>
#include <Ticker.h>

#define ssid "P"


#define pass "123456789"
#define auth "leKeZc64Ab0uiNboRHQYu3BS225cjLVH"

#define r1 16
#define r2 14
#define r3 12
#define r4 13

int setTimer1, setTimer2, setTimer3, setTimer4;


int timer1, timer2, timer3, timer4;
bool rly1, rly2, rly3, rly4;
bool timerMode = 0, firstRun = 0;

Ticker rtc;

void setup() {
Serial.begin(9600);
rtc.attach(1.0, oneSec);

pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(r4, OUTPUT);

WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println((String)"\nConnected To " + ssid);
Blynk.config(auth);

34
Blynk.connect(3333);
}

void oneSec() {
if (timerMode == 1) {
timer1++; timer2++;
timer3++; timer4++;

if (timer1 == setTimer1) {
timer1 = 0;
rly1 = !rly1;
digitalWrite(r1, rly1);
Blynk.virtualWrite(V4, rly1);
Serial.print("R1=");
Serial.println(rly1);
}
if (timer2 == setTimer2) {
timer2 = 0;
rly2 = !rly2;
digitalWrite(r2, rly2);
Blynk.virtualWrite(V5, rly2);
Serial.print("R2=");
Serial.println(rly2);
}
if (timer3 == setTimer3) {
timer3 = 0;
rly3 = !rly3;
digitalWrite(r3, rly3);
Blynk.virtualWrite(V6, rly3);
Serial.print("R3=");
Serial.println(rly3);
}
if (timer4 == setTimer4) {
timer4 = 0;
rly4 = !rly4;
digitalWrite(r4, rly4);
Blynk.virtualWrite(V7, rly4);
Serial.print("R4=");
Serial.println(rly4);
}
}
}

void loop() {
Blynk.run();

if (Serial.available() > 0) {
String cmd = Serial.readString();

if (cmd.startsWith("TM")) {

35
cmd.remove(0, 3);
timerMode = cmd.toInt();
Blynk.virtualWrite(V8, timerMode);
}

if (cmd.startsWith("T1")) {
cmd.remove(0, 3);
setTimer1 = cmd.toInt();
Blynk.virtualWrite(V0, setTimer1, 0, "Europe/Kiev", "1");
}

if (cmd.startsWith("T2")) {
cmd.remove(0, 3);
setTimer2 = cmd.toInt();
Blynk.virtualWrite(V1, setTimer2, 0, "Europe/Kiev", "1");
}

if (cmd.startsWith("T3")) {
cmd.remove(0, 3);
setTimer3 = cmd.toInt();
Blynk.virtualWrite(V2, setTimer3, 0, "Europe/Kiev", "1");
}

if (cmd.startsWith("T4")) {
cmd.remove(0, 3);
setTimer4 = cmd.toInt();
Blynk.virtualWrite(V3, setTimer4, 0, "Europe/Kiev", "1");
}

if (timerMode == 0) {
if (cmd.startsWith("V4")) {
cmd.remove(0, 3);
rly1 = cmd.toInt();
digitalWrite(r1, rly1);
Blynk.virtualWrite(V4, rly1);
}
else if (cmd.startsWith("V5")) {
cmd.remove(0, 3);
rly2 = cmd.toInt();
digitalWrite(r2, rly2);
Blynk.virtualWrite(V5, rly2);
}
else if (cmd.startsWith("V6")) {
cmd.remove(0, 3);
rly3 = cmd.toInt();
digitalWrite(r3, rly3);
Blynk.virtualWrite(V6, rly3);
}
else if (cmd.startsWith("V7")) {
cmd.remove(0, 3);

36
rly4 = cmd.toInt();
digitalWrite(r4, rly4);
Blynk.virtualWrite(V7, rly4);
}
}
}
}

BLYNK_CONNECTED() {
if (firstRun == 0) {
Blynk.syncAll();
firstRun = 1;
}
}

BLYNK_WRITE(V0) {
if (param[0].asLong() != setTimer1) {
setTimer1 = param[0].asLong();
Serial.print("T1=");
Serial.println(setTimer1);
}
}

BLYNK_WRITE(V1) {
if (param[0].asLong() != setTimer2) {
setTimer2 = param[0].asLong();
Serial.print("T2=");
Serial.println(setTimer2);
}
}

BLYNK_WRITE(V2) {
if (param[0].asLong() != setTimer3) {
setTimer3 = param[0].asLong();
Serial.print("T3=");
Serial.println(setTimer3);
}
}

BLYNK_WRITE(V3) {
if (param[0].asLong() != setTimer4) {
setTimer4 = param[0].asLong();
Serial.print("T4=");
Serial.println(setTimer4);
}
}

BLYNK_WRITE(V4) {
if (param.asInt() != rly1 && timerMode == 0) {
rly1 = param.asInt();

37
digitalWrite(r1, rly1);
Serial.print("R1=");
Serial.println(rly1);
}
}

BLYNK_WRITE(V5) {
if (param.asInt() != rly2 && timerMode == 0) {
rly2 = param.asInt();
digitalWrite(r2, rly2);
Serial.print("R2=");
Serial.println(rly2);
}
}

BLYNK_WRITE(V6) {
if (param.asInt() != rly3 && timerMode == 0) {
rly3 = param.asInt();
digitalWrite(r3, rly3);
Serial.print("R3=");
Serial.println(rly3);
}
}

BLYNK_WRITE(V7) {
if (param.asInt() != rly4 && timerMode == 0) {
rly4 = param.asInt();
digitalWrite(r4, rly4);
Serial.print("R4=");
Serial.println(rly4);
}
}

BLYNK_WRITE(V8) {
if (param.asInt() != timerMode) {
timerMode = param.asInt();
Serial.print("TM=");
Serial.println(timerMode);
}
}

38
Appendix II
#include <SoftwareSerial.h>
#include <TouchScreen.h> //touch library
#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_KBV.h> //Hardware-specific library

SoftwareSerial esp(11, 10);

#define BLACK 0x0000 /* 0, 0, 0 */


#define BLUE 0x001F /* 0, 0, 255 */
#define RED 0xF800 /* 255, 0, 0 */
#define GREEN 0x07E0 /* 0, 255, 0 */
#define CYAN 0x07FF /* 0, 255, 255 */
#define MAGENTA 0xF81F /* 255, 0, 255 */
#define YELLOW 0xFFE0 /* 255, 255, 0 */
#define WHITE 0xFFFF /* 255, 255, 255 */
#define NAVY 0x000F /* 0, 0, 128 */
#define DARKGREEN 0x03E0 /* 0, 128, 0 */
#define DARKCYAN 0x03EF /* 0, 128, 128 */
#define MAROON 0x7800 /* 128, 0, 0 */
#define PURPLE 0x780F /* 128, 0, 128 */
#define OLIVE 0x7BE0 /* 128, 128, 0 */
#define LIGHTGREY 0xC618 /* 192, 192, 192 */
#define DARKGREY 0x7BEF /* 128, 128, 128 */
#define ORANGE 0xFD20 /* 255, 165, 0 */
#define GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define PINK 0xF81F /* 255, 0, 255 */

#define TS_MINX 906


#define TS_MAXX 116
#define TS_MINY 92
#define TS_MAXY 952

#define STATUS_X 10
#define STATUS_Y 65

#define MINPRESSURE 10
#define MAXPRESSURE 1000

39
#define YP A3
#define XM A2
#define YM 9
#define XP 8

LCDWIKI_KBV my_lcd(ILI9486, A3, A2, A1, A0, A4);


TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

byte hh1, hh2, hh3, hh4;


byte mm1, mm2, mm3, mm4;
bool rly1, rly2, rly3, rly4;
int timer1, timer2, timer3, timer4;
bool mode;

typedef struct _button_info {


uint8_t button_name[4];
uint8_t button_name_size;
uint16_t button_name_colour;
uint16_t button_colour;
uint16_t button_x;
uint16_t button_y;
} button_info;

#define BUTTON_R 35 //the radius of button


#define BUTTON_SPACING_X 35 //the horizontal distance between button
#define BUTTON_SPACING_Y 10 //the vertical distance between button
#define EDG_Y 10 //lower edge distance
#define EDG_X 20 //left and right distance

button_info phone_button[12] = {
"1", 4, BLACK, CYAN, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() -
EDG_Y - 4 * BUTTON_SPACING_Y - 9 * BUTTON_R - 1,
"2", 4, BLACK, CYAN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1,
my_lcd.Get_Display_Height() - EDG_Y - 4 * BUTTON_SPACING_Y - 9 * BUTTON_R
- 1,
"3", 4, BLACK, CYAN, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X - 1,
my_lcd.Get_Display_Height() - EDG_Y - 4 * BUTTON_SPACING_Y - 9 * BUTTON_R
- 1,
"4", 4, BLACK, CYAN, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() -
EDG_Y - 3 * BUTTON_SPACING_Y - 7 * BUTTON_R - 1,
"5", 4, BLACK, CYAN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1,
my_lcd.Get_Display_Height() - EDG_Y - 3 * BUTTON_SPACING_Y - 7 * BUTTON_R
- 1,
"6", 4, BLACK, CYAN, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X - 1,
my_lcd.Get_Display_Height() - EDG_Y - 3 * BUTTON_SPACING_Y - 7 * BUTTON_R
- 1,
"7", 4, BLACK, CYAN, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() -
EDG_Y - 2 * BUTTON_SPACING_Y - 5 * BUTTON_R - 1,

40
"8", 4, BLACK, CYAN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1,
my_lcd.Get_Display_Height() - EDG_Y - 2 * BUTTON_SPACING_Y - 5 * BUTTON_R
- 1,
"9", 4, BLACK, CYAN, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X - 1,
my_lcd.Get_Display_Height() - EDG_Y - 2 * BUTTON_SPACING_Y - 5 * BUTTON_R
- 1,
"<<", 3, WHITE, RED, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() -
EDG_Y - BUTTON_SPACING_Y - 3 * BUTTON_R - 1,
"0", 4, BLACK, CYAN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1,
my_lcd.Get_Display_Height() - EDG_Y - BUTTON_SPACING_Y - 3 * BUTTON_R - 1,
"SET", 3, BLACK, GREEN, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X
- 1, my_lcd.Get_Display_Height() - EDG_Y - BUTTON_SPACING_Y - 3 * BUTTON_R
- 1,
};

uint16_t text_x = 7, text_y = 10, text_x_add = 6 * phone_button[0].button_name_size,


text_y_add = 8 * phone_button[0].button_name_size;
byte n = 0, updater;
bool inKeypadScreen = 0;

void setup() {
Serial.begin(9600);
esp.begin(9600);
my_lcd.Init_LCD();
delay(2000);

homeScreen();
}

void loop() {
checkTouch();
if (esp.available() > 0) {
String cmd = esp.readString();

if (cmd.startsWith("R1=1")) {
rly1 = 1;
updateUI(1);
}
else if (cmd.startsWith("R1=0")) {
rly1 = 0;
updateUI(1);
}

else if (cmd.startsWith("R2=1")) {
rly2 = 1;
updateUI(2);
}
else if (cmd.startsWith("R2=0")) {
rly2 = 0;
updateUI(2);

41
}

else if (cmd.startsWith("R3=1")) {
rly3 = 1;
updateUI(3);
}
else if (cmd.startsWith("R3=0")) {
rly3 = 0;
updateUI(3);
}

else if (cmd.startsWith("R4=1")) {
rly4 = 1;
updateUI(4);
}
else if (cmd.startsWith("R4=0")) {
rly4 = 0;
updateUI(4);
}

else if (cmd.startsWith("TM=1")) {
mode = 1;
updateUI(5);
}
else if (cmd.startsWith("TM=0")) {
mode = 0;
updateUI(5);
}

else if (cmd.startsWith("T1")) {
cmd.remove(0, 3);
timer1 = cmd.toInt();
hh1 = timer1 / 3600;
mm1 = ((timer1 / 3600.0) - hh1) * 60;
updateUI(6);
}

else if (cmd.startsWith("T2")) {
cmd.remove(0, 3);
timer2 = cmd.toInt();
hh2 = timer2 / 3600;
mm2 = ((timer2 / 3600.0) - hh2) * 60;
updateUI(7);
}

else if (cmd.startsWith("T3")) {
cmd.remove(0, 3);
timer3 = cmd.toInt();
hh3 = timer3 / 3600;
mm3 = ((timer3 / 3600.0) - hh3) * 60;

42
updateUI(8);
}

else if (cmd.startsWith("T4")) {
cmd.remove(0, 3);
timer4 = cmd.toInt();
hh4 = timer4 / 3600;
mm4 = ((timer4 / 3600.0) - hh4) * 60;
updateUI(9);
}
}
}

void homeScreen() {
my_lcd.Fill_Screen(BLACK);

my_lcd.Set_Draw_color(DARKGREY);
my_lcd.Fill_Rectangle(0, 455, 320, 480);

// borders
my_lcd.Set_Draw_color(GREEN);
my_lcd.Draw_Rectangle(10, 20, 155, 130);
my_lcd.Draw_Rectangle(165, 20, 310, 130);
my_lcd.Draw_Rectangle(10, 145, 155, 260);
my_lcd.Draw_Rectangle(165, 145, 310, 260);

my_lcd.Draw_Rectangle(10, 275, 80, 385);


my_lcd.Draw_Rectangle(85, 275, 155, 385);
my_lcd.Draw_Rectangle(160, 275, 230, 385);
my_lcd.Draw_Rectangle(235, 275, 305, 385);

// timer span
my_lcd.Set_Draw_color(ORANGE);
my_lcd.Fill_Rectangle(20, 55, 75, 120);
my_lcd.Fill_Rectangle(90, 55, 145, 120);

my_lcd.Fill_Rectangle(175, 55, 230, 120);


my_lcd.Fill_Rectangle(245, 55, 300, 120);

my_lcd.Fill_Rectangle(20, 180, 75, 250);


my_lcd.Fill_Rectangle(90, 180, 145, 250);

my_lcd.Fill_Rectangle(175, 180, 230, 250);


my_lcd.Fill_Rectangle(245, 180, 300, 250);

my_lcd.Fill_Rectangle(10, 400, 310, 440); // mode

// texts
print("TIMER 1", 15, 30, 2, WHITE, BLACK);
print("TIMER 2", 170, 30, 2, WHITE, BLACK);

43
print("TIMER 3", 15, 155, 2, WHITE, BLACK);
print("TIMER 4", 170, 155, 2, WHITE, BLACK);

print("R1", 35, 320, 2, WHITE, BLACK);


print("R2", 110, 320, 2, WHITE, BLACK);
print("R3", 185, 320, 2, WHITE, BLACK);
print("R4", 260, 320, 2, WHITE, BLACK);

// timer span
print(str(hh1).c_str(), 30, 75, 3, BLACK, ORANGE);
print(":", 75, 75, 3, WHITE, BLACK);
print(str(mm1).c_str(), 100, 75, 3, BLACK, ORANGE);

print(str(hh2).c_str(), 185, 75, 3, BLACK, ORANGE);


print(":", 230, 75, 3, WHITE, BLACK);
print(str(mm2).c_str(), 255, 75, 3, BLACK, ORANGE);

print(str(hh3).c_str(), 30, 200, 3, BLACK, ORANGE);


print(":", 75, 200, 3, WHITE, BLACK);
print(str(mm3).c_str(), 100, 200, 3, BLACK, ORANGE);

print(str(hh4).c_str(), 185, 200, 3, BLACK, ORANGE);


print(":", 230, 200, 3, WHITE, BLACK);
print(str(mm4).c_str(), 255, 200, 3, BLACK, ORANGE);

print("MODE: BUTTON", 90, 415, 2, BLACK, ORANGE);


}

void showKeypad() {
uint16_t i;
text_x = 7, text_y = 10;
text_x_add = 6 * phone_button[0].button_name_size;
text_y_add = 8 * phone_button[0].button_name_size;
n = 0;
my_lcd.Fill_Screen(BLUE);
for (i = 0; i < sizeof(phone_button) / sizeof(button_info); i++) {
my_lcd.Set_Draw_color(phone_button[i].button_colour);
my_lcd.Fill_Circle(phone_button[i].button_x, phone_button[i].button_y, BUTTON_R);
print(phone_button[i].button_name, phone_button[i].button_x -
strlen(phone_button[i].button_name)*phone_button[i].button_name_size * 6 / 2 +
phone_button[i].button_name_size / 2 + 1, phone_button[i].button_y -
phone_button[i].button_name_size * 8 / 2 + phone_button[i].button_name_size / 2 + 1,
phone_button[i].button_name_size, phone_button[i].button_name_colour, BLACK);
}
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(1, 1, my_lcd.Get_Display_Width() - 2, 3);
my_lcd.Fill_Rectangle(1, 45, my_lcd.Get_Display_Width() - 2, 47);
my_lcd.Fill_Rectangle(1, 1, 3, 47);
my_lcd.Fill_Rectangle(my_lcd.Get_Display_Width() - 4, 1,
my_lcd.Get_Display_Width() - 2, 47);

44
}

void print(uint8_t *str, int16_t x, int16_t y, uint8_t csize, uint16_t fc, uint16_t bc) {
my_lcd.Set_Text_Mode(1);
my_lcd.Set_Text_Size(csize);
my_lcd.Set_Text_colour(fc);
my_lcd.Set_Text_Back_colour(bc);
my_lcd.Print_String(str, x, y);
}

String str(int val) {


if (val < 10) return (String) '0' + val;
else return (String) val;
}

void checkTouch() {
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
p.x = map(p.x, TS_MINX, TS_MAXX, my_lcd.Get_Display_Width(), 0);
p.y = map(p.y, TS_MINY, TS_MAXY, my_lcd.Get_Display_Height(), 0);

if (inKeypadScreen == 1) {
uint8_t val[2];
for (int i = 0; i < sizeof(phone_button) / sizeof(button_info); i++) {
if (isPressed(phone_button[i].button_x - BUTTON_R, phone_button[i].button_y -
BUTTON_R, phone_button[i].button_x + BUTTON_R, phone_button[i].button_y +
BUTTON_R, p.x, p.y)) {
my_lcd.Set_Draw_color(DARKGREY);
my_lcd.Fill_Circle(phone_button[i].button_x, phone_button[i].button_y,
BUTTON_R);
print(phone_button[i].button_name, phone_button[i].button_x -
strlen(phone_button[i].button_name)*phone_button[i].button_name_size * 6 / 2 +
phone_button[i].button_name_size / 2 + 1, phone_button[i].button_y -
phone_button[i].button_name_size * 8 / 2 + phone_button[i].button_name_size / 2 + 1,
phone_button[i].button_name_size, WHITE, BLACK);
delay(100);
my_lcd.Set_Draw_color(phone_button[i].button_colour);
my_lcd.Fill_Circle(phone_button[i].button_x, phone_button[i].button_y,
BUTTON_R);
print(phone_button[i].button_name, phone_button[i].button_x -
strlen(phone_button[i].button_name)*phone_button[i].button_name_size * 6 / 2 +
phone_button[i].button_name_size / 2 + 1, phone_button[i].button_y -
phone_button[i].button_name_size * 8 / 2 + phone_button[i].button_name_size / 2 + 1,
phone_button[i].button_name_size, phone_button[i].button_name_colour, BLACK);
if (n < 2 && i != 9 && i != 11) {

45
print(phone_button[i].button_name, text_x, text_y,
phone_button[i].button_name_size, GREENYELLOW, BLACK);
text_x += text_x_add - 1;
val[n] = phone_button[i].button_name[0];
n++;
}
else if (i == 11) { // SET
inKeypadScreen = 0;
switch (updater) {
case 1:
hh1 = (val[0] - 48) * 10 + (val[1] - 48);
timer1 = hh1 * 3600 + mm1 * 60;
Serial.println((String)"T1=" + timer1);
break;
case 2:
mm1 = (val[0] - 48) * 10 + (val[1] - 48);
timer1 = hh1 * 3600 + mm1 * 60;
esp.println((String)"T1=" + timer1);
break;
case 3:
hh2 = (val[0] - 48) * 10 + (val[1] - 48);
timer2 = hh2 * 3600 + mm2 * 60;
esp.println((String)"T2=" + timer2);
break;
case 4:
mm2 = (val[0] - 48) * 10 + (val[1] - 48);
timer2 = hh2 * 3600 + mm2 * 60;
esp.println((String)"T2=" + timer2);
break;
case 5:
hh3 = (val[0] - 48) * 10 + (val[1] - 48);
timer3 = hh3 * 3600 + mm3 * 60;
esp.println((String)"T3=" + timer3);
break;
case 6:
mm3 = (val[0] - 48) * 10 + (val[1] - 48);
timer3 = hh3 * 3600 + mm3 * 60;
esp.println((String)"T3=" + timer3);
break;
case 7:
hh4 = (val[0] - 48) * 10 + (val[1] - 48);
timer4 = hh4 * 3600 + mm4 * 60;
esp.println((String)"T4=" + timer4);
break;
case 8:
mm4 = (val[0] - 48) * 10 + (val[1] - 48);
timer4 = hh4 * 3600 + mm4 * 60;
esp.println((String)"T4=" + timer4);
break;
}

46
homeScreen();
}
else if (i == 9) { //del
if (n > 0) {
my_lcd.Set_Draw_color(BLUE);
text_x -= (text_x_add - 1);
my_lcd.Fill_Rectangle(text_x, text_y, text_x + text_x_add - 1, text_y +
text_y_add - 2);
val[n] = 0;
n--;
}
}
}
}
}
else {
if (isPressed(20, 55, 75, 120, p.x, p.y)) { // hh1
updater = 1;
inKeypadScreen = 1;
showKeypad();
}
else if (isPressed(90, 55, 145, 120, p.x, p.y)) { // mm1
updater = 2;
inKeypadScreen = 1;
showKeypad();
}
else if (isPressed(175, 55, 230, 120, p.x, p.y)) { // hh2
updater = 3;
inKeypadScreen = 1;
showKeypad();
}
else if (isPressed(245, 55, 300, 120, p.x, p.y)) { // mm2
updater = 4;
inKeypadScreen = 1;
showKeypad();
}
else if (isPressed(20, 180, 75, 250, p.x, p.y)) { // hh3
updater = 5;
inKeypadScreen = 1;
showKeypad();
}
else if (isPressed(90, 180, 145, 250, p.x, p.y)) { // mm3
updater = 6;
inKeypadScreen = 1;
showKeypad();
}
else if (isPressed(175, 180, 230, 250, p.x, p.y)) { // hh4
updater = 7;
inKeypadScreen = 1;
showKeypad();

47
}
else if (isPressed(245, 180, 300, 250, p.x, p.y)) { // mm4
updater = 8;
inKeypadScreen = 1;
showKeypad();
}
else if (isPressed(10, 275, 80, 385, p.x, p.y)) { // rly1
rly1 = !rly1;
updateUI(1);
}
else if (isPressed(85, 275, 155, 385, p.x, p.y)) { // rly2
rly2 = !rly2;
updateUI(2);
}
else if (isPressed(160, 275, 230, 385, p.x, p.y)) { // rly3
rly3 = !rly3;
updateUI(3);
}
else if (isPressed(235, 275, 305, 385, p.x, p.y)) { // rly4
rly4 = !rly4;
updateUI(4);
}
else if (isPressed(10, 400, 310, 440, p.x, p.y)) { // mode
mode = !mode;
updateUI(5);
}
}
}
}

void updateUI(byte which) {


if (which == 1) {
if (rly1 == 1) {
my_lcd.Set_Draw_color(GREEN);
my_lcd.Fill_Rectangle(10, 275, 80, 385);
print("R1", 35, 320, 2, BLACK, GREEN);
esp.println("V4=1");
delay(200);
}
else {
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(10, 275, 80, 385);
my_lcd.Set_Draw_color(GREEN);
my_lcd.Draw_Rectangle(10, 275, 80, 385);
print("R1", 35, 320, 2, WHITE, BLACK);
esp.println("V4=0");
delay(200);
}
}
else if (which == 2) {

48
if (rly2 == 1) {
my_lcd.Set_Draw_color(GREEN);
my_lcd.Fill_Rectangle(85, 275, 155, 385);
print("R2", 110, 320, 2, BLACK, GREEN);
esp.println("V5=1");
delay(200);
}
else {
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(85, 275, 155, 385);
my_lcd.Set_Draw_color(GREEN);
my_lcd.Draw_Rectangle(85, 275, 155, 385);
print("R2", 110, 320, 2, WHITE, BLACK);
esp.println("V5=0");
delay(200);
}
}
else if (which == 3) {
if (rly3 == 1) {
my_lcd.Set_Draw_color(GREEN);
my_lcd.Fill_Rectangle(160, 275, 230, 385);
print("R3", 185, 320, 2, BLACK, GREEN);
esp.println("V6=1");
delay(200);
}
else {
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(160, 275, 230, 385);
my_lcd.Set_Draw_color(GREEN);
my_lcd.Draw_Rectangle(160, 275, 230, 385);
print("R3", 185, 320, 2, WHITE, BLACK);
esp.println("V6=0");
delay(200);
}
}
else if (which == 4) {
if (rly4 == 1) {
my_lcd.Set_Draw_color(GREEN);
my_lcd.Fill_Rectangle(235, 275, 305, 385);
print("R4", 260, 320, 2, BLACK, GREEN);
esp.println("V7=1");
delay(200);
}
else {
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(235, 275, 305, 385);
my_lcd.Set_Draw_color(GREEN);
my_lcd.Draw_Rectangle(235, 275, 305, 385);
print("R4", 260, 320, 2, WHITE, BLACK);
esp.println("V7=0");

49
delay(200);
}
}
else if (which == 5) {
if (mode == 1) {
my_lcd.Set_Draw_color(ORANGE);
my_lcd.Fill_Rectangle(10, 400, 310, 440);
print("MODE: TIMER", 90, 415, 2, BLACK, ORANGE);
esp.println("TM=1");
delay(200);
}
else {
my_lcd.Set_Draw_color(ORANGE);
my_lcd.Fill_Rectangle(10, 400, 310, 440);
print("MODE: BUTTON", 90, 415, 2, BLACK, ORANGE);
esp.println("TM=0");
delay(200);
}
}
else if (which == 6) {
my_lcd.Set_Draw_color(ORANGE);
my_lcd.Fill_Rectangle(20, 55, 75, 120);
my_lcd.Fill_Rectangle(90, 55, 145, 120);
print(str(hh1).c_str(), 30, 75, 3, BLACK, ORANGE);
print(":", 75, 75, 3, WHITE, BLACK);
print(str(mm1).c_str(), 100, 75, 3, BLACK, ORANGE);
}
else if (which == 7) {
my_lcd.Set_Draw_color(ORANGE);
my_lcd.Fill_Rectangle(175, 55, 230, 120);
my_lcd.Fill_Rectangle(245, 55, 300, 120);
print(str(hh2).c_str(), 185, 75, 3, BLACK, ORANGE);
print(":", 230, 75, 3, WHITE, BLACK);
print(str(mm2).c_str(), 255, 75, 3, BLACK, ORANGE);
}
else if (which == 8) {
my_lcd.Set_Draw_color(ORANGE);
my_lcd.Fill_Rectangle(20, 180, 75, 250);
my_lcd.Fill_Rectangle(90, 180, 145, 250);
print(str(hh3).c_str(), 30, 200, 3, BLACK, ORANGE);
print(":", 75, 200, 3, WHITE, BLACK);
print(str(mm3).c_str(), 100, 200, 3, BLACK, ORANGE);
}
else if (which == 9) {
my_lcd.Set_Draw_color(ORANGE);
my_lcd.Fill_Rectangle(175, 180, 230, 250);
my_lcd.Fill_Rectangle(245, 180, 300, 250);
print(str(hh4).c_str(), 185, 200, 3, BLACK, ORANGE);
print(":", 230, 200, 3, WHITE, BLACK);
print(str(mm4).c_str(), 255, 200, 3, BLACK, ORANGE);

50
}
}

boolean isPressed(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t px, int16_t py) {
if ((px > x1 && px < x2) && (py > y1 && py < y2)) return true;
else return false;
}

51

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy