Home Automation Based On IoT Using Google Assistant

54
ALNEELAIN UNIVERCITY FACULTY OF ELECTRONIC ENGINEERING M.SC. OF EMBEDDED SYSTEMS Home Automation Based On IoT Using Google Assistant Thesis submitted in partial fulfillment of requirement for M.Sc. degree in embedded systems By: Ahmed Mohammed Ahmed Ali Supervisor: Dr. Abdelrahim Ahmed Mohamed Ate November 2020

Transcript of Home Automation Based On IoT Using Google Assistant

ALNEELAIN UNIVERCITY

FACULTY OF ELECTRONIC ENGINEERING

M.SC. OF EMBEDDED SYSTEMS

Home Automation Based On IoT Using

Google Assistant

Thesis submitted in partial fulfillment of requirement for M.Sc. degree

in embedded systems

By:

Ahmed Mohammed Ahmed Ali

Supervisor:

Dr. Abdelrahim Ahmed Mohamed Ate

November 2020

I

ياأ

حيم حمن الره الره ه بسم

: قال تعالى

ين ) { ق أ أ آي ل ر 02في اأأ أ مأ أف ت س في أنأ ) (12{(

صدق ه العظيم

يا ة) سو ا ) ال

(21-20)ياأ

II

ااهداء

يب ال اي ر يل إا بش يب ال ي اي حظ إا إا إل يب ال ات عتك .. يب ب ا ت كر .. بيب ال إا برؤيتك ه جل جله ا ت اآخر إا بع ..

ن ي الرح ح اأم .. إل ن ن ن .. أ اأم ل غ الرس ين إل من ب ل .. الع

د ص ه مسيدن مح س يه ع

ي ل ه ه ب ل إل من ك ه ب ل أس ء بد انتظ .. إل من أح ي الع ق .. إل من ع الست .. افت ف بعد ط انتظ ا قد ح ق ر لتر ث د في ع ج من ه أ ي تك أ ك

إل اأبد في الغد .. ن أهتد ب الي

الد العزيز

ني .. إل بس الحي إل الت إل مع الح ج مكي في الحي .. إل مع الحب سر ال

يب سم جراحي إل أغ الح ن ب ح حي ئ سر ن ع إل من ك

ي أمي الح

ي مإل من ب ع ر تي مأك ير حي د ت ع مت د .. إل ش .. أعت

ه ج مح ا حد ل مإل من ب .. أكتسب ق

مع الحي مإل من عرفت مع

تي ااعزاءأخ

نك اشيء معك ه الحي بد بي فيق نك أك مثل أ شيء .. في إل أخي بد أك أن ك اق ر ع م يد أ أش ا أ ي مش ظرا اأمل ن حي ب عت ل ي إل من ت ال

.اشرفأخي

بيع إل ء إل ي الع ء ف ل ا ب يز ت ء إخ دهن أمي .. إل من تح ب اتي لم ت ا ال اأخالحزي سر إل من م في الحي الح ت برف م سعد ، في إل من مع د ال ال

ير ال ا معي ع طريق ال ن ك

م ني أ ا أضيع ع إل من عرفت كيف أجدهم

A5WIS

III

Acknowledgement

Firstly, we thank “Allah”, for letting us through all the

difficulties. We have experienced your guidance day by

day. I will keep on trusting you for my future.

I would like to send our sincere gratitude to our

supervisor

Dr. Abdel Rahim Ahmed Ate

For comments that greatly improved the manuscript and

for sharing his pearls of wisdom, patience, motivations,

enthusiasm and immense knowledge, his guidance helped

me in all the time of this research, I am very grateful for

your efforts.

Last but not the least to all those that helped me toward

this success, specially my parents, my families, my

teachers and my colleagues.

IV

Abstract

This research addressed the applications of embedded systems

using the internet of things. The research contained a general

study of the IoT and its practical applications. On the practical

side of the research, some home appliances were controlled via

verbal commands on Google Assistance. Arduino IDE was use to

program an ESP 8266 controller with three digital outputs for

switching it ON and OFF. The home appliances were run

automatically through the voice command of Google assistant.

This was achieved by designing the system. The result of turning

a light ON/OFF usi g a er al o a d tur light ON/OFF

through Google Assistant was achieve. The ESP 8266 controller

gave the corresponding output to the ON/OFF command. The

same result was attained for other appliances, namely: fan and

AC ith the er al o a ds tur Fa ON/OFF a d tur AC

ON/OFF respe ti ely. Therefore, the cost reduced by minimizing

the circuit component and using ESP 8266 that is costless and

has WIFI module build in .The consistency of the results with

different types of appliances showed the robustness of the code

and the configuration of the controller.

V

ص ست ال

ل اأنظمهذا البحث ، تنا ني باستخدا المتضمن هذا البحث ع دراس يحت اأشياءنترن أ ت

ا IoTعام لل تطبي ل ،إضاف ي تمث العم . زة المنزلي المتحكاستخدا ل التحك االي في ااج

ESP8266 خرج رقم 42ع يحت الذ ربائي دخل زة الك تحك في تشغيل ااج ذل ل ي

قل لتشغيل النظا مباشرة،المنزلي تي لمساعد ق امر ص يمكن مالبرنامج المص عن اعطاء ا

تحك في ا جزء من استخدامهعديل فيه بحيث يمكن الت ستخدا ت إالبحث في هذا البرنامج،ل

كي تال ع صيا الس صل ال لتصمي شكل المشر قد ت الت ائي، اف/تشغيل الن المصباح عند اي

فظي " قل turn light on/offاعطاء اامر ال بإعطاء ESP8266ي متحك عندها " لمساعد ق

افإ تشغيلإما الخرج المائ له، زة ، المصباح ي ي باقي اأج ي نفس النتيج ع ت الحصل ع

تي امرالص المكيف باعطاء اا ح turn Fan on/off" turn AC المنزلي بااخص المر

on/off" الي ي الت دائرة ع ف من خال استخدا عناصر اقل ل نا التك ا متحك باستخد بذل ق

ESP8266 ا فا مضمن الرخيص الثمن د اثبت . يحت المتحكم النتائج كفاءةل د .الك

VI

Contents

I اأي

II ااهداء

ACKNOWLEDGEMENT III

ABSTRACT IV

ص ست V ال

LIST OF CONTENTS V1

LIST OF FIGURES IX

LIST OF TABLE X

LIST OF ABBREVIATIONS XI

CHAPTER ONE, INTRODUCTION 1

1.1 Overview 1

1.2 Problem statement 3

1.3 Research Objectives 3

1.4 Methodology 3

1.5 Research Layout 4

VII

CHAPTER TWO,LITERATURE REVIEW 5

2.1 Introduction to Internet of things (IoT) 5

2.2 History of IOT 5

2.3 Architecture 7

2.3.1 Network architecture 8

2.3.2 Enabling technologies for IoT 8

2.3.3 Addressability 9

2.3.4 Short-range wireless 10

2.4 ESP8266 NodeMCU 11

2.4.1 NodeMCU Devkit 1.0 11

2.4.2 ESP-12E 12

2.4.3 Node MCU 1.0 ESP-12E Pins 13

2.5 IFTTT 14

2.5.1 Overview 15

2.5.2 Applet 16

2.6 Control devices using the Google Assistant 17

2.6.1 Control devices using voice commands 17

2.7 Adafruit IO 19

2.7.1 Adafruit dashboard

20

2.8 Message Queuing Telemetry Transport (MQTT) 21

2.8.1 Message types

22

VIII

CHAPTER THREE ,METHODOLOGY 24

3.1 Introductions 24

3.2 Project Implementation 24

3.3 Program Explanation 25

CHAPTER FOUR ,RESULT AND DISCUSSIONS 28

4.1 Introduction 28

2.4 turning light on/off operation 28

4.3 Turning Fan on/off operation 29

4.4 Turning AC on/0ff operation 30

4.4 Active/dis-active motion sensor 31

CHAPTER FIVE ,CONCLUSION AND RECOMMENDATIONS 32

5.1 Conclusion 32

5.2 Recommendation 32

REFERENCES 33

APPENDIX 35

IX

LIST OF FIGURES

Page NO FIGURE NO.

12 ESP kit

12 ESP-12E

13 Processor RISC Ten silica

14 ESP pins

20 Adafruit IO Dashboard configuration

23 Mqtt session

26 Program procedure

27 Operation flow chart

28 Turn light on

29 Turn light off

29 Turn fan on

29 Turn fan off

30 Turn AC on

30 Turn AC off

X

LIST OF TABLE

TABLE NO PAGE

google assistant control light commands 18

google assistant commands 19

XI

List of ABBREVIATIONS

Abbreviation Denotation

IOT Internet Of Thinks

IFTTT IF This Then That

MQTT Message Queuing Telemetry Transport

Li-Fi Light-Fidelity RFID Radio-frequency Identification D2D Device to Device

NFC Near-field Communication

DEL Decode-Encode Language),

