You are on page 1of 46

PROJECT REPORT ON

ChatGPT WhatsApp chatbot using Python,


Twilio, and AWS EC2.

Submitted to

Department of Computer Applications

for Completion of Semester 5

Bachelor of Science in Information Technology

Batch (2021-2024)

Submitted by

Name of the student: Vashu Vashi

Enrollment Number: GE-21220758

Under the Guidance of

DR. Anmol Chaudary

GRAPHIC ERA DEEMED TO BE UNIVERSITY DEHRADUN


CANDIDATE’S DECLARATION
I hereby certify that the work presented in this project report entitled
“ ” in partial fulfilment of
the requirements for the award of the degree of Master of Computer Applications is a
Bonafede work carried out by me during the period of January 2020 to June 2020 under the
supervision of , Department of Computer Application, Graphic Era
Deemed to be University, Dehradun, India.

This work has not been submitted elsewhere for the award of a degree/diploma/certificate.

Name and Signature of Candidate

This is to certify that the above-mentioned statement in the candidate’s declaration is correct
to the best of my knowledge.

Date: Name and Signature of Guide

Signature of Supervisor Signature of External Examiner

HOD

ii
Acknowledgement

A student of a university will have to write the acknowledgement for their project or research
paper stating that the submission is done and is not copied. The acknowledgement sample for
the university project is mostly attached after the dedication page thanking all the faculty
members of the department, HOD, the Dean and the mentor.

I would like to express my profound gratitude to Mr. Sanjiv Chauhan Sir, HOD Computer
Application department(UG).

I would like to express my special thanks to my mentor Mr Anmol Chaudary Purohit for his
time and efforts he/she provided throughout the year. Your useful advice and suggestions
were really helpful to me during the project’s completion. In this aspect, I am eternally
grateful to you.

I would like to acknowledge that this project was completed entirely by me and not by
someone else.

Candidate Name and Signature


Table of Contents

Candidate’s Declaration ii
Acknowledgement iii
s
Table of Contents iv
Abstract v
Chapter1. 1

1.1 Introduction 1

1.2 Background 2

1.3 Project Objective 2

1.3.1 Scope 3

Chapter 2. Prerquisites 5

Chapter 3. Building the ChatGPT WhatsApp Chatbot 19

Chapter 4. Deploying on 32
AWS EC2

Enhancements and Customizations


Chapter 5. 37

Chapter 6. Conclusion 40

iii
ABSTRACT
This project presents the overall design of Home Automation System (HAS) with low cost
and wireless system. It specifically focuses on the development of an IOT based home
automation system that is able to control various components via internet or be automatically
programmed to operate from ambient conditions. In this project, we design the development
of a firmware for smart control which can successfully be automated minimizing human
interaction to preserve the integrity within whole electrical devices in the home. We used
Node MCU, a popular open source IOT platform, to execute the process of automation.
Different components of the system will use different transmission mode that will be
implemented to communicate the control of the devices by the user through Node MCU to
the actual appliance. The main control system implements wireless technology to provide
remote access from smart phone. We are using a cloud server-based communication that
would add to the practicality of the project by enabling unrestricted access of the appliances
to the user irrespective of the distance factor. We provided a data transmission network to
create a stronger automation. The system intended to control electrical appliances and devices
in house with relatively low cost design, user-friendly interface and ease of installation. The
status of the appliance would be available, along with the control on an android platform.
This system is designed to assist and provide support in order to 1fulfil the needs of elderly
and disabled in home. Also, the smart home concept in the system improves the standard
living at home.

v
Chapter 1

Introduction
1.1 Introduction

Integrating ChatGPT with WhatsApp has revolutionized the way we interact


with chatbots. Leveraging the powerful capabilities of ChatGPT, developers
can create intelligent and context-aware chatbots that offer a more natural and
human-like conversation experience on the popular messaging platform.

By combining the advanced language understanding of ChatGPT with the


widespread usage of WhatsApp, users can engage in meaningful conversations
with chatbots for various purposes, from answering queries to providing
personalized assistance. This integration opens up new possibilities for
businesses, developers, and individuals looking to enhance their
communication strategies.

As seen in recent developments, major tech companies like Meta are adopting
ChatGPT-style AI chatbots for platforms like WhatsApp, Instagram, and
Facebook. This indicates a growing trend towards utilizing advanced language
models to improve user interactions and provide more sophisticated services
within messaging applications.

For developers interested in building their own ChatGPT-powered WhatsApp


chatbots, there are comprehensive guides available to walk through the
integration process in a few easy steps. This technology not only enhances user
engagement but also showcases the potential of combining natural language
processing with widely-used messaging services.

1
1.2 Background

The ever-evolving landscape of conversational AI, integrating chatbots with


popular messaging platforms has become a pivotal avenue for enhancing
user engagement and support. One notable instance is the implementation of
ChatGPT, a state-of-the-art language model developed by OpenAI, into
WhatsApp, one of the world's most widely used messaging applications.
ChatGPT, developed by OpenAI, integrates with WhatsApp, bringing
advanced AI to messaging platforms. This setup involves deploying
ChatGPT on AWS EC2, creating a Flask API, and ensuring smooth testing
and troubleshooting for reliable user interactions. This integration reflects
the evolution of AI-driven chatbots, enhancing communication for
businesses and users alike.

