Professional Documents
Culture Documents
BCI BASED HOME AUTOMATION SYSTEM Report PDF
BCI BASED HOME AUTOMATION SYSTEM Report PDF
Group Members
(2015-2019)
Project Supervisor:
DEPATMENT OF ENGINEERING
FACULTY OF ENGINEERING
AIR UNIVERSITY, ISLAMABAD
A Final Year Project Report
presented to
AIR University
in partial fulfillments of the requirements for
the degree of
Submitted By
2015-2019
“BRAINCOMPUTER INTERFACED
BASED HOME AUTOMATION
SYSTEM”
has met the required standard for submission
in partial fulfillments of the requirements for
the award of degree of
Bachelor of Electrical Engineering at
Air University, Islamabad
Project Supervisor
Head of Department
i
DEDICATION
We dedicate this project to
Our Parents, Teachers and Friends
ii
ABSTRACT
Brain Computer Interface Based
Home Automation System
This project has been designed for Handicapped people as well as for normal people. We want to
use the education we have gained from this degree for a good purpose and to benefit the human
beings. Our main objective is to do something to make life easier for people who cannot move on
their own. This Brain-controlled technology we used in our project is non-invasive which makes
it safe and easy to use. EEG headset used in our project senses the number of surprise facial
expression from user’s Brain and state of home appliances like fans, bulbs and AC are toggled.
The commands are taken directly from the users’ brain via the Headset and sent to the
computer/laptop to decode the command and a device is first selected and the state of this device
is then toggled. Temperature and Humidity of that particular place/room is also measured and is
displayed on an online server thingspeak.com. This is just a prototype and we can add many more
features in this project with time.
iii
Table of Contents
ACKNOWLEDGEMENT ..................................................................................................... i
DEDICATION ...................................................................................................................... ii
ABSTRACT ......................................................................................................................... iii
CHAPTER 1: INTRODUCTION ................................................................................ 1
1.1 Aims and Objectives: .................................................................................................. 1
1.2 Brain Computer Interface: .......................................................................................... 1
1.3 EEG: ............................................................................................................................ 2
1.4 Literature Review:....................................................................................................... 2
1.5 Background: ................................................................................................................ 4
1.6 Objective of Project: ................................................................................................... 5
1.7 Scope of Project: ......................................................................................................... 5
1.8 Motivation: .................................................................................................................. 5
CHAPTER 2: SYSTEM DESCRIPTION......................................................................... 6
2.1 Brain Signal Acquisition Techniques ......................................................................... 6
2.1.1 Invasive BCI ........................................................................................................ 7
2.1.2 Partially Invasive or Semi Invasive BCI .............................................................. 7
2.1.3 Non-Invasive BCI ........................................................................................... 8
2.1.3.1 Blood Flow Based Methods .......................................................................... 8
2.1.3.2 Electromagnetic Based Methods ................................................................... 8
CHAPTER 3: SYSTEM DESIGN ..................................................................................... 9
3.1 Automation of Devices ............................................................................................... 9
3.1.1 Mind-Control: ...................................................................................................... 9
3.1.2 Relays Operation: ............................................................................................... 10
3.1.3 Devices Operation: ............................................................................................. 10
3.2 External Environment Measurement and Display .................................................... 10
CHAPTER 4: EMOTIV INSIGHT HEADSET.............................................................. 11
4.1 Description: ............................................................................................................... 11
4.2 Features: .................................................................................................................... 11
4.3 Technical Specifications: .......................................................................................... 11
4.4 Sensor Software: ....................................................................................................... 11
4.4.1 EMOTIV Control Panel: .................................................................................... 12
4.4.2 EMOTIV EmoKey: ............................................................................................ 12
4.4.3 EMOTIV Composer:.......................................................................................... 13
4.5 Features Used: ........................................................................................................... 14
i
4.6 Sensors Placement: ................................................................................................... 15
4.7 Processing Methodology: .......................................................................................... 18
4.7.1 Headset: .............................................................................................................. 18
4.7.1.1 Data Acquisition: ........................................................................................ 18
4.7.1.2 Pre-Processing and Amplification: ............................................................. 18
4.7.2 Software: ............................................................................................................ 19
4.7.2.1 Feature Extraction: ...................................................................................... 19
4.7.2.2 Classification:.............................................................................................. 19
4.7.2.3 Controller: ................................................................................................... 19
4.7.2.4 Interfacing: .................................................................................................. 19
4.7.2.5 Post-Processing: .......................................................................................... 20
CHAPTER 5: SIMULATION AND MODELING .......................................................... 21
1.5 EEG Headset: ............................................................................................................ 21
5.2 Components Used: .................................................................................................... 21
5.2.1 Arduino Uno: ..................................................................................................... 21
5.2.1.1 Arduino at Client Side: ............................................................................... 23
5.2.1.1.1 Visual Representation of Client-side Arduino ..................................... 23
5.2.1.1.2 Schematic Diagram of Client-side Arduino ......................................... 24
5.2.1.2 Arduino at Relay Side: ................................................................................ 25
5.2.1.2.1 Visual Representation of Relay-side Arduino ..................................... 25
5.2.1.2.2 Schematic Diagram of Relay-side Arduino ......................................... 26
5.2.2 ESP8266 Wi-Fi Modules: .................................................................................. 27
5.2.2.1 Wi-Fi module at Client Side: ...................................................................... 28
5.2.2.2 Wi-Fi module at Client Side: ...................................................................... 29
5.2.3 TFT LCD Modules: ........................................................................................... 30
5.2.3.1 Designed Interfaced of TFT LCD Module: ................................................ 31
5.2.4 DHT22 Temperature & Humidity Sensor:......................................................... 32
CHAPTER 6: RESULTS AND CONCLUSION............................................................. 34
REFERENCES………………………………………………………………………….35
ii
Appendix A: Code for Client-side Arduino….…………………………………..…36
Appendix B: Code for Relays side Arduino …….……………………………...….46
Appendix C: Code for Client-side Wi-Fi Module.…………………………………48
Appendix D: Code for Relays side Wi-Fi Module…………………………………51
iii
List of Figures
Figure 1: Brain Computer Interface ...................................................................................... 2
Figure 2: Robotic Arm control using BCI ............................................................................ 3
Figure 3: Paralyzed woman using thought control robotic arm ............................................ 3
Figure 4: Percentage Distribution of Disabilities .................................................................. 4
Figure 5: Signal Acquisition Techniques .............................................................................. 7
Figure 6: Block Diagram....................................................................................................... 9
Figure 7.1: Emotiv Control Panel ....................................................................................... 12
Figure 8: EMOTIV EmoKey .............................................................................................. 13
Figure 10: EMOTIV Composer .......................................................................................... 14
Figure 11: EMOTIV Features ............................................................................................. 15
Figure 12: Headset Sensor .................................................................................................. 16
Figure 13: Brain Lobes ....................................................................................................... 17
Figure 14: Headset Interface ............................................................................................... 20
Figure 15: Arduino Uno Module ........................................................................................ 22
Figure 16: Arduino at Client Side ....................................................................................... 23
Figure 17: Visual Representation of Arduino at Client Side .............................................. 24
Figure 18: Schematic Diagram of Client-side Arduino ...................................................... 24
Figure 19: Arduino at Relay Side ....................................................................................... 25
Figure 20: Visual Representation of Relay-side Arduino ................................................... 26
Figure 21: Schematic Diagram of Relay-side Arduino ....................................................... 27
Figure 22: Client-side Wi-Fi Module.................................................................................. 29
Figure 23: Relay side Wi-Fi Module .................................................................................. 30
Figure 24: TFT LCD interface ............................................................................................ 32
iv
CHAPTER 1: INTRODUCTION
2. To make a Home Automation system which will make it easier for handicapped
people to control Home Appliances using brain commands.
This device and the technology behind it has a great potential for further development. It
has opened a world of possibilities for physically impaired people as there is a wide range
of possible modifications in the device according to the requirements. It is introducing a
new area of development based on BCI (Brain Computer Interface) technology. This is a
non-invasive technology which rules out the danger of further damage to the neural network.
1
Figure 1: Brain Computer Interface
1.3 EEG:
Electroencephalography (EEG) is an electrophysiological monitoring method which is
used to record change in electrical activity of the brain. This technique is noninvasive,
In this technique electrodes are placed on the surface of brain, although invasive
electrodes are used in limited applications Encephalogram measures voltage variations
resulting from electric current within the neurons of the mind. In medicine based
context, EEG refers to the transcription of the brain's spontaneous electrical activity
over a period of time, as recorded from multiple electrode placed on the scalp.
Diagnostic covering generally focus on the spectral content of EEG, that is, the type of
neural oscillations (popularly called "brain waves") that can be observed in EEG sign.
Dr. Walter (1964) explained the first BCI. He implanted electrodes directly into the
motor areas of a patient, who was being operated for some other reasons. Walter
2
observed and recorded the patient’s brain activity while the slide projector was being
operated. When patient wanted to press the button, the slide projector was advanced by
the detection ` patients.
Georgopoulos (20th century) did a detailed study and investigated the behavior of
neurons in primary motor cortex and performed experiments on monkeys to train them
to move the hand to visual targets.
Hochberg (2012) enabled a paralyzed woman to make use of thought controlled robotic arm
to reach and grasp coffee mug.
3
1.5 Background:
According to a National survey for disabled people conducted in 1984-85, the crude
disability rate in Pakistan was at 4.9% and this rate has only grown since. A survey of
disabled persons in Islamabad was also carried out in 1986 which gave an estimated rate of
2.5%.
The distribution of different disabilities in the 1986 survey for Islamabad was as follows:
There has been a rise in the devices using this new BCI (Brain Control Interface)
technology in the past few years. A brain-controlled robotic arm, a brain-controlled hand
glove for people who cannot move their fingers, and a brain-controlled wheelchair for
people who have lost mobility in their legs have been made by groups of university students.
We also want to play our part in the helping of people living with physical disabilities as
life is already difficult for them and we want to do our best job to facilitate them in any way
that we can.
4
1.6 Objective of Project:
The primary objective of this project is to develop and interface a Home Automation
System which operates with a human brain. Enabling people (especially disabled) to
communicate and control devices by mere thinking.
1.8 Motivation:
The motivation behind this project was to use our knowledge in a positive way that would
make life easier for physically impaired people.
5
CHAPTER 2: SYSTEM DESCRIPTION
Our project details a Home Automation System which will enhance the life trait of
people with serious physical infirmity by using technology of brain computer interface.
Specifically, this project is designed for the persons who feel segregated from entire
world. Segregation from people is a severe issue that anyone can face, especially for
the ones who experience these things. We tried to serve such miserable persons with
the facility of brain computer controlled System and try to develop their social network
and improvement in their personality. As we know that advancement in technology is
increasing day by day. Everyone should move with the society to reap success in life.
In the era of technology our personal and social life is reliant on gadgets that people
have developed. The Home Automation system which we are developing in our project
is not limited to the persons with physical disabilities. Healthy or common people can
also enjoy the perks of this system. People will ask questions like if we have hands and
we can control these devices using our hands then why we use brain to control them.
Answer to this question is if people have legs then why they use transport to move from
one place to other. They should use their legs instead of using transports. With the
passage of time, we have to accept the amendments done in technology to move with
our society. So, this Automation System will entertain miserable as well as healthy
people.
6
Figure 5: Signal Acquisition Techniques
7
2.1.3 Non-Invasive BCI
Non-Invasive BCI technique is the one in which electrodes are placed on the scalp.
Signals acquired by this technique are weak but this technique is regarded to be safest
when compared to other types.
8
CHAPTER 3: SYSTEM DESIGN
Our project is basically divided into two major portions. One is the Devices Automation
side and the second part is Measurement Display of External Environment. Given
below is the block diagram of our project.
3.1.1 Mind-Control:
The first part of the project is the Mind-Control part using the EEG headset. The brain
signals are gathered via the headset and then sent to the PC via Bluetooth. EMOTIV
INSIGHT will detect the EEG signals of different required commands from brain which
will be preprocessed using digital signal processing techniques and then required
features will be extracted from the given signal. Then classification of the required
features will be done based on different algorithms designed by experts of the fields. The
9
controller will detect the required signals and process it depending on the programming
and generates the demanded output.
10
CHAPTER 4: EMOTIV INSIGHT HEADSET
4.1 Description:
EMOTIV Insight is a 5-channel mobile EEG headset that records brainwaves and translates
them into meaningful data that you can understand. It is the only device in its category that
offers 5 EEG sensors and 2 reference sensors. This high spatial resolution provides in-depth
information of your brain activity. It is designed for extended use in the research, BCI (Brain
Computer Interface) and self-assessment cases.
4.2 Features:
Some features of this EMOTIV Insight Headset are:
1. Control Panel
2. Emokey
3. Composer
12
Figure 8: EMOTIV EmoKey
13
Figure 9: EMOTIV Composer
14
Figure 10: EMOTIV Features
The five sensors are placed in the 10-20 System ratio generally used for sensor
placement in headsets.
15
• 1 sensor on the Parietal Lobe
• Frontal Lobe associated with reasoning, motor skills, higher level cognition, and
expressive language
• Parietal Lobe associated with processing tactile sensory information such as
pressure, touch, and pain
16
• Temporal Lobe processes sensory input, visual processing
Temporal T
Central C
Parietal P
Occipital O
17
4.7 Processing Methodology:
Modern EEGs function by measuring the voltage fluctuations along the surface of the
scalp caused by ionic current flows within the neurons. A neuron is a cell in the brain
that transmits nerve impulses from the body. Neurons can receive different kinds of
signals from the body, either through a chemical change, such as a response from the
olfactory receptors, or from a physical change such as a touch receptor in the skin or a
light receptor in retina of eye. The signals that neuron receives causes Sodium and
Potassium ions to move across the neuron's plasma membrane, which in turn causes an
electrical current flow, which can be used to evaluate the activity of the brain, and is
therefore read directly by the EEG. The current flow is measured by electrodes on the
scalp, which operate under a standard sensitivity of 7 μ-volts/mm. The readings gathered
by these electrodes are then reported by the EEG as a measure of frequency, along
number of different consistent electrode placements. Decisions for Electrode placement
are based on number of different standards, but the most common system is the
International 10-20 system, developed in 1958 by a committee of the International
Federation of Societies for Electroencephalography and Clinical Neurophysiology. The
International 10-20 system uses anatomic landmarks on the scalp to give a consistency
of electrode placement among varying individuals.
The processing of the signal obtained from the brain is done in the following steps:
4.7.1 Headset:
4.7.1.1 Data Acquisition:
There should be a device proficient of grabbing data from brain signals and then filter
data and send it to some software to control the cursor/paddle. We use EMOTIV Insight
EEG headset to collect the date from brain. EMOTIV Insight headset has 5 channels.
4.7.2 Software:
4.7.2.1 Feature Extraction:
The process of extracting representative characteristics i.e. mean, variance, and power
spectral density (PSD) of a signal is known as feature extraction. The extracted features
are then stored as “feature vectors” and they are passed to the classifiers. This process
of feature extraction helps us to get required data and to facilitate the classification of
this data into classes of interest.
4.7.2.2 Classification:
The process of identifying patterns from the data based on statistical models built using
the training data is known as classification of signal. In this process signal are classified
into different classes by identifying their patterns from the statistical models built using
training data. It is actually done to differentiate between different brain commands. It is
done using LDA (Linear Discriminant Analysis) and comparing features from inter-
class mean and intra-class variance to differentiate between different brain signals.
4.7.2.3 Controller:
After data classification, controller gets the cleaned and filtered signal which performs
tasks according to the signal. Controller is a processor which processes the received
clean brain signal as input and generates output as per instructions installed by the user.
4.7.2.4 Interfacing:
Interfacing with any other software is done using EmoKey part of the Xavier software.
This step is done to send the brain command as a trigger for further use. Interfacing is
done by sending generated commands to Arduino serial port. Commands are generated
by EMOTIV software. Signal filtering and signal amplification is done by EMOTIV
software itself. Arduino reads commands from serial port which control further action.
19
Figure 13: Headset Interface
4.7.2.5 Post-Processing:
Based on the programming downloaded by the user in controller, controller process the
received data to detect which output should be turned on based on the brain signal
acquired by the headset. The controller makes the decision based on the input given to
the controller through serial port of Arduino, which after processing will generate the
specified output.
20
CHAPTER 5: SIMULATION AND MODELING
Activity Table
Neutral No Action
21
Figure 14: Arduino Uno Module
Some features of Arduino Uno are shown below in the following table:
Serial ports 4
22
5.2.1.1 Arduino at Client Side:
Arduino at client side is connected directly with the PC/Laptop, a TFT LCD module and
a Wi-Fi Module. This Arduino receives brain commands from EEG Headset that are
received at PC via Bluetooth, displays the data on to the TFT LCD attached directly
with it as well as sends the data to wi-Fi modules which is transferred to the relay side
Wi-Fi module via wireless communication.
23
Figure 16: Visual Representation of Arduino at Client Side
24
5.2.1.2 Arduino at Relay Side:
Arduino at relay side is connected directly with the relays, a DHT22 Temperature and
Humidity Sensor module and a Wi-Fi Module. This Arduino receives signal received at
wi-Fi module of relay side from client-side Wi-Fi module, and control the Relays ny
actuating them to ultimately control the devices attached to Relays. This Arduino also
receives data from DHT22 Temperature and Humidity sensor values and forward it to
client side via Wi-Fi, as well as displays it on to Home internet router on an online server
thingspeak.com
25
Figure 19: Visual Representation of Relay-side Arduino
26
Figure 20: Schematic Diagram of Relay-side Arduino
27
Just like two Arduino Modules, we used two Wi-Fi modules in our project. One at the
client side connected to PC and the second one at the Relay side.
28
Figure 21: Client-side Wi-Fi Module
29
Figure 22: Relay side Wi-Fi Module
Resolution 320×480
30
5.2.3.1 Designed Interfaced of TFT LCD Module:
Designed Interface of TFT LCD Module shows:
Thin-film-transistor liquid-crystal display (TFT LCD) module shows yellow circle when
the device is selected, a red circle when the selected device is in OFF state and a Green
circle when the selected device is in ON state.
Color State
31
Figure 23: TFT LCD interface
32
TFT LCF Features
33
CHAPTER 6: RESULTS AND CONCLUSION
The crucial need of every handicapped person is to enjoy the perks of life like normal people
i.e. without the support of anyone. BCI provides a promising solution for the patients who
suffer with physical challenges. The main idea was to detect the brain signals followed by
utilization of these signals to control the Home Appliances like TV, Bulbs, Fans, AC etc.
The detection of these acquired EEG signals serves as a medium for transferring
information. The device that is used for capturing EEG signal is the EMOTIV Insight
headset. The acquired brain signals are generated due to the firing of neurons in the brain.
In order to detect these electrical activities, EEG headset is placed on the scalp of patients.
The electrical activities are then transferred wirelessly to the laptop/computer for the
purpose of signal processing. After these signals are processed, useful features are extracted
and then classified according to the control thoughts/actions. On the basis of classification,
different control commands are generated by the laptop/computer and given to the control
Relays for Automation of Home Appliances. The accuracy and stability of the system
depends upon the thoughts generated by the subject, the more the training the better the
results.
34
REFERENCES
• https://www.emotiv.com/product/emotiv-insight-5-channel-mobile-eeg/#tab-
description
• https://www.researchgate.net/figure/Components-of-a-BCI-system-signals-from-
the-users-brain-are-acquired-and-processed-to_fig1_267792090
• https://cb-electronics.com/products/touch-lcd-3-5/
• http://www.mind-your-reality.com/brain_waves.html
35
Appendix A: Code for Client-side Arduino
#include <MCUFRIEND_kbv.h>
#include <SoftEasyTransfer.h>
#include <SoftwareSerial.h>
#define LCD_RESET A4
#define LCD_CS A3 // Chip Select - Analog pin 3
#define LCD_CD A2 // Command/Data - Analog pin 2
#define LCD_WR A1 // LCD Write - Analog pin 1
#define LCD_RD A0 // LCD Read - Analog pin 0
char choice;
int S1=0;
int S2=0;
int S3=0;
36
int S4=0;
MCUFRIEND_kbv tft;
struct SENSOR_DATA_STRUCTURE{
//put your variable definitions here for the data you want
to send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
float temp;
float hum;
};
SENSOR_DATA_STRUCTURE sensor_data;
struct DEVICE_DATA_STRUCTURE{
//put your variable definitions here for the data you want
to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int8_t device;
int8_t state;
};
DEVICE_DATA_STRUCTURE device_data;
38
0x00, 0x00, 0x00, 0x07, 0xfe, 0x38, 0x7f, 0xe0, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x8f, 0x01, 0xe1, 0xf0, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x03, 0x83, 0x81, 0xf0, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0x00, 0xe7, 0x00, 0xf8, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0xf8, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3e, 0x00, 0x38, 0x00, 0x7c, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7c, 0x00, 0x44, 0x00, 0x3c, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7c, 0x00, 0x01, 0x00, 0x3e, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf8, 0x01, 0xff, 0xff, 0x1f, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0x07, 0xff, 0xff, 0xdf, 0x00, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x01, 0xf0, 0x7f, 0xff, 0xff, 0xff, 0x80, 0x00,
0x3e, 0x00, 0x00,
0x00, 0x00, 0x03, 0xe1, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x7c, 0x00, 0x00,
0x00, 0x00, 0x03, 0xe7, 0xff, 0xc0, 0x00, 0x7f, 0xe0, 0x00,
0xfc, 0x00, 0x00,
0x00, 0x00, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x0f, 0xf0, 0x00,
0xfc, 0x00, 0x00,
0x00, 0x00, 0x07, 0xff, 0xc0, 0x00, 0x00, 0x01, 0xfe, 0x03,
0xf8, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xf8, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff,
0xf0, 0x00, 0x00,
0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff,
0xc0, 0x00, 0x00,
0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff,
0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0xd8, 0xbe, 0x09, 0xbc, 0x91, 0x7d, 0xf7, 0xb7,
0xb4, 0x00, 0x00,
0x00, 0x01, 0x08, 0xf3, 0x09, 0xa6, 0xd3, 0x61, 0xb3, 0x33,
0x1c, 0x00, 0x00,
0x00, 0x02, 0x2c, 0xfe, 0x09, 0xa6, 0xda, 0x7d, 0xf1, 0xb3,
0x18, 0x00, 0x00,
39
0x00, 0x00, 0x64, 0xf2, 0x09, 0xa6, 0xce, 0x61, 0x30, 0xf3,
0x18, 0x00, 0x00,
0x00, 0x00, 0x7e, 0xf3, 0x0f, 0xa6, 0xcc, 0x7d, 0x17, 0xb3,
0x18, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
ETin.begin(details(sensor_data), &mySerial);
ETout.begin(details(device_data), &mySerial);
tft.reset();
tft.begin(0x9486);
tft.setRotation(2);
tft.fillScreen(BLACK);
delay(500);
tft.setCursor(110,15);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("BRAIN COMPUTER");
tft.setCursor(110,35);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("INTERFACE BASED");
tft.setCursor(110,55);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("HOME AUTOMATION");
tft.setCursor(10,95);
40
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.print("Ali Arshad(150192),Fahad (150189),
Siddique(150279)");
tft.setCursor(65,120);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.print("TEMPERATURE");
tft.setCursor(180,145);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("o");
tft.setCursor(200,160);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("C");
tft.setCursor(80,190);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.print("HUMIDITY");
tft.setCursor(200,220);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("%");
tft.setCursor(65,260);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("FAN");
tft.fillCircle(240,270,20,RED);
tft.drawCircle(240,270,20,WHITE);
tft.setCursor(65,320);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("LIGHT");
tft.fillCircle(240,330,20,RED);
tft.drawCircle(240,330,20,WHITE);
tft.setCursor(65,380);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("AC");
tft.fillCircle(240,390,20,RED);
tft.drawCircle(240,390,20,WHITE);
41
tft.setCursor(65,440);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("TV");
tft.fillCircle(240,450,20,RED);
tft.drawCircle(240,450,20,WHITE);
tft.drawRect(0,0,320,480,WHITE);
delay(500);
}
void loop()
{
if (ETin.receiveData())
{
tft.setCursor(90,160);
tft.setTextColor(WHITE,BLACK);
tft.setTextSize(3);
tft.print(sensor_data.temp);
delay(100);
tft.setCursor(90,220);
tft.setTextColor(WHITE,BLACK);
tft.setTextSize(3);
tft.print(sensor_data.hum);
}
if (Serial.available())
{
choice = Serial.read();
if (choice == 'd')
{
device_data.device++;
if (device_data.device == 1)
{
tft.setCursor(65,260);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.print("FAN");
tft.setCursor(65,440);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("TV");
}
else if (device_data.device == 2)
{
tft.setCursor(65,320);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.print("LIGHT");
42
tft.setCursor(65,260);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("FAN");
}
else if (device_data.device == 3)
{
tft.setCursor(65,380);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.print("AC");
tft.setCursor(65,320);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("LIGHT");
}
else if (device_data.device == 4)
{
tft.setCursor(65,440);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.print("TV");
tft.setCursor(65,380);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("AC");
}
else if (device_data.device > 4)
{
device_data.device = 1 ;
tft.setCursor(65,260);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.print("FAN");
tft.setCursor(65,440);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("TV");
}
Serial.println(device_data.device);
}
if (choice == 's')
{
if ( device_data.device == 1)
{
if (S1==0)
{
S1=~S1;
device_data.state=1;
tft.fillCircle(240,270,20,GREEN);
tft.drawCircle(240,270,20,WHITE);
}
else
43
{
S1=~S1;
device_data.state=0;
tft.fillCircle(240,270,20,RED);
tft.drawCircle(240,270,20,WHITE);
}
}
else if ( device_data.device == 2)
{
if (S2==0)
{
S2=~S2;
device_data.state=1;
tft.fillCircle(240,330,20,GREEN);
tft.drawCircle(240,330,20,WHITE);
}
else
{
S2=~S2;
device_data.state=0;
tft.fillCircle(240,330,20,RED);
tft.drawCircle(240,330,20,WHITE);
}
}
else if ( device_data.device == 3)
{
if (S3==0)
{
S3=~S3;
device_data.state=1;
tft.fillCircle(240,390,20,GREEN);
tft.drawCircle(240,390,20,WHITE);
}
else
{
S3=~S3;
device_data.state=0;
tft.fillCircle(240,390,20,RED);
tft.drawCircle(240,390,20,WHITE);
}
}
else if ( device_data.device == 4)
{
if (S4==0)
{
S4=~S4;
device_data.state=1;
tft.fillCircle(240,450,20,GREEN);
tft.drawCircle(240,450,20,WHITE);
}
else
44
{
S4=~S4;
device_data.state=0;
tft.fillCircle(240,450,20,RED);
tft.drawCircle(240,450,20,WHITE);
}
}
ETout.sendData();
}
}
}
45
Appendix B: Code for Relays side Arduino
#include <SoftEasyTransfer.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define DHTPIN 7
#define D1 8
#define D2 9
#define D3 10
#define D4 11
DHT dht(DHTPIN, DHT22);
SimpleTimer timer;
struct SENSOR_DATA_STRUCTURE{
//put variable definitions here for the data we want to
send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
float temp;
float hum;
};
SENSOR_DATA_STRUCTURE sensor_data;
struct DEVICE_DATA_STRUCTURE{
//put variable definitions here for the data we want to
receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int8_t device;
int8_t state;
};
DEVICE_DATA_STRUCTURE device_data;
void setup() {
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);
mySerial.begin(9600);
Serial.println("******** BEGIN ***********");
Serial.println("- start DHT sensor");
dht.begin();
46
ETin.begin(details(device_data), &mySerial);
ETout.begin(details(sensor_data), &mySerial);
timer.setInterval(1000*25, readDHTSensor);
}
void readDHTSensor() {
delay(200);
sensor_data.temp = dht.readTemperature();
sensor_data.hum = dht.readHumidity();
if (isnan(sensor_data.hum) || isnan(sensor_data.temp)) {
sensor_data.temp = 0.00;
sensor_data.hum = 0.00;
}
ETout.sendData();
}
void loop() {
timer.run();
if(ETin.receiveData()){
if (device_data.device==1)
{
if (device_data.state==0) {digitalWrite(D1,
HIGH);}
else if (device_data.state==1) {digitalWrite(D1,
LOW);}
}
else if (device_data.device==2)
{
if (device_data.state==0) {digitalWrite(D2,
HIGH);}
else if (device_data.state==1) {digitalWrite(D2,
LOW);}
}
else if (device_data.device==3)
{
if (device_data.state==0) {digitalWrite(D3,
HIGH);}
else if (device_data.state==1) {digitalWrite(D3,
LOW);}
}
else if (device_data.device==4)
{
if (device_data.state==0) {digitalWrite(D4,
HIGH);}
else if (device_data.state==1) {digitalWrite(D4,
LOW);}
}
delay(100);
}
47
Appendix C: Code for Client-side Wi-Fi Module
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <EasyTransfer.h>
struct SENSOR_DATA_STRUCTURE{
//put your variable definitions here for the data you want
to send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
float temp;
float hum;
};
SENSOR_DATA_STRUCTURE sensor_data;
struct DEVICE_DATA_STRUCTURE{
//put your variable definitions here for the data you want
to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int8_t device;
int8_t state;
};
DEVICE_DATA_STRUCTURE device_data;
// AP Wi-Fi credentials
const char* ssid = "FYP";
const char* password = "ABCDEF";
char x;
String myString1, myString2;
// Static network configuration
IPAddress ip(192, 168, 4, 4);
IPAddress gateway(192, 168, 4, 0);
IPAddress subnet(255, 255, 255, 0);
int device=1;
int state=1;
ESP8266WebServer server(80);
48
WiFiClient client;
void setup() {
Serial.begin(9600);
ETin.begin(details(device_data), &Serial);
ETout.begin(details(sensor_data), &Serial);
Serial.println("- set ESP STA mode");
WiFi.mode(WIFI_STA);
Serial.println("- connecting to wifi");
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
server.on("/", handle_index);
server.on("/feed", handle_feed);
server.begin();
}
void handle_index() {
server.send(200, "text/plain", "Hello from my server!");
}
void handle_feed() {
myString1 = server.arg("temp");
myString2 = server.arg("hum");
sensor_data.temp = myString1.toFloat();
sensor_data.hum = myString2.toFloat();
server.send(200, "text/plain", "This is response to feed
client");
ETout.sendData();
}
void sendHttpRequest1() {
HTTPClient http;
http.begin(serverHost1);
http.addHeader("Content-Type", "application/x-www-form-
urlencoded");
http.POST(data1);
http.writeToStream(&Serial);
Serial.println("");
http.end();
}
49
void buildDataStream1() {
data1 = "device=";
data1 += String(device_data.device);
data1 += "&state=";
data1 += String(device_data.state);
}
void loop() {
server.handleClient();
if(ETin.receiveData())
{
buildDataStream1();
sendHttpRequest1();
delay(100);
}
}
50
Appendix D: Code for Relays side Wi-Fi Module
#include <EasyTransfer.h>
#include <ESP8266WiFi.h>
#include <SimpleTimer.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
// IoT platform Credentials
String apiKey = "RW6ZAA2OSRBCFXFE";
const char* logServer = "api.thingspeak.com";
SimpleTimer timer;
struct SENSOR_DATA_STRUCTURE{
//put variable definitions here for the data we want to
receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
float temp;
float hum;
};
SENSOR_DATA_STRUCTURE sensor_data;
struct DEVICE_DATA_STRUCTURE{
//put variable definitions here for the data we want to
send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int8_t device;
int8_t state;
};
DEVICE_DATA_STRUCTURE device_data;
ESP8266WebServer server(80);
WiFiClient client;
void setup() {
Serial.begin(9600);
51
ETin.begin(details(sensor_data), &Serial);
ETout.begin(details(device_data), &Serial);
timer.setInterval(1000*60*60, repeat);
WiFi.mode(WIFI_AP_STA);
setupAccessPoint();
}
void repeat() {
setupStMode(String(sensor_data.temp) ,
String(sensor_data.hum));
}
void setupAccessPoint(){
void setupServer(){
Serial.println("* SETUP SERVER *");
Serial.println(" starting server :");
server.on("/", handle_index);
server.on("/device", handle_device);
server.begin();
}
WiFiClient client;
void buildDataStream() {
data = "temp=";
data += String(sensor_data.temp);
data += "&hum=";
data += String(sensor_data.hum);
Serial.println("- data stream: "+data);
}
void sendHttpRequest() {
HTTPClient http;
http.begin(serverHost);
53
http.addHeader("Content-Type", "application/x-www-form-
urlencoded");
http.POST(data);
http.end();
}
void loop() {
timer.run();
server.handleClient();
if (ETin.receiveData())
{
buildDataStream();
sendHttpRequest();
delay(100);
}
}
54