NLS On-Line System ()

1

Chapter One

Introduction

1.1 Overview

The Internet of Things (IoT) is the network of physical devices,

vehicles, home appliances, and other items embedded with

electronics, software, sensors, actuators, and connectivity which

enables these things to connect and exchange data.

The number of IoT devices increased 31% year-over-year to 8.4

billion in the year 2017 and it is estimated that there will be 30

billion devices by 2020. The global market value of IoT is

projected to reach $7.1 trillion by 2020.[1]

IoT devices can be used to monitor and control the mechanical,

electrical and electronic systems used in various types of

buildings (e.g., public and private, industrial, institutions, or

residential) in home automation and building automation

systems. In this context, three main areas are being covered in

literature:

The integration of the Internet with building energy

management systems in order to create energy efficient and IOT

dri e s art uildi gs .

The possible means of real-time monitoring for reducing energy

consumption and monitoring occupant behaviors.

4

The integration of smart devices in the built environment and

how they might to know who to be used in future

applications.[2]

The IoT can assist in the integration of communications, control,

and information processing across various transportation

systems. Application of the IoT extends to all aspects of

transportation systems (i.e. the vehicle,] the infrastructure, and

the driver or user). Dynamic interaction between these

components of a transport system enables inter and intra

vehicular communication. smart traffic control, smart parking,