1.3 PROJECT OBJECTIVES

Integration with WhatsApp


Forge a seamless interaction channel, integrating ChatGPT with WhatsApp
to enable users to engage effortlessly via the messaging platform. Ensure a
smooth conversational experience.

AWS EC2 Deployment


Employ Amazon EC2 services for deploying the project, focusing on
efficient scaling, high availability, and accessibility. Establish a reliable
infrastructure on the AWS cloud.
Flask API Creation
Construct a robust Flask-based API to facilitate communication between ChatGPT
and WhatsApp. Enable effective data exchange and interaction through a well-
structured interface.
24/7 Availability
Design and implement a resilient system architecture on AWS EC2,
guaranteeing continuous availability. Provide users with uninterrupted
service, emphasizing a reliable and responsive platform
2
Testing and Troubleshooting
Conduct comprehensive testing procedures to ensure functionality and
user satisfaction. Implement effective troubleshooting mechanisms to
promptly address any issues that may arise, ensuring a seamless user
experience.

1.3.1 SCOPE

TThe project aims to create a dynamic WhatsApp Chatbot using ChatGPT,


providing users with an interactive and intelligent conversational experience.
The scope encompasses the development of a robust infrastructure on AWS EC2,
ensuring scalability and reliability. The Flask-based API will serve as the
communication bridge between ChatGPT and WhatsApp, facilitating seamless
interactions. The project's focus extends to defining availability metrics,
establishing downtime parameters, and implementing strategies to maintain
uninterrupted service. A comprehensive testing framework will be employed to
validate system functionality, emphasizing proactive troubleshooting and issue
resolution. Overall, the project seeks to deliver an efficient and user-friendly
ChatGPT-powered WhatsApp Chatbot, leveraging AWS capabilities and best
practices in API development.

3
Chapter 2

Prerequisites

2.1 I Setting up Twilio Account


Commence the project journey by establishing a comprehensive Twilio account
Twilio, a leading cloud communications platform, plays a pivotal role in integrating
essential communication functionalities into the WhatsApp Chatbot. Dive into the
account creation process, exploring the array of features and settings to tailor the
platform to your project needs.

2.1.1 AWS EC2 Instance Configuration:

Embark on the intricacies of configuring an Amazon EC2 instance on AWS. This


pivotal step involves creating a virtual server explicitly designed for hosting and
4
executing the WhatsApp Chatbot. Delve into the nuances of AWS EC2, ensuring
meticulous security group configurations are in place to fortify the environment
against potential threats and allowing seamless external access.

5
6
2.1.2 C
IOT encourages the communication between devices, also famously known as
Machine-to-Machine(M2M) communication. Because of this, the physical devices
can stay connected and hence the total transparency is available with lesser
inefficiencies and greater quality.
Automation and Control
Due to physical objects getting connected and controlled digitally and centrally
with wireless infrastructure, there is a large amount of automation and control in
the workings. Without human intervention, the machines are able to
communicate with each other leading to faster and timely output.
Monitor
The second most obvious advantage of IOT is monitoring. Knowing the exact
quantity of supplies or the air quality in your home, can further provide more
information that could not have previously been collected easily. For instance,
knowing that you are low on milk or printer ink could save you another trip to the
store in the near future. Furthermore, monitoring the expiration of products can
and will improve safety.
Time
As hinted in the previous examples, the amount of time saved because of IOT
could be quite large.And in today’s modern life, we all could use more time.
Money
The biggest advantage of IOT is saving money. If the price of the tagging and
monitoring equipmentis less than the amount of money saved, then the Internet of
Things will be very widely adopted.
IOT fundamentally proves to be very helpful to people in their daily routines by
making the appliances communicate to each other in an effective manner thereby
saving and conserving energy and cost. Allowing the data to be communicated
and shared between devices and thentranslating it into our required way, it makes
our systems efficient.
Automation of daily tasks leads to better monitoring of devices.

7
The IOT allows you to automate and control the tasks that are done on a daily
basis, avoiding human intervention. Machine-to-machine communication helps to
maintain transparency in the processes. It also leads to uniformity in the tasks. It
can also maintain the quality of service. We canalso take necessary action in case
of emergencies.
Efficient and Saves Time
The machine-to-machine interaction provides better efficiency, hence; accurate
results can be obtained fast. This results in saving valuable time. Instead of
repeating the same tasks every day, itenables people to do other creative jobs.
Saves Money
Optimum utilization of energy and resources can be achieved by adopting this
technology andkeeping the devices under surveillance. We can be alerted in case
of possible bottlenecks, breakdowns, and damages to the system. Hence, we can
save money by using this technology.
Better Quality of Life
All the applications of this technology culminate in increased comfort, convenience, and
bettermanagement, thereby improving the quality of life.

2.1.3 Disadvantages of IOT


Compatibility
Currently, there is no international standard of compatibility for the tagging and
monitoring equipment. I believe this disadvantage is the easiest to overcome. The
manufacturing companiesof these equipment just need to agree to a standard,
such as Bluetooth, USB, etc. This is nothing new or innovative needed.
Complexity
As with all complex systems, there are more opportunities of failure. With the
Internet of Things, failures could skyrocket. For instance, let’s say that both you
and your spouse each get a message saying that your milk has expired, and both
of you stop at a store on your way home, and you both purchase milk. As a result,
you and your spouse have purchased twice the amount that you both need. Or

8
maybe a bug in the software ends up automatically ordering a new ink cartridge
for your printer each and every hour for a few days, or at least after each power
failure, when you only needa single replacement.
Privacy/Security
With all this IOT data being transmitted, the risk of losing privacy increases. For
instance, howwell encrypted will the data be kept and transmitted with? Do you
want your neighbors or employers to know what medications that you are
taking or your financial situation?
Safety
Imagine if a notorious hacker changes your prescription. Or if a store
automatically ships you an equivalent product that you are allergic to, or a flavor
that you do not like, or a product that is already expired. As a result, safety is
ultimately in the hands of the consumer to verify allautomation.
As all the household appliances, industrial machinery, public sector services like
water supply and transport, and many other devices all are connected to the
Internet, a lot of information is availableon it. This information is prone to attack
by hackers. It would be very disastrous if private and confidential information is
accessed by unauthorized intruders.
Lesser Employment of Menial Staff
The unskilled workers and helpers may end up losing their jobs in the effect of
automation of daily activities. This can lead to unemployment issues in the society. This
is a problem with the advent ofany technology and can be overcome with education.
With daily activities getting automated, naturally, there will be fewer requirements of
human resources, primarily, workers and less educated staff. This may create
Unemployment issue in the society.

9
2.2 Application Grounds of

IOT Wearables

Wearable technologies are a hallmark of IOT applications and is one of the


earliest industries to have deployed IOT at its services. Fit Bits, heart rate
monitors, smartwatches, glucose monitoring devices reflect the successful
applications of IOT.

Smart homes

This area of application concerned to this project, so a detailed application is


discussed further. Jarvis, an AI home automation employed by Mark Zuckerberg,
is a remarkable example in this field of application.

Health care

IOT applications have turned reactive medical based system into proactive
wellness-based system. IOT focuses on creating systems rather than equipment.
IOT creates a future of medicine and healthcare which exploits a highly integrated
network of sophisticated medical devices. The integration of all elements provides
more accuracy, more attention to detail, faster reactions to events, and constant
improvement while reducing the typical overhead of medical research and
organizations.

Agriculture
A greenhouse farming technique enhances the yield of crops by controlling
environmental parameters. However, manual handling results in production loss,
energy loss, and labor cost, making the process less effective. A greenhouse with
embedded devices not only makes it easier tobe monitored but also, enables us to
control the climate inside it. Sensors measure different.

10
2.2.1 IOT Technologies and
Protocols Bluetooth

Bluetooth is a short range IOT communication protocol/technology that is


profound in many consumer product markets and computing. It is expected to be
key for wearable products in particular, again connecting to the IOT albeit
probably via a smartphone in many cases. The new Bluetooth Low-Energy (BLE)
– or Bluetooth Smart, as it is now branded – is a significant protocol for IOT
applications. Importantly, while it offers a similar range to Bluetooth it has been
designed to offer significantly reduced power consumption.

Zigbee

ZigBee is similar to Bluetooth and is majorly used in industrial settings. It has


some significant advantages in complex systems offering low-power operation,
high security, robustness and high and is well positioned to take advantage of
wireless control and sensor networks in IOT applications. The latest version of
ZigBee is the recently launched 3.0, which is essentially the unification of the
various ZigBee wireless standards into a single standard.

Z-Wave

Z-Wave is a low-power RF communications IOT technology that primarily design


for home automation for products such as lamp controllers and sensors among
many other devices. A Z- Wave uses a simpler protocol than some others, which
can enable faster and simpler development, but the only maker of chips is Sigma
Designs compared to multiple sources for other wireless technologies such as
ZigBee and others.

Wi-Fi

Wi-Fi connectivity is one of the most popular IOT communication protocol, often
an obvious choicefor many developers, especially given the availability of Wi-Fi
within the home environment within LANs. There is a wide existing
infrastructure as well as offering fast data transfer and the ability to handle high

1
1
quantities of data. Currently, the most common Wi-Fi standard used in homes and
many businesses is 802.11n, which offers range of hundreds of megabit per
second, which is fine for file transfers but may be too power-consuming for many
IOT applications.
Cellular
Any IOT application that requires operation over longer distances can take
advantage of GSM/3G/4G cellular communication capabilities. While cellular is
clearly capable of sending high quantities of data, especially for 4G, the cost and
also power consumption will be too high for manyapplications. But it can be ideal
for sensor-based low-bandwidth-data projects that will send very low amounts of
data over the Internet.
NFC
NFC (Near Field Communication) is an IOT technology. It enables simple and
safe communicationsbetween electronic devices, and specifically for smartphones,
allowing consumers to perform transactions in which one does not have to be
physically present. It helps the user to access digitalcontent and connect electronic
devices. Essentially it extends the capability of contactless card technology and
enables.