electronic toll collection systems, logistic and fleet management,

vehicle control, and safety and road assistance. In Logistics and

Fleet Management for example, The IoT platform can

continuously monitor the location and conditions of cargo and

assets via wireless sensors and send specific alerts when

management exceptions occur (delays, damages, thefts, etc.).

This can only be possible with the IoT and its seamless

connectivity among devices. Sensors such as GPS, Humidity,

Temperature, send data to the IoT platform and then the data is

analyzed and send further to the users.[3]

1.2 Problem statement

The main problem that the home automation has highly cost to

control appliances, in this project the cost reduce based on voice

controlled (Google Assistant) in home automation controlling

general appliances.

3

1.3 Aims and Objectives

The specific objectives are

Understand the IOT projects.

The aim of this research is to propose a cost-effective

voice controlled (Google Assistant) home automation

o trolli g ge eral applia es fou d i o e’s ho e.

1.4 Methodology

In this research, the Google Assistant, the IFTTT application, the

Arduino framework software and the NodeMCU ESB 8266

microcontroller are used as the major components along with a

relays and sensors. Natural language voice is used to give

commands to the Google Assistant, the IFTTT transfer the

command to MQTT server where ESP 8266 can read the change

and give signal of the suitable output. All of the components are

connected over the internet using Wi-Fi which puts this system

under the IoT.

2

1.5 Thesis Layout

This project consists of five chapters. Chapter one gives brief

introduction about the proposed project. Chapter two is

literature review on this field, chapter three is the design and

implementation of simulation, chapter four contains the results

and discussion, finally chapter showed conclusion and

recommendation.

Chapter Two

Literature Review

2.1 Introduction to Internet of things (IoT)

The Internet of things (IoT) is the network of devices such as

vehicles, and home appliances that contain electronics, software,

actuators, and connectivity which allows these things to connect,

interact and exchange data

The IoT involves extending Internet connectivity beyond standard

devices, such as desktops, laptops, smart phones and tablets, to

any range of traditionally dumb or non-internet-enabled physical

devices and everyday objects. Embedded with technology, these

devices can communicate and interact over the Internet, and they

can be remotely monitored and controlled. [4]

2.2 History of IOT

The definition of the Internet of things has evolved due to

convergence of multiple technologies, real-time analytics, machine

learning, commodity sensors, and embedded systems. Traditional

fields of embedded systems, wireless sensor networks, control

systems, automation (including home and building automation),

and others all contribute to enabling the Internet of things.

The concept of a network of smart devices was discussed as early

as 1982, with a modified Coke vending machine at Carnegie Mellon

University becoming the first Internet-connected appliance, able to

report its inventory and whether newly loaded drinks were cold or

not Mark Weiser's 1991 paper on ubiquitous computing, "The

Computer of the 21st Century", as well as academic venues such as

UbiComp and PerCom produced the contemporary vision of the

IoT. In 1994, Reza Raji described the concept in IEEE Spectrum as

"[moving] small packets of data to a large set of nodes, so as to

integrate and automate everything from home appliances to entire

factories". Between 1993 and 1997, several companies proposed

solutions like Microsoft's at Work or Novell's NEST. The field

gained momentum when Bill Joy envisioned Device-to-Device

(D2D) communication as a part of his "Six Webs" framework,

presented at the World Economic Forum at Davos in 1999.

The term "Internet of things" was likely coined by Kevin Ashton of

Procter & Gamble, later MIT's Auto-ID Center, in 1999 though he

prefers the phrase "I ter et for thi gs . At that poi t, he ie ed

Radio-frequency identification (RFID) as essential to the Internet of

things, which would allow computers to manage all individual

things.[5]

A research article mentioning the Internet of Things was submitted

to the conference for Nordic Researchers in Norway, in June 2002,

which was preceded by an article published in Finnish in January

2002 The implementation described there was developed by Kary

Främling and his team at Helsinki University of Technology and

more closely matches the modern one, i.e. an information system

infrastructure for implementing smart, connected objects. [6]

2.3 Architecture

IoT system architecture, in its simplistic view, consists of

three tiers: Tier 1: Devices, Tier 2: the Edge Gateway, and Tier

3.The Cloud Devices include networked things, such as the sensors

and actuators found in IoT equipment, particularly those that use

protocols such as Modbus, Zigbee, or proprietary protocols, to

connect to an Edge Gateway The Edge Gateway consists of sensor

data aggregation systems called Edge Gateways that provide

functionality, such as pre-processing of the data, securing

connectivity to cloud, using systems such as Web Sockets, the

event hub, and, even in some cases, edge analytics or fog

computing The final tier includes the cloud application built for IoT

using the micro services architecture, which are usually polyglot

and inherently secure in nature using HTTPS/OAuth. It includes

various database systems that store sensor data, such as time

series databases or asset stores using backend data storage