Lora WAN

is one of popular IOT Technology, targets wide-area network (WAN)


applications. The Lora WAN design to provide low-power WANs with features
specifically needed to support low-cost mobile secure communication in IOT,
smart city, and industrial applications. Specifically meets requirements for low-
power consumption and supports large networks with millions and millions of
devices, data rates range from 0.3 kbps to 50 kbps.

12
IOT software

IOT software addresses its key areas of networking and action through platforms,
embedded systems, partner systems, and middleware. These individual and
master applications are responsible for data collection, device integration, real-
time analytics, and application and process extension within the IOT network.
They exploit integration with critical business systems (e.g., ordering systems,
robotics, scheduling, and more) in the execution of related tasks.

Data Collection

This software manages sensing, measurements, light data filtering, light data
security, and aggregation of data. It uses certain protocols to aid sensors in
connecting with real-time, machine- to-machine networks. Then it collects data
from multiple devices and distributes it in accordance with settings. It also works
in reverse by distributing data over devices. The system eventually transmits all
collected data to a central server.

Device Integration

Software supporting integration binds (dependent relationships) all system devices


to create the body of the IOT system. It ensures the necessary cooperation and
stable networking between devices. These applications are the defining software
technology of the IOT network because without them, it is not an IOT system.
They manage the various applications, protocols, and limitations of each device to
allow communication.

Real-Time Analytics

These applications take data or input from various devices and convert it into
feasible actions or clear patterns for human analysis. They analyse information
based on various settings and designsin order to perform automation-related tasks
or provide the data required by industry.

1
3
2.2.2 Application and Process Extension

These applications extend the reach of existing systems and software to allow a
wider, more effective system. They integrate predefined devices for specific
purposes such as allowing certain mobile devices or engineering instruments
access. It supports improved productivity and more accurate data collection.

2.2.3 NODE MCU

NodeMCU (Node Microcontroller Unit) 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.

Figure 1. Node MCU Development Board.

NodeMCU is an open source firmware for which open source prototyping board
designs are available. The name “NodeMCU” combines “node” and “MCU”
(micro-controller unit). The term “NodeMCU” strictly speaking refers to the
firmware rather than the associated development kits.

Both the firmware and prototyping board designs are open source.

14
The firmware uses the Lua scripting language. The firmware is based on the eLua
project and built on the Espressif Non-OS SDK for ESP8266. It uses many
open source projects, such as lua- cjson and SPIFFS. Due to resource
constraints, users need to select the modules relevant for their project and build a
firmware tailored to their needs. Support for the 32-bit ESP32 has also been
implemented.

The prototyping hardware typically used is a circuit board functioning as a dual in-
line package (DIP) which integrates a USB controller with a smaller surface-
mounted board containing the MCU and antenna. The choice of the DIP format
allows for easy prototyping on breadboards. The design was initially was based
on the ESP-12 module of the ESP8266, which is a Wi-Fi SoC integrated with
a Tensilica Xtensa LX106 core, widely used in IOT applications.

Pin Configuration of Node MCU Development Board

This module provides an access to the GPIO subsystem. All the access is based on
I/O index number of Node MCU kits, not the internal GPIO pins. For example, the
D0 pin on the development kit is mapped to GPIO pin 16. Node MCU provides
access to the GPIO pins, and the following pin mappingtable is a part of the API
documentation.

1
5
2.4 Installation of Node MCU
Mostly these days devices download and install drivers on their own,
automatically. Windows doesn’t know how to talk to the USB driver on the Node
MCU so it can’t figure out that the board is a Node MCU and proceed normally.
Node MCU Amica is an ESP8266 Wi-Fi module based development board. It has
got Micro USB slot that can directly be connected to the computer or other USB
host devices. Ti has got 15X2 header pins and a Micro USB slot, the headers can
be mounted on a breadboard and Micro USB slot is to establish connection to USB
host device. It has CP2120 USB to serial converter. In order to install CP2120
(USB to serial converter), user is needed to download thedriver for the same. Once
user downloads drivers as per its respective operating system, the system
establishes connection to Node MCU. The user needs to node down the COM post
allotted to newlyconnected USB device (Node MCU) from device manager of the
system. This com port number will be required while using Node MCU Amica. As
the CP2120 driver has been installed, the Node MCU can be programmed using
Arduino IDE software by coding in embedded C. this requires ESP8266 board
installation in Arduino IDE from board manager, and assigning communication
port.

16
BLOCK DIAGRAM

Figure 2. Block diagram


The block diagram gives the functionality of the overall project. The Node MCU
unit is the microcontroller or the main controlling unit of the system. The user uses
the mobile application in setting commands for functioning of the appliances. The
mobile application interprets the command form in user in voice or switch mode
and sends signal to the Node MCU unit, over a wireless network established by
Wi- Fi communication. Hence the Wi-Fi module (actually inbuilt into Node
MCU), helps the microcontroller establish Wi-Fi communication with a device
and take commands from an application over wireless network. The Node MCU
on further receiving the signal then turns on/off the appliance with the help of
relay. The Node MCU, relay and the final appliances are physically connected.
There is a power supply unit that powers the microcontroller, the relay as well as
the final appliances. There is also a display unit that displays the status of the
application.

1
7
Proposed system
The android OS provides the flexibility of using the open source. The inbuilt
sensors can be accessedeasily. The application used to control the system has the
following features. Android Phone acts as a client and data are sent via sockets
programming. The application takes command from user in twodifferent modes.

Switch mode: Switch mode uses the radio buttons that are used to control the
home appliances. The radio button sends the status of the switch.

Voice mode: Voice Mode is used to control the home appliances using voice
command. Usingthe inbuilt microphone of Smartphone, the application creates an
intent that fetches the speech data to the Google server which responds with a
string data. The string data are further analysed and then processed.

More detailed discussion about the modes of control and how they actually control the
system isdiscussed if coming chapters.

18
CHAPTER 3

Hardware and Setup

3.1 MAIN FEATURES OF THE PROTOTYPE

The features of the developed prototype are:

The prototype establishes a wireless remote switching system of home appliances.

The prototype uses Wi-Fi to establish wireless control, which gives an indoor
range to about150 feet.

The command to switch on and off an appliance can be given from radio
buttons on theapplication from one’s smartphone.

There is also a provision developed to use voice commands on smartphone to


remotelyswitch home appliances

Any device capable of Wi-Fi connectivity can be used to control the prototype.

The control over home appliances is obtained over secure connections, by SSL over TCP,
SSH.

Simple design easy to integrate into a verity of appliances and extend on further range.

Displays the status of each appliances on the application in smartphone

Cost effective.

1
9
3.2 Google Firebase

The Firebase Realtime Database is a cloud-hosted NoSQL database provided by Google.


It allows developers to store and synchronize data in real-time across multiple clients. The
database is built on a hierarchical JSON-like structure, which enables efficient data
storage and retrieval. Realtime updates ensure that changes made to the database are
immediately reflected across all connected clients. It provides seamless data
synchronization across web, mobile, and server platforms. The Realtime Database
supports offline capabilities, allowing clients to access and modify data even when
offline. When the device reconnects, the database automatically synchronizes the changes
with the server. The database provides client-side SDKs for various platforms, including
Android, iOS, and web. It offers simple and powerful APIs for reading and writing data,
making it easy to integrate into applications. The Firebase Realtime Database uses
WebSockets for real-time communication between clients and the server. It ensures
efficient and low-latency data synchronization. The database allows developers to define
security rules to control access to the data. These rules can be customized based on
specific user roles and permissions. It provides a scalable and reliable infrastructure,
handling data storage and synchronization at scale. The Realtime Database supports
automatic scaling, ensuring optimal performance for applications with varying user loads.
It offers built-in data validation and synchronization, reducing the need for manual error
handling and conflict resolution. The database supports transactions, allowing developers
to perform atomic operations on data. Transactions ensure data integrity and consistency
in multi-client environments. It provides listeners and event-based triggers to receive real-
time updates when data changes. Developers can subscribe to specific data paths and
receive notifications when changes occur. The Realtime Database supports indexing and
querying of data, enabling efficient data retrieval. It allows sorting, filtering, and
searching of data based on specific criteria. The database supports nested and complex
data structures, enabling flexible data modeling. Developers can create relationships
between data nodes for better organization and retrieval. The Realtime Database offers a
scalable and cost-effective solution, with a free tier available for small-scale applications.
It seamlessly integrates with other Firebase services, such as Authentication, Cloud
Functions, and Cloud Messaging. The database can be used in a wide range of
20
applications, including chat apps, collaborative tools, and real-time analytics. It provides
strong data consistency guarantees, ensuring that clients always see the most up-to-date
data. The Realtime Database supports backups and data restoration, providing data
durability and resilience. It offers a graphical interface, the Firebase console, for
managing and monitoring the database. The console allows developers to view and edit
data, monitor usage, and configure security rules. The Realtime Database provides
analytics and insights into user engagement and behavior. Developers can track and
analyze data changes, user interactions, and performance metrics. It supports data export
and import, facilitating data migration and backups. The database allows data sharing and
collaboration between different Firebase projects. Developers can securely share data
across different applications and environments. The Realtime Database offers SDKs and
client libraries in multiple programming languages, providing flexibility for developers.

3.2.1 Integrate Firebase with ESP8266

Set up Firebase Project:

Go to the Firebase Console (console.firebase.google.com) and create a new project.

Enable the Realtime Database feature for your project.

Configure Firebase Realtime Database:

In the Firebase Console, navigate to the Realtime Database section.

Set up the database rules to define read and write permissions.

Take note of your Firebase project's credentials, including the database URL.

Set up ESP8266:

Connect the ESP8266 module to your computer.

Install the Arduino IDE (if not already installed) and open it.

2
1
Go to "File" -> "Preferences" and enter the following URL in the "Additional Boards
Manager URLs" field:
"http://arduino.esp8266.com/stable/package_esp8266com_index.json".

Go to "Tools" -> "Board" -> "Boards Manager" and search for "esp8266". Install the
"esp8266" board package.

Select the appropriate ESP8266 board from the "Tools" -> "Board" menu.