systems (e.g. Cassandra, Posters). The cloud tier in most cloud-

based IoT system features event queuing and messaging system

that handles communication that transpires in all tiers. Some

experts classified the three-tiers in the IoT system as edge,

platform, and enterprise and these are connected by proximity

network, access network, and service network, respectively. [7]

Building on the Internet of things, the web of things is architecture

for the application layer of the Internet of things looking at the

convergence of data from IoT devices into Web applications to

create innovative use-cases. In order to program and control the

flow of information in the Internet of things, a predicted

architectural direction is being called BPM everywhere, which is a

blending of traditional process management with process mining

and special capabilities to automate the control of large numbers

of coordinated devices.[6]

2.3.1 Network architecture

The Internet of things requires huge scalability in the network

space to handle the surge of devices. IETF 6LoWPAN would be

used to connect devices to IP networks. With billions of devices

being added to the Internet space, IPv6 will play a major role in

handling the network layer scalability. IETF's Constrained

Application Protocol, ZeroMQ, and MQTT would provide

lightweight data transport.

Fog computing is a viable alternative to prevent such large burst of

data flow through Internet. The edge devices' computation power

can be used to analyses and process data, thus providing easy real

time scalability.[7]

2.3.2 Enabling technologies for IoT

There are many technologies that enable the IoT. Crucial to the

field is the network used to communicate between devices of an

IoT installation, a role that several wireless or wired technologies

may fulfill.

2.3.3 Addressability

The original idea of the Auto-ID Center is based on RFID-tags and

distinct identification through the Electronic Product Code. This

has evolved into objects having an IP address or URI. An alternative

view, from the world of the Semantic Web focuses instead on

making all things (not just those electronic, smart, or RFID-

enabled) addressable by the existing naming protocols, such as

URI. The objects themselves do not converse, but other agents

may now refer to them, such as powerful centralized servers,

acting for their human owners, Integration with the Internet

implies that devices will use an IP address as a distinct identifier.

Due to the limited address space of IPv4 (which allows for 4.3

billion different addresses), objects in the IoT will have to use the

next generation of the Internet protocol (IPv6) to scale to the

extremely large address space required. Internet-of-things devices

additionally will benefit from the stateless address auto-

configuration present in IPv6, as it reduces the configuration

overhead on the hosts,] and the IETF 6LoWPAN header

compression. Largely, the future of the Internet of things will not

be possible without the support of IPv6. Consequently, the global

adoption of IPv6 in the coming years will be critical for the

successful development of the IoT in the future. [8]

11

2.3.4 Short-range wireless

Bluetooth mesh networking – Specification providing a mesh-

networking variant to Bluetooth low energy (BLE) with increased

number of nodes and standardized application layer (Models).

Light-Fidelity (Li-Fi) – Wireless communication technology similar

to the Wi-Fi standard, but using visible light communication for

increased bandwidth.

Near-field communication (NFC) – Communication protocols

enabling two electronic devices to communicate within a 4 cm

range.

QR codes and barcodes – Machine-readable optical tags that store

information about the item to which they are attached.

Radio-frequency identification (RFID) – Technology using

electromagnetic fields to read data stored in tags embedded in

other items.

Transport Layer Security – Network security protocol.

Wi-Fi – technology for local area networking based on the IEEE

802.11 standard, where devices may communicate through a

shared access point or directly between individual devices.

ZigBee – Communication protocols for personal area networking

based on the IEEE 802.15.4 standard, providing low power

consumption, low data rate, low cost, and high throughput.[8]

11

2.4 ESP8266 NodeMCU

ESP8266 pinning, or in other words, Node MCU,as it already

comes with USB input. However, it is important to explain that the

Node MCU is formed by an ESP12E, which still has an ESP8266EX

inside it. Thus, we will learn the correct pin identification by doing

the following: looking at the Node MCU datasheet, knowing which

of these pins work with digital Write, digital Read, analog Write,

and analog Read, and understanding the boot more thoroughly.

As programing more with Adriano IDE, the user practically see the

Node MCU as an Adriano. However, the user must emphasize

these devices have differences, especially concerning the pinning.

If the user at hed the E“P34 ideo e titled I ter al Details a d

Pi out, the user have learned there are pins that cannot be used,

or that are reserved for certain things. So the user want to do

something useful here related to this, but this time with

ESP8266.[9]

2.4.1 NodeMCU Devkit 1.0

The term Node MCU usually refers to the firmware, while the

board is called Davit. Node MCU Davit 1.0 consists of an ESP-12E

on a board, which facilitates its use. It also has a voltage regulator,

a USB interface as is shown in figure 2.1.[10]

14

Figure 2.1: ESP kit

2.4.2 ESP-12E

The ESP-12E is a board created by AI-THINKER, which consists of an

ESP8266EX inside the metal cover as is shown in figure 2.2.

Figure 2.2: ESP-12E

13

ESP8266EX

Made by Expressive, this microchip has integrated Wife and low-

power consumption.

Processor RISC Ten silica L 106 32bit with a maximum clock160

MHz as is shown in figure 2.3.[10]

Figure 2.3: Processor RISC Ten silica

2.4.3 Node MCU 1.0 ESP-12E Pins

It contains many pins for several purposes input pins, output pins

and communication pins

For output pins used the number that is in front of the constants

A0, D0, D1, D2, D3, D4, D5, D6, D7, and D8. The figure below shows

all pins in details as is shown in figure 2.4.

12

Figure 2.4 : ESP pins [9]

2.5 IFTTT

If This Then That, also known as IFTTT, is a free web-based service

to create chains of simple conditional statements, called applets.

An applet is triggered by changes that occur within other web

services such as Gmail, Facebook, Telegram, Instagram, or

Pinterest. For example, an applet may send an e-mail message if

the user tweets using a hashtag, or copy a photo on Facebook to a

user's archive if someone tags a user in a photo.

In addition to the web-based application, the service runs on iOS

and Android. In February 2015, IFTTT renamed its original

application to IF, and released a new suite of apps called Do, which

lets users create shortcut applications and actions. As of 2015,

1

IFTTT users created about 20 million recipes each day. All of the

functionalities of the Do suite of apps have since been integrated

into a redesigned IFTTT app. IFTTT is an initialize for "If This Then

[11]

2.5.1 Overview

IFTTT employs the following concepts:

Services (formerly known as channels) are the basic building blocks

of IFTTT. They mainly describe a series of data from a certain web

service such as YouTube or eBay. Services can also describe actions

controlled with certain APIs, like SMS. Sometimes, they can

represent information in terms of weather or stocks. Each service

has a particular set of triggers and actions.

Triggers are the "this" part of an applet. They are the items that

trigger the action. For example, from an RSS feed, you can receive

a notification based on a keyword or phrase.

Actions are the "that" part of an applet. They are the output that

results from the input of the trigger.

Applets (formerly known as recipes) are the predicates made from

Triggers and Actions. For example, if you like a picture on

Instagram (trigger), an IFTTT app can send the photo to your

Dropbox account (action).

Ingredients are basic data available from a trigger—from the email

trigger, for example; subject, body, attachment, received date, and

se der’s address.[12]

1

Usage examples

IFTTT can automate web-application tasks, such as posting the

same content on several social networks.

Marketing professionals can use IFTTT to track mentions of

companies in RSS feeds.

IFTTT also is used in home automation, for instance switching on a

light when detecting motion in a room (with associated compliant

devices).[13]

2.5.2 Applet

In computing, an applet is any small application that performs one

specific task that runs within the scope of a dedicated widget

engine or a larger program, often as a plug-in. The term is

frequently used to refer to a Java applet, a program written in the

Java programming language that is designed to be placed on a web

page. Applets are typical examples of transient and auxiliary

applications that don't monopolize the user's attention. Applets

are not full-featured application programs, and are intended to be

easily accessible.

The word applet was first used in 1990 in PC Magazine. However,

the concept of an applet, or more broadly a small-interpreted

program downloaded and executed by the user, dates at least to

RFC 5 (1969) by Jeff Rulifson, which described the Decode-Encode

Language (DEL), which was designed to allow remote use of the

on-Line System (NLS) over ARPANET, by downloading small

1

programs to enhance the interaction. This has been specifically

credited as a forerunner of Java's downloadable programs in RFC

2555. Applet is an event driven program. [13]

Applet as an extension of other software

In some cases, an applet does not run independently. These

applets must run either in a container provided by a host program,

through a plugin, or a variety of other applications including

mobile devices that support the applet programming model.

2.6 Control devices using the Google Assistant

The smart home devices including lights, switches, outlets, and

thermostats was controlled using the Google Assistant on Pixel

book.

For example, user can say or type:

"Ok Google, set the thermostat to 72 degrees"

"Ok Google, dim the kitchen lights"

The user can also use the Google Assistant to check the status of

compatible smart home devices, like thermostats and lights.

2.6.1 Control devices using voice commands

On your device, press the key or say "Ok Google."

1

Say "Ok Google" or select Speak

To type instead, select Type

Say or type a command [14]

Control lights

the brightness and turn on/off lights and more was

adjust. Explore all the Google Assistant partners user can use to

control things around user’s home with just your voice. Table 2.1

shows the commands.

Table 2.1: google assistant control light commands

To do this: “ay "Ok Google" or Hey Google," then...

To turn on/off a light "Turn on <light name>"

Dim a light "Dim the <light name>"

Brighten a light "Brighten the <light name>"

Set a light brightness to a

certain percentage

"Set <light name> to 50%"

Dim/Brighten lights by a

certain percentage

Dim/Brighten <light name>

by 50%"

Change the color of a light "Turn <light name> green"

Turn on/off all lights in room Tur o /off lights i <roo name>"

Turn on/off all lights Tur o /off all of the lights

1

Control smart fan and switch

The appliances around the house with smart plugs was

controlled. Explore all the Google Assistant partners user can use

to control things around your home with just your voice.as in the

table 2.2

Table 2.2: google assistant commands

To do this: “ay "Ok Google" or Hey Google," the ...

Turn on/off fan Tur o /off the [plug a e]"