Install Required Libraries:

In the Arduino IDE, go to "Sketch" -> "Include Library" -> "Manage Libraries".

Search and install the following libraries:

Firebase ESP8266

ArduinoJson

ESP8266WiFi

ESP8266HTTPClient

Set up Wi-Fi Credentials:

In your Arduino sketch, include the necessary libraries:

include <ESP8266WiFi.h> include <FirebaseESP8266.h>

Set up your Wi-fi

const char "Your WiFi SSID" const char "Your WiFi


Password"

Configure Firebase Credentials:

22
In the Arduino sketch, include Firebase and define Firebase credentials:

include <FirebaseESP8266.h> define "your-


project.firebaseio.com" define "your-auth-token"

Note: Replace "your-project" with your actual Firebase project name and "your-auth-token"
with the authentication token from your project's settings.

Connect to Wi-Fi:

Add the following code in your setup() function to connect to Wi-Fi:

.begin
delay 500

Initialize Firebase:

In the setup() function, initialize the Firebase object:

Firebase begin FIREBASE_HOST FIREBASE_AUTH

Reading and Writing Data:

You can now read or write data from/to Firebase using Firebase methods.

For example, to read data from a specific node:

getString "node/path"

To write data to a specific node:

setString "node/path" "data"

Upload and Run:

Connect your ESP8266 to your computer and upload the code.

2
3
Open the serial monitor to see the ESP8266's connection status and any debugging
information.

3.1.2 Source Code ESP8266:-

#include <ESP8266WiFi.h>

#include <FirebaseArduino.h>

#define FIREBASE_HOST "node-3c895-default-rtdb.asia-


southeast1.firebasedatabase.app"

#define FIREBASE_AUTH "jCzEbGd2M2PAeiiCU2a4dzo4Y7h5PtWsT3fxl2QM"

#define WIFI_SSID "Anshgujral"

#define WIFI_PASSWORD "ansh1234"

String fireStatus = "";

int led = 5;

int fan=4;

void setup()

Serial.begin(9600);

delay(1000);

pinMode(led, OUTPUT);

pinMode(fan,OUTPUT);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to ");

24
Serial.print(WIFI_SSID);

while (WiFi.status() != WL_CONNECTED)

Serial.print(".");

delay(500);

Serial.println();

Serial.print("Connected to ");

Serial.println(WIFI_SSID);

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

Firebase.setString("LED_STATUS", "OFF");

Firebase.setString("FAN_STATUS", "OFF");

void loop()

fireStatus = Firebase.getString("LED_STATUS");

if (fireStatus == "OFF")

Serial.println("Led Turned OFF");

delay(1000);

digitalWrite(led, HIGH);

2
5
}

else if (fireStatus == "ON")

Serial.println("Led Turned on");

delay(1000);

digitalWrite(led, LOW);

else

Serial.println("Command Error! Please send ON/OFF");

fireStatus = Firebase.getString("FAN_STATUS");

if (fireStatus == "OFF")

Serial.println("fan Turned OFF");

delay(1000);

digitalWrite(fan, HIGH);

else if (fireStatus == "ON")

Serial.println("fan Turned ON");

delay(1000);
26
digitalWrite(fan, LOW);

else

Serial.println("Command Error! Please send ON/OFF");

3.1.3 Integrating Firebase With Android Studio

Set up Firebase Project:

Go to the Firebase Console (console.firebase.google.com) and create a new project.

Register your Android app with Firebase by providing the package name and SHA-1
fingerprint.

Add Firebase to Android Studio Project:

In Android Studio, open your project.

In the Project view, right-click on the app module and select "Open Module Settings" (F4).

Click on the "Dependencies" tab, then the "+" button, and choose "Library Dependency".

Search for "firebase" and select the desired Firebase libraries to include in your project.

Click "OK" to add the dependencies.

Download and Sync Configuration Files:

In the Firebase Console, navigate to your project's settings.

Click on the "google-services.json" download button to obtain the configuration file for your
Android app.

Move the downloaded file to the "app" module of your Android project.

2
7
In your project's build.gradle file (project-level), add the following classpath dependency:

'com.google.gms:google-services:4.3.10'

In your app's build.gradle file (module-level), add the following plugins and apply plugin:

'com.google.gms.google-services'

Sync your project to apply the changes.

Use Firebase Services in your Android App:

Depending on the Firebase services you want to use, you may need to add additional
dependencies or configurations.

For example, to use Firebase Authentication, add the following dependency:

'com.google.firebase:firebase-auth:21.0.1'

Follow the documentation and guides provided by Firebase to integrate and use specific
services in your app.

Initialize Firebase in your app's main Application class or MainActivity:

this

Test and Run:

Ensure that your Android device or emulator is connected and running.

Build and run your Android app from Android Studio.

Monitor the logs and verify the Firebase integration by checking the Firebase Console for
data updates and events.

Remember to follow the Firebase documentation and specific guides for each Firebase
service you want to integrate. Each service may have additional steps, such as configuration,
authentication setup, and API usage.

Android (JAVA) Source Code:

package com.example.myhomeapp;

28
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import com.google.firebase.database.DatabaseReference;

import com.google.firebase.database.FirebaseDatabase;

public class MainActivity extends AppCompatActivity {

Button b1,b2,b3,b4;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

b1=findViewById(R.id.button3);

b2=findViewById(R.id.button4);

b3=findViewById(R.id.button5);

b4=findViewById(R.id.button6);

final FirebaseDatabase database = FirebaseDatabase.getInstance();

b1.setOnClickListener(new View.OnClickListener() {

@Override

2
9
public void onClick(View view) {

// Write a message to the database

DatabaseReference LED = database.getReference("LED_STATUS");

LED.setValue("ON");

});

b2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// Write a message to the database

DatabaseReference LED = database.getReference("LED_STATUS");

LED.setValue("OFF");

});

b3.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// Write a message to the database

DatabaseReference FAN = database.getReference("FAN_STATUS");

30
FAN.setValue("ON");

});

b4.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// Write a message to the database

DatabaseReference FAN = database.getReference("FAN_STATUS");

FAN.setValue("OFF");

});

3
1
Chapter 4

Testing

4.1 TYPES OF TESTING

UNIT TESTING

Unit testing includes the plan of experiments that approve that the inner program rationale is
working legitimately and that program inputs produce substantial yields. All decision
branches and interior code stream ought to be approved. It is the trying of person
programming units of the application .it is done after the fruition of an individual unit prior to
incorporation. This is basic testing, that depends on information about its construction and is
obtrusive. Unit tests perform fundamental tests at part level and test a particular business
procedure, application, or potentially framework setup. Unit tests guarantee that each one of a
kind way of a business procedure performs precisely to the archived determinations also,
contains obviously characterized data sources and anticipated outcomes.

INTEGRATION TESTING

Combination tests are intended to test incorporated programming parts to decide whether they
really keep running as one program. Testing is occasion driven and is progressively
Concerned with the fundamental result of screens or fields. Mix tests exhibit that despite the
fact that the parts were separately fulfillment, as appeared by effectively unit testing, the mix
of parts is right and steady. Coordination testing is explicitly gone for uncovering the issues
that emerge from the mix of segments.

FUNCTIONAL TESTING

Blend tests are planned to test fused programming parts to choose whether they truly continue
running as one program. Testing is event-driven and is dynamically Concerned with the
major aftereffect of screens or fields. Blend tests show that regardless of the way that the
parts were independently satisfaction, as showed up by adequately unit testing, the blend of
32
parts is correct and unfaltering. Coordination testing is unequivocally gone for revealing the
issues that rise up out of the blend of portions.

SYSTEM TESTING

Framework testing guarantees that the whole incorporated programming framework meets
necessities. It tests an arrangement to guarantee known and unsurprising outcomes. A case of
framework testing is the setup situated framework incorporation test. Framework testing
depends on process portrayals and streams, accentuating pre-driven procedure connections
and combination focuses.

WHITEBOX TESTING

White Box Testing is a trying in which the product analyzer knows about the inward
activities, structure, and language of the product, or possibly its motivation. It is the reason. It
is utilized to test zones that can't become to from a discovery level

BLACK BOX TESTING

Discovery Testing will be trying the product with no learning of the inward functions,
structure or language of the module being tried. Discovery tests, as most different sorts of
tests, must be composed of a conclusive source report, for example, particular or necessities
report, for example, particular or prerequisites record. It is a trying in which the product
under test is dealt with, as a discovery you can't "see" into it. The test gives data sources and
reacts to yields without thinking about how the product works.

INTEGRATION TESTING

Programming joining testing is the gradual combination testing of at least two integround
programming segments on a solitary stage to create disappointments brought about by
interface abandons. The undertaking of the mixed test is to watch that parts or programming
applications, e.g: segments in a product framework or – one stage up – programming
applications at the organization level – associate without mistake.

3
3
ACCEPTANCE TESTING

Client Acceptance Testing is a basic period of any task and requires huge standard ticipation
by the end client. It additionally guarantees that the framework meets the practical
requirements.

ALPHA TESTING

In programming improvement, alpha test will be a test among the groups to affirm that your
item works. Initially, the term alpha test implied the main period of testing in a product
improvement process. The primary stage incorporates unit testing, part testing, and
framework testing. It additionally empowers us to test the item on the most reduced normal
denominator machines to ensure download times are satisfactory and preloads work.

BETA TESTING

In programming improvement, a beta test is the second period of programming testing in


which an examining of the target group attempts the item out. Beta testing can be considered
∧ quot; pre-discharge testing. Beta test variants of programming are currently dispersed to
educational programs authorities and educators to give the program a ∧ quot; genuine world
∧ amount; test. 37 C

4.2 Testing Methodology

Define a set of test cases to cover different functionalities and scenarios of the project.

Create a test plan that outlines the objectives, test cases, and expected outcomes.

Perform functional testing to verify that all features and components work as intended.

Conduct performance testing to evaluate the system's responsiveness, latency, and scalability.

Test the system under various network conditions, including both local and remote
connections.

34
Validate the integration between the ESP8266 hardware, Firebase Realtime Database, and the
Android application.