Turn on/off switch Tur o /off the [s it h a e]

2.7 Adafruit IO

Adafruit.io is a cloud service - that just means we run it for you and

you don't have to manage it. You can connect to it over the

Internet. It's meant primarily for storing and then retrieving data

but it can do many feature such as:

1. Display data in real-time, online

2. Make project internet-connected: Control motors, read

sensor data, and more!

3. Connect projects to web services like Twitter, RSS feeds,

weather services, etc.

4. Connect project to other internet-enabled devices.

41

2.7.1 Adafruit dashboard

Dashboards allow you to visualize data and control Adafruit IO

connected projects from any modern web browser. Widgets

such as charts, sliders, and buttons are available to help you

quickly get your IoT project up and running without the need

for any custom code then configure it what suitable to your

project as shown in figure 2.5 below shows this.

Figure 2.5 : Adafruit IO Dashboard configuration

41

2.8 Message Queuing Telemetry Transport (MQTT)

An MQTT system consists of clients communicating with a

server, often called a "broker". A client may be either a

publisher of information or a subscriber. Each client can

connect to the broker.

Information is organized in a hierarchy of topics. When a

publisher has a new item of data to distribute, it sends a control

message with the data to the connected broker. The broker

then distributes the information to any clients that have

subscribed to that topic. The publisher does not need to have

any data on the number or locations of subscribers, and

subscribers in turn do not have to be have configured with any

data about the publishers.

If a broker receives a topic for which there are no current

subscribers, it will discard the topic unless the publisher

indicates that the topic is to be have retained. This allows new

subscribers to a topic to receive the most current value rather

than waiting for the next update from a publisher.

When a publishing client first connects to the broker, it can set

up a default message to be have sent to subscribers if the

broker detects that the publishing client has unexpectedly

disconnected from the broker.

Clients only interact with a broker, but a system may contain

several broker servers that exchange data based on their

current subscribers' topics.

44

A minimal MQTT control message can be as little as two bytes

of data. A control message can carry nearly 256 megabytes of

data if needed. There are fourteen defined message types used

to connect and disconnect a client from a broker, to publish

data, to acknowledge receipt of data, and to supervise the

connection between client and server.

MQTT relies on the TCP protocol for data transmission. A

variant, MQTT-SN, is used over other transports such as UDP or

Bluetooth.

MQTT sends connection credentials in plain text format and

does not include any measures for security or authentication.

This could be have provided by the underlying TCP transport

using measures to protect the integrity of transferred

information from interception or duplication. [16]

2.8.1 Message types

1. Connect

Waits for a connection to be established with the server and

creates a link between the nodes.

2. Disconnect

Waits for the MQTT client to finish any work it must do, and for

the TCP/IP session to disconnect.

43

3. Publish

Returns immediately to the application thread after passing the

request to the MQTT client as is shown in figure 2.6.[16]

Figure 2.6 : mqtt session [8]

42

Chapter Three

Methodology

3.1 Introductions

IoT devices can be used to monitor and control the mechanical,

electrical and electronic systems used in various types of

buildings (e.g., public and private, industrial, institutions, or

residential) in home automation and building automation

systems. In this context.

In recent years, it has become a common practice to combine

home automation systems with digital personal assistants. Many

big companies have presented their solutions to the market like

Google with Google Home and google assistant.

3.2 Project Implementation

This project uses the Google Assistant, the IFTTT application,

the Arduino framework software and the NodeMCU ESB 8266

microcontroller as the major components along with a relays

and sensors. Natural language voice is used to give commands to

the Google Assistant. All of the components are connected over

the internet using Wi-Fi, which puts this system under the IoT.

4

3.3 Program Explanation

The system mainly contains two modules. The module 1 is

Google assistant and IFTTT. In this phase, there are two stages.

The stage I called IFTTT account creation, and stage 2 called

Google assistant configuration. At first, user open Google

assistant and says ok Google establish the dialog. Then, says a

one of commands, which has been sit. Before that, user first

creates an IFTTT account and creates the triggers to turn on/off

the appliances through Adafruit 10. When a command to turn on

a device is given (1FT), then it (TT) forwards to Node MCU which

is placed in the corresponding output through Adafruit 10 MQTT

server. The module 2 of the system is the Node MCU connected

with electrical appliances. This phase also contains two stages:

stage 1 is called Adafruit 10 (MQTT server) account creation, and

stage 2 is called working of ESP8266 connected with electrical

appliances through relay which is placed at each classroom.

Before receiving the output from the Adafruit MQTT server, user

first creates an Adafruit 10 account and adds all the electrical

appliances in the dashboard. After the IFT (if this) section of the

IFTTT service in Google assistant, the "THEN THAT(TT)" section of

FITT is forward to Node ESP8266

Through Adafruit I0, and corresponding device will turn on/off.

So for this module 2, it require Node MCU, relay, high-speed Wi-

Fi for Internet and electrical appliances like fan, bulb, projector,

etc., and give power supply to ESP8266 and relay, the figures 3.1

and 3.2 show the modes and the flow chart of it respectively.