Document any bugs or issues encountered during testing.

4.2.1 Test Cases and Results:

Test Case 1: Wi-Fi Connection

Objective: Ensure that the ESP8266 module can establish a stable connection to the Wi-Fi
network.

Expected Result: ESP8266 successfully connects to the specified Wi-Fi network.

Actual Result: ESP8266 establishes a reliable Wi-Fi connection.

Test Case 2: Data Reading from Firebase

Objective: Verify that the ESP8266 can retrieve data from the Firebase Realtime Database.

Expected Result: ESP8266 reads the correct data from the designated Firebase database node.

Actual Result: ESP8266 successfully retrieves the expected data from Firebase.

Test Case 3: Data Writing to Firebase

Objective: Ensure that the ESP8266 can write data to the Firebase Realtime Database.

Expected Result: ESP8266 writes the specified data to the designated Firebase database node.

Actual Result: ESP8266 successfully writes data to the Firebase Realtime Database.

Test Case 4: Mobile App Integration

Objective: Validate the integration between the Android application and the ESP8266.

3
5
Expected Result: The Android app can send commands to the ESP8266 and receive real-time
updates from the device.

Actual Result: The Android application effectively communicates with the ESP8266 module.

Test Case 5: Performance and Scalability

Objective: Evaluate the system's performance and scalability under various loads.

Expected Result: The system maintains consistent performance and responsiveness, even
with multiple concurrent users and data updates.

Actual Result: The system handles increased loads and multiple users, maintaining
satisfactory performance.

36
Chapter 5

Conclusion and Future Scope

5.1 RESULT

The experimental model was made according to the circuit diagram and the results
were as expected. The home appliances could be remotely switched over Wi-Fi
network. Both the switch mode and the voice mode control methodologies were
successfully achieved. The Blynk application was also successful in displaying the
status of every application.

5.2 LIMITATIONS

Android devices having lower API version than 16 requires internet access to
convert the speech data to string data. Currently, the application is made for
Android Smart Phones; other OS platform doesn’t support our application. During
voice mode, external noises (voice) may affect our result. The speech instruction
that we command in our voice mode may not give exact result as expected. There
hence lies an ambiguity in result.

5.3 FURTHER ENHANCEMENT AND FUTURE SCOPE

Looking at the current situation we can build cross platform system that can be
deployed on various platforms like iOS, Windows. Limitation to control only
several devices can be removed by extending automation of all other home
appliances. The prototype can include sensors to implement automatic control of
the home appliances like; an LDR that can sense daylight and switch lamp
accordingly, a PIR to detect motion and be used for security purposes making an
alarm buzz, or a DHT11 sensor that’s senses ambient temperature and humidity of
atmosphere and switch fan/air conditioner accordingly. Scope of this project can
be expanded to many areas by not restricting to only home, but to small offices

3
7
CONCLUSION

It is evident from this project work that an individual control home automation
system can be cheaply made from low-cost locally available components and can
be used to control multifarious home appliances ranging from the security lamps,
the television to the air conditioning system and even the entire house lighting
system. And better still, the components required are so small and few thatthey
can be packaged into a small inconspicuous container. The designed home
automation system was tested a number of times and certified to control different
home appliances used in the lighting system, air conditioning system, home
entertainment system and many more . Hence, this system isscalable and flexible.

38
Image Representation of Project

Chapter 6
3
9
References
“Smart Energy Efficient Home Automation System using IOT”, by Satyendra K.
Vishwakarma, Prashant Upadhyaya, Babita Kumari, Arun Kumar Mishra.

“IOT Based Smart Security and Home Automation”, by Shardha Somani, Parikshit
Solunke, Shaunak Oke, Parth Medhi, Prof. P. P. Laturkar.

“A Dynamic Distributed Energy Management Algorithm of Home Sensor Network for


Home Automation System”, by Tui-Yi Yang, Chu-Sing Yang, Tien-Wen Sung; in
2016 Third International Conference on Computing Measurement Control and Sensor
Network.

“Enhance Smart Home Automation System based on Internet of Things”, by Tushar


Churasia and Prashant Kumar Jain; in Proceedings of the Third International
Conference on I-SMAC (IoTin Social, Mobile, Analytics and Cloud) (I-SMAC 2019)
IEEE Xplore Part Number:CFP19OSV- ART; ISBN:978-1-7281-4365-1

“Visual Machine Intelligence for Home Automation”, by Suraj, Ish Kool, Dharmendra
Kumar, Shovan Barman.

“A Low Cost Home Automation System Using Wi-Fi based Wireless Sensor Network
Incorporating internet of Things”, by Vikram.N, Harish.K.S, Nihaal.M.S, Raksha
Umesh, ShettyAashik Ashok Kumar; in 2017 IEEE 7th International Advance
Computing Conference.

“Voice Controlled Home Automation System using Natural Language Processing and
Internetof Things”, by Mrs. Paul Jasmin Rani, Jason Bakthakumar, Praveen
Kumaar.B, Praveen Kumaar.U, Santhosh Kumar; in 2017 Third International
Conference on Science Technology Engineering & Management (ICONSTEM)

40
Thank You

4
1

You might also like