4

figure 3.1: program procedure [17]

4

figure 3.2: Operation Flow Chart [17]

When the system runs and takes a command from Google Assistant, this

command will be sent to IFTTT. IF it matches one of the given commands, the

ESP8266 will turn home appliances on or off by taking the signal from

Adafruit IO cloud.

Start

Initialize system peripherals

Google Assistant active on hearing

OK Google

Does the

command

match that

in IFTTT

NO

YES

Load ON/OFF

RETURN

4

Chapter Four

Result and Discussions

4.1 Introduction

This chapter presents discusses and the results obtained upon

running the program designed using by ESP8266 as main

controller and google assistant as command receiver.

2.4 turning light on/off operation

When the system started and a command turn light on is said to

google assistant the relay1 applet switch in adafruit io will turn

to on/off and the corresponded pin2 in ESP82366 output will

switch on/off so the lamb will be on as is shown in figure 4.1 and

4.2.

Figure 4.1 turn light on

4

Figure 4.2 turn light off

4.3 Turning Fan on/off operation

When the system started and a command turn fan on is said to

google assistant the relay2 applet switch in adafruit io will turn

to on and the corresponded realy in ESP82366 output pin3 will

switch on/off so the fan will be on/off as is shown in figure 4.3

and 4.4..

31

Figure 4.3 turn fan on

Figure 4.4: turn fan off

4.4 Turning AC on/0ff operation

When the system started and a command turn AC on is said to

google assistant the relay3 applet switch in adafruit io will turn

to on and the corresponded realy in ESP82366 output will switch

on so the lamb will be off. as shown in Figure 4.5 and figure 4.6.

31

Figure 4.5: turn AC on

Figure 4.6: turn AC off

4.4 Active/dis-active motion sensor

When the system started and a command active

motion/disactive motion on is said to google assistant the relay4

applet switch in adafruit io will tell ESP82366 to take the signal

of motion sensor in input pin to the output pin4

34

Chapter Five

Conclusion and Recommendations

5.1 Conclusion

In this project the home appliance system being

monitored and controlled using ESP Nod MCU 8266 to

design IOT system , the Arduino IDE software has been

used to program ESP8266 , the Google assistant has been

used to give a verbal command through IFTT to dafrut io

server. Moreover, the hardware has been implanted

successfully. In addition to that, this system is highly

reliable and efficient for the aged people and differently

abled person on a wheel chair who cannot reach the

switch for the switching ON/OFF the device and are

dependent on others.

5.2 Recommendation

In this system, more sensors can be embedded to

recognize the environment with more perfection and

accuracy.

(SMS) can also be integrated into the system. These extra

features will allow the system to directly alert the user.

33

REFERENCES

[1] Andreas François Vermeulen, Industrial Machine Learning:

using Artificial Intelligence as Transformational Disruptor, – p.50-

Apress Retrieved November 30, 2019

[2]https://medium.com/@1620/internet-of-things-

7890793864af.access time 4:00 5/6/2019

[3] Taiwan Information Strategy, Internet and E-commerce

Development Handbook, International Business

Publication.2006,P.75.

[4] XMPP community (November 1, 2013). "Internet Of Things".

wiki.xmpp.org. XMPP wiki. p. 1. Retrieved May 9, 2014.

[6] Ashton, K. (22 June 2009). "That 'Internet of Things' Thing".

Retrieved 9 May 2017.

[6] "ESP8266 Overview". Espressif Systems. Retrieved 2017-10-

02..access time 10:42 5/7/2019

[7] Rowayda, A. Sadek (May 2018). "– An Agile Internet of Things

(IoT) based Software Defined Network (SDN)

Architecture". Egyptian Computer Science Journal.

[8] Benjiamin Fabian,Olver Gunther,Lenka

Ivantysynova,Holger Ziekow, RFID and the Internet of Things:

Technology, Applications, and Security Challenges. January

2010.

[9] Bryan L. A., Bryan E. A., Programmable Controllers Theory

and Implementation, 2nd.Ed. Industrial Text Company, 1997.

[10] Vowstar. "NodeMCU Devkit". Github. NodeMCU Team.

Retrieved 2 April 2015.

32

[11]"Adafruit HUZZAH ESP8266 Breakout". Adafruit

Industries. Retrieved 2015-06-25.

[12] Bryan L. A., Bryan E. A., Programmable Controllers

Theory and Implementation, 2nd.Ed. Industrial Text Company,

1997.

[13] http:// www.timhunkin.com/a166_iot. access time 3:14

5/6/2019

[14] Wood, Daren; Robson, Dave (August 13, 2012). "Message

broker technology for flexible signalling control" (PDF).

irse.org. IRSE. p. 7. Retrieved March 31, 2014

[15] Zhang, Lucy (August 12, 2011). "Building Facebook

Messenger". facebook.com/Engineering. Facebook. p. 1.

Retrieved October 15, 2015.

[16] "MQTT Buddy". mqtt.ximxim.com. XIM, Inc. Retrieved

July 1, 2017.

[17] http:// www.electronicwiring.com/nodemcu/conytol-

homeaplliances-using-google-assistant. access time 4:24

5/6/2019.

3

APPENDIX

Arduino IDE cod

This code concluded to do the purpose of connecting ESP8266 to

WIFI first and then to connected it to the server Adafruit through

the web io.adafruit.com to be able to fetch the change and give

respected response to that change.

#include <ESP8266WiFi.h>

#include "Adafruit_MQTT.h"

#include "Adafruit_MQTT_Client.h"

/***************** Pin Definition ******************/

#define Relay1 1

#define Relay2 2

#define Relay3 3

#define Relay4 4

#define buzzer 0

#define analogpin A0

/********************* WiFi Acce***************/

#define WLAN_SSID "mate10"

3

#define WLAN_PASS "ahmed111"

/**************** Adafruit.io Setup ************/

#define AIO_SERVER "io.adafruit.com"

#define AIO_SERVERPORT 1883 // use 8883 for SSL

#define AIO_USERNAME "torlajzerz"

#define AIO_KEY "0de7d2dbd7694744b133f24f589f4bc7"

WiFiClient client;

);

/********************* Fee***********/

// Setup a feed called 'onoff' for subscribing to changes.

Adafruit_MQTT_SubscribeLight1=Adafruit_MQTT_Subscribe(&m

qtt,AIO_USERNAME"/feeds/rela");

Adafruit_MQTT_SubscribeFan1=Adafruit_MQTT_Subscribe(&mq

tt, AIO_USERNAME "/feeds/relay2");

Adafruit_MQTT_SubscribeAC=Adafruit_MQTT_Subscribe(&mqtt,

AIO_USERNAME "/feeds/relay3");

Adafruit_MQTT_Subscribemotion=Adafruit_MQTT_Subscribe(&

mqtt,AIO_USERNAME "/feeds/relay4");

/***************** Sketch Code ********************/

void MQTT_connect();

3

void setup() {

Serial.begin(115200);

delay(10);

pinMode(buzzer, OUTPUT);

pinMode(Relay1, OUTPUT);

pinMode(Relay2, OUTPUT);

pinMode(Relay3, OUTPUT);

pinMode(Relay4, OUTPUT);

// Connect to WiFi access point.

Serial.println(); Serial.println();

Serial.print("Connecting to ");

Serial.println(WLAN_SSID);

WiFi.begin(WLAN_SSID, WLAN_PASS);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

}

Serial.println();

Serial.println("WiFi connected");

3

Serial.println("IP address: "); Serial.println(WiFi.localIP());

// Setup MQTT subscription for onoff feed.

mqtt.subscribe(&Light1);

mqtt.subscribe(&Fan1);

mqtt.subscribe(&AC);

mqtt.subscribe(&motion);

}

uint32_t x = 0;

void loop() {

// Ensure the connection to the MQTT server is alive (this will

make the first

MQTT_connect();

// this is our 'wait for incoming subscription packets' busy

subloop

Adafruit_MQTT_Subscribe *subscription;

while ((subscription = mqtt.readSubscription(20000))) {

if (subscription == &Light1) {

Serial.print(F("Got: "));

Serial.println((char *)Light1.lastread);

3

int Light1_State = atoi((char *)Light1.lastread);

digitalWrite(Relay1, Light1_State);

}

if (subscription == &Fan1) {

Serial.print(F("Got: "));

Serial.println((char *)Fan1.lastread);

int Light2_State = atoi((char *)Fan1.lastread);

digitalWrite(Relay2, Light2_State);

}

if (subscription == &AC) {

Serial.print(F("Got: "));

Serial.println((char *)AC.lastread);

int Fan1_State = atoi((char *)AC.lastread);

digitalWrite(Relay3, Fan1_State);

}

}

// Now we can publish stuff!

int motion_State = digitalRead(analogpin);

if (subscription == &motion) {

21

Serial.print(F("Got: "));

Serial.println((char *)motion.lastread);

int motion_State = atoi((char *)motion.lastread);

if (motion_State==HIGH){

digitalWrite(buzzer, motion_State);

delay(100000);

digitalWrite(buzzer, LOW);

}

}

}

if(! mqtt.ping()) {

mqtt.disconnect();}

void MQTT_connect()

{

int8_t ret;

if (mqtt.connected()) {

return;

}

Serial.print("Connecting to MQTT... ");

21

uint8_t retries = 3;

digitalWrite(buzzer, HIGH);

delay(200);

digitalWrite(buzzer, LOW);

delay(200);

digitalWrite(buzzer, HIGH);

delay(200);

digitalWrite(buzzer, LOW);

delay(200);

while ((ret = mqtt.connect()) != 0) { // connect will return 0 for

connected

Serial.println(mqtt.connectErrorString(ret));

Serial.println("Retrying MQTT connection in 5 seconds...");

mqtt.disconnect();

delay(5000); // wait 5 seconds

retries--;

if (retries == 0) {

while (1);

}

24

}

Serial.println("MQTT Connected!");

digitalWrite(buzzer, HIGH);

delay(2000);

digitalWrite(buzzer, LOW);

}