Documente Academic
Documente Profesional
Documente Cultură
College of Engineering
In Partial Fulfillment
Jer-michael F. Gimpayan
Adviser
May 2017
i
ABSTRACT
operated through wireless communication between Arduino and Android via Wi-
capabilities, a Feedback Module, which uses ACS712 technology and will enable
System Test phases, CentraLight and WiLight were developed. Unit tests were
conducted to verify if the modules selected can deliver the necessary functions for
the whole system to operate properly. The integration tests were conducted to test
the operations and behaviors of the modules when they operate together. Finally,
the system tests were conducted to test the whole system and note its behaviors.
significant limitations that were observed in the ability of the ESP8266 to facilitate
ii
ACKNOWLEDGMENT
development is a miracle in itself. But true to the nature of science and engineering,
miracles are to be broken down into understandable bits of information. Thus, this
acknowledgement section.
There are a lot of things that need acknowledgement for this study. One is
that the eternal pursuit of scientific discovery and understanding stems from the
innumerable and infinite things there are in the world provided to us by an infinitely
powerful God. Another is His never-ending grace, mercy, and provision without
which no scientific endeavor could ever take place. For this we are eternally
grateful.
Next, we would like to express our utmost and heartfelt gratitude to our
adviser, Dr. Noel S. Gunay, for his technical advice, enthusiasm for our study, for
being a constant source of support and inspiration, and finally, for always keeping
us on track.
We are also grateful to our teammates, Nesvelle Mae Pascua and Michelle
Palate, developers of WiLight, the other half of our system. Our study would
technically useless without them, but more than that, they have provided
assistance and comfort during the most trying periods of the development of the
system.
iii
To our boardmates, friends, and classmates who have provided technical
Also, we would like to thank our family who never failed to encourage us
when we were down and for providing financial assistance and understanding
is not only defined by what we are able to discover but also by finding out how
iv
TABLE OF CONTENTS
Page
Approval Sheet i
Abstract ii
Acknowledgement iii
Table of Contents v
CHAPTER 1: INTRODUCTION 1
v
(Rojo, Samaranos, & Tuban, 2016) 6
3.1.3 Hardware 11
3.1.4 Software 16
vi
3.1.5 Integration 16
vii
3.3.2.1 Android to Arduino Communication
(SW-IT-01) 22
(SWF-IT-01) 23
viii
4.1.2 ESP8266 Wi-Fi Module 29
DATA
5.1.2 DM-UT-01 40
5.1.3 ACS-UT-01 41
5.1.4 SSR-UT-01 43
5.1.5 ESP-UT-01 44
ix
5.2 Integration Tests 44
5.2.1 AAC-IT-01 44
5.2.2 SW-IT-01 45
5.2.3 SWF-IT-01 49
5.3.1 ST-01 50
5.3.2 ST-02 51
5.3.3 ST-03 53
6.1 Summary 56
6.2 Recommendations 57
BIBLIOGRAPHY 60
APPENDICES 62
Appendix A 63
Appendix B 67
x
Appendix C 75
Appendix D 80
Appendix E 82
xi
LIST OF TABLES Page
Table 4.1 Seek Bar to PWM pin Output to Brightness Conversion Table 31
xii
LIST OF FIGURES Page
Figure 4.1 Wiring Diagram for ESP8266 Wi-Fi Module to Arduino Uno 29
xiii
CHAPTER 1
INTRODUCTION
living. Today, the steady rise of smart technology through Android and Arduino
monitoring and control has opened up new doors for smarter and more efficient
ways of living by enabling people to integrate their tasks systematically through the
With Arduino and Android technology as gateway to the more complex and
integrated Internet of Things, the study will focus in the communication between
monitoring and control. This will be realized in the aspect of dwelling, office, school,
or any environment that presents to be a fit, following the basic idea of a smart
home, to be precise.
The smart home basically utilizes sensors and control systems to monitor a
dwelling and adjust the various components of the systems accordingly if not
1
otherwise adjusted manually. To be specific, the study focuses on the control of
lights through an android device. Lighting is one of the basic and most important
part in an electrical system design. Ease of access and control to lighting provides
Android tech presents to be the most efficient and readily accessible today
which will be perfect for an adaptive system. Arduino, being open-source, will be
the perfect partner for the Android in implementing the smart system.
Wi-Fi by Rojo, Tuban, Samaranos the backbone of the study, the proponents
switching system.
The main objective of this study is to develop one major part of a commercially-
viable Wireless Android to Arduino Lighting System controlled via Wi-Fi through
lighting device. To be even more specific, the proponents aimed to accomplish the
following:
systems performance.
2
4. To develop an efficient object-oriented Arduino code that can be used
to develop similar codes that utilizes more lights compared to the limit
7. To package the whole system into a box-type end product that is aimed
to be commercially viable.
The proponents believed that the study would benefit the following:
has the technology to help the community which will in turn awaken its
still fare poorly as opposed to other state universities in the country. With a
3
and ease of access which can mitigate the already problematic learning
to it will be the server and controller for the system. The Arduino IDE will be used
to generate or modify codes to be uploaded to the board. The Android device used
to control the lights will be considered solely as a medium to control the lights.
The system will operate at 220 V AC and at most 12 V DC but will only use
220 V AC source.
4
The study will also involve testing with multiple users solely to identify its
5
CHAPTER 2
LITERATURE REVIEW
Moreover, this chapter reviews the similar studies and finds its gaps and
limitations.
the trainer level of our system. Using familiar methodologies and the same
the study used existing Arduino Webserver codes from the internet and
App that they programmed to be a Telnet client. A dimmer circuit was also
constructed using circuits from the internet. Finally, they packaged the
6
Therefore, it cannot detect any malfunctions in the system, particularly
the functions necessary for a complete and working closed loop system in
sensing hardware and software functions and methods that would complete
it.
commercial level.
our study.
There are various online sources explaining the operation of the Hall
basically does is to take advantage of the hall effect that is exhibited when
7
CHAPTER 3
DATA GATHERING
SYSTEM DESIGN
HARDWARE SOFTWARE
INTEGRATION
(Package Design)
EVALUATION/
EXPERIMENTATION
In data gathering, all variables are taken into account starting from
the engineering aspect of the system up to the economic aspect. With the
8
research and elaborate discussions have been made for the proponents to
casing.
The deployment diagram shown in Figure 3.2 shows the general flow of the
system. The dashed lines represent wireless connections while solid lines
9
of the Android Device (WiLight) and Arduino Uno via the ESP8266 Wi-Fi
5V DC source and shall have outputs ranging from 0 to 5 V DC. The Wi-Fi
Module shall be dependent to the Arduino and shall utilize a Software Serial
Library. This means, no codes will be uploaded to the Wi-Fi module as used
commands via the Wi-Fi shield, it then interprets the information sent to it
and drives the different modules accordingly. Then, the Arduino Uno will
send feedback information to the Android App. The exchange of data will
LEGEND:
Driver Module
Connected to Light/Luminaires
(Blue Lines)
Power Circuit
10
The commands that are delivered to and received by the Arduino
Uno are implemented in the Driver Module. The Driver Module has two main
be responsible for the regular light connections and a dimmer module which
will be responsible for the dimmer light. The power circuit refers to the part
of the system that is high-powered and utilizes the 220V AC power source
directly.
System External
Circuitry
Feedback
Module
3.1.3 Hardware
includes ESP8266 Wi-Fi Module, Arduino Uno, Dimmer Module and Solid
State Relays (SSR) and ACS712 Hall-Effect Current Sensors. Through the
Wi-Fi Shield, the Arduino communicates with the Android device. Dimmer
11
depending of what the user wants. Lastly, SSR, just like any other relays
the device to detect current flow which will serve as the Feedback Module
of the device.
12
3.1.3.3 Relay Module
requirements.
parts, which means lower cost and easier SMT printed-circuit board
will be using a solid state relay. Four lamps will be switched ON/OFF,
13
3.1.3.4 Dimmer Module
From the previous study, both PSM and PWM are a success
in dimming the light but when timing is taken into account PSM will
be ruled out.
data process occurred. The delay was due to the dimmable lamps
detects the zero crossing which is then fed to the Arduino default
interrupt pin. Every time the Arduino detects the zero-crossing point
is detected every 8.333 ms. Imagine how can this dimmer give so
dimmer still gives a timing issues. Though the method PSM was a
success to dim the light, it is a big failure for aiming a fast response
and processing of data between the Android and the Arduino (Rojo,
14
3.1.3.5 ACS712 Hall-Effect Current Sensor
and reads the analog value sent. It can measure positive and
the earlier parts of development will involve the use of 4 light bulbs
Tuban (2016) in their study. However, in the final stages, this will be
15
differently, as in a house for example. This is further discussed in
detail in Chapter 4.
proponents have selected this type of chassis for the reason that it is
already available in an electronic shop and will be best suit for our
3.1.4 Software
Arduino IDE available for download in their website and with the
therefore opted to design a box-type output that will include the different
16
3.2 Research Methods
For the Android and Arduino to access the ESP8266 Wi-Fi Module,
a Software Serial Library shall be used. Most of the debugging will be done
using the built-in Serial Monitor of the IDE. As for the codes, the proponents
have decided to program the Arduino to act as a Telnet server and the
The code we modified and tried to perfect was the Code used by
information thus causing delays and/or confusion for the Android App
means that without it being a library, code reuse is not possible. Code
reuse will prove to be crucial once the device goes into full
17
may utilize more than just four lightbulbs. The object-oriented sketch
Android device as the client and the Arduino with the Wi-Fi Module as the
server. A serial port will be specified and the IP address of the Wi-Fi Module
shall be used. For debugging, the serial monitor will be used extensively.
Android device and the Arduino with the Wi-Fi Module as station points. The
router IP is static.
concept of PWM. It was made to be the smallest possible. The relay module
was bought off the shelf. The ACS712 Feedback Module was constructed
individually. Once they were finished, they were bolted in rectangular acrylic
There are four pairs of screw-type binding posts for the lamps mounted on
18
the side of the box. For the AC Power Input, a C8 shotgun connector was
that is two-pronged in the other end. The box also has a switch. Fuse
There were three main phases for the experiments and these are Unit,
Integration, and System Test Phases. Each of these phases had criteria to be
considered before their execution and conclusion which shall be referred from here
on out as Entry Criteria and Exit Criteria, respectively. These tests were done in
order and no test were executed without passing its own entry criteria and the exit
criteria of the test before it. Figure 3.4 is a diagram showing the sequence of the
test phases.
19
3.3.1 Unit Test Phase
as a meaningful whole. This means that each test was executed without the
consideration of other components. The unit tests in this study are function-
oriented. There is only one entry criterion for these tests and that is that the
future purpose. This is to expedite the construction of the package later on.
To exit the Unit Test Phase, 100% success must be achieved. Necessary
03)
Microcontroller and how it will power and carry out the sketch
uploaded to it.
codes
constructed module
20
The set-up included the Arduino Uno to provide the PWM
signal, the Dimmer Module, and a lamp. The set-up utilized 220V AC
Power.
solid-state relay.
Uno.
and testing if the Android device can connect to it. The second step
let us find out if the module can receive and send data. The third step
21
involved setting the module as a station point and testing if it can
oriented. To enter this phase, all modules to be used in each test should be
operational. To exit the phase, 100% success rate must be achieved. All
(AAC-IT-01)
Module can receive and send data to the Android device using the
modified codes.
installed.
22
3.3.2.2 Switching via Wi-Fi Integration Test (SW-IT-01)
This test involved testing if the Arduino UNO with the Wi-Fi
module can drive the different modules to turn on and off or dim the
lamps.
(SWF-IT-01)
This test followed a similar set-up as the previous test but with
the assessing the quality level of the device. The System Tests are
23
Since this phase is to verify if the different modules mesh
properly as one whole,the exit criterion for this phase is that it fulfills
obstructions.
the room.
test is to make sure that lights can be operated by more than one
24
3.3.4 Summary of Test Methods
Microcontroller MC-UT-01;
Verifies Microcontroller Functionalities needed for
MC-UT-02;
Unit Test the operation of CentraLight
MC-UT-03
ESP8266 Unit
Checking Connectivity Capabilities of the Module ESP-UT-01
Test
25
3.3.4.2 Integration Tests
Arduino Uno,
Android to
ESP8266 Wi-Fi Tests if the Arduino
Arduino
Module, Four-Channel Uno with the Wi-Fi AAC-IT-01
Communication
SSR, Dimmer Module, Module
Integration Test
PC, Android Device
26
3.3.4.3 System Tests
27
CHAPTER 4
In this chapter, the construction and use of the modules will be discussed.
A number of store-bought materials were used but there are modules that were
constructed. This section will elaborate the connections of these modules to the
Arduino Uno or to the other modules. This chapter will also cover the software
components of the system, namely the Arduino Sketch and the Android Program,
in detail.
system. It will interpret information received via the Wi-Fi Module and
execute the appropriate commands. It will also send back information to the
device it received information from. In this system, it will receive data to turn
on, turn off, dim down, or dim up respective lamps and will do so. It will also
send feedback information to the Android Devices to tell them the current
28
4.1.2 ESP8266 Wi-Fi Module
bought. The Wi-Fi Module is responsible for receiving and sending data
The module is connected to the Arduino Uno via five pins Figure 4.1
Connections
VCC to 3.3 V
CH-PD to 3.3 V
GND to GND
Tx to Rx
Rx to Tx
Figure 4.1 Wiring Diagram for ESP8266 Wi-Fi Module to Arduino Uno (Made
using Fritzing)
29
4.1.3 Relay Module
that is store-bought.
triggered via a digital input. This input will come from the Arduino Uno. Since
its an active low device, the lamps, in theory, should turn on if its respective
Connections
DC+ to 5V
DC- to GND
CHANNELS to DIGITAL
(1 TO 4) I/O PINS
from the previous study. All the components in constructing this module are
store-bought.
Two wires from the module are connected to the microcontroller, pin
9 and Ground. Pin 9 which is a PWM pin is able to accept an analog value
control the current flow on the MOSFET. By default, the PWM Arduino pin
3) 100K ohm, 0.5-.6 Watt Resistor (1) 8) IRF730 or STP10NK60 MOSFET (1)
Table 4.1 details the levels of brightness assigned to the PWMs output.
Table 4.1 Seek Bar to PWM pin Output to Brightness Conversion Table
0 255 0
31
1-17 252-207 1.18 18.82
the proponents opted to veto PSM and directly applied PWM. Following the
decided to use 4n25 Opto Coupler. The reasons for this are detailed in
Chapter 5.
house any item. The box is 10 x 7.5 x 3.25 and is black in color.
A switch will be installed to the box that is in series from the plug to
allow current to power the power circuit and the lamps. To boot up the
Arduino which is responsible for turning on the modules SSR and ACS712
fuse, will be placed in series with each of the lamps and switch to secure
these devices from overcurrent. The fuse holder is mounted on the boxs
32
back to easily replace a broken fuse when an overcurrent is detected. Eight
screw-type binding posts are placed on the front of the box which is allotted
for the connection of the lamps. The system will gain power when the
outlet.
The Arduino Program will follow a simple flow shown in Figure 4.3. The code
will be object-oriented and will be utilizing the Software Serial Library. Two classes
were made for the code, namely, the Lightbulb Class and the Dimmer Class. While
the switching responsile for the lightbulb uses the same method as the dimmer,
The Dimmer Class does not inherit from the Lightbulb Class because the function
for dimming adjustment already includes the switching of the dimmer. The
proponents found it best to just make the two classes independent to easily modify
The Arduino checks for data printed in the Software Serial and then,
it looks for the String +IPD,. The Software Serial cursor then moves to the
end of that String. This is where the connection ID and information are
contained. Using the functions of the Software Serial class, data is stored
33
The proponents have decided to do the communication with
numbers, the same way Rojo and the other researchers in the previous
ControlL study did it. However, the proponents changed it up a little bit.
The data for light bulbs is coded with the first character to contain the
lamp number, the second character to contain its state, ON or OFF. The
data for dimmer still uses the first character to contain the lamp number but
it uses two more characters to contain the dimming level which will vary
from 00 to 85. When a lamp is broken, the Arduino sends the lamp number
and the 9. This goes for both the lightbulb and the dimmer. There might
appear to be a confusion in the code with the dimmer which uses two
characters for its state but note that the Android Device cannot send a
command to make the lamps broken. Therefore, the Arduino does not parse
34
4.2.2 Data Exchange
messages sent by the Android client (WiLight). The CentraLight accepts two
characters at a time. The first character corresponds to the lamp number and
second character is represented as the lamp state. The second character being
0 or 1. The former being designated as OFF state and the latter ON state. For
The next table depicts what data has been sent, how it functions and its feedbacks.
11 Turning lamp 1 on on
21 Turning lamp 2 on on
31 Turning lamp 3 on on
35
35-51 Adjusting Brightness 40 58.82 %
brightness
enables the creation of a Software Serial object. The software serial object
reception, data parsing, and data transmission. Table 4.3 lists down the
functions from the Software Serial Library used in the sketch. The
36
port. This is data that's already arrived and
stored in the serial receive buffer
37
LEGEND
A Power Circuit
F Dimmer Circuit
K Switch
38
CHAPTER 5
In this chapter, the different tests are going to be presented. Each test is
explained in detail. At the end of the chapter, the interpretation and analysis of the
data is discussed.
found in the Examples from the Arduino IDE. They are Blink, Fade, and
The first sketch allows us to see if the digital I/O pins from the MC
Setup:
39
Once the sketch is done uploading, the LED should turn on and off
in one second intervals. This is repeated in all 13 digital I/O pins. This is
MC-UT-01
Setup:
The same set-up is to be followed from the previous sketch but the
LED shall only be connected to PWM pins (pins marked with a tilde beside
The LED should turn on and off in a fading manner. This is MC-UT-
02.
The third and final sketch allows us to see the analog reading
Setup:
Using a serial monitor or a serial plotter, the value should exhibit the
40
Results and Discussions:
to turn the LED on. The PWM pins have also been able to dim the LED
down and up. The MC has also successfully read analog input via the
to secure the connections to Analog Ports since the data that comes in is
analog and continuous and is very prone to variations. This will prove to be
5.1.2 DM-UT-01
Setup:
This test will involve voltage around 220V. The AC power input, the
lamp and the MC are connected. The Fade sketch from MC-UT-01 shall be
used. Once the code is uploaded and the circuit is powered through the
220V AC source, the light should exhibit the same fading behavior from MC-
41
Results and Discussions:
The dimmable light bulb used in the circuit has been successfully
made to exhibit the characteristics of a dimmer lamp. Using the same code
as with MC-UT-02, we have been able to dim the lamp up and down. This
was only achieved when the proponents swapped the 4n35 Opto Coupler
with a 4n25 Opto Coupler. For reasons yet unknown to us, the 4n35 does
not perform as well as the 4n25 in terms of durability. The proponents have
had to replace the IC multiple times only to end up using 4n25 because it
was the only one available in the local electronics store. Luckily, with 4n25,
5.1.3 ACS-UT-01
ACS712.
Setup:
with the lamps, and the 5V, GND, OUT to 5V, GND, and an analog port of
the MC, and uploading a modified code from a code provided by the
determined and this will reflect via the Serial Monitor. If the lamp is removed,
the Serial monitor should print 0.00 until the circuit is closed again by
42
The code from Electrical World was dissected and verified. The code
The major modification that was made was changing of the multiplier
for the rms, which was initially (50 / 1024.0). By deducing the process by
which the code calculates the value of current, we found that the multiplier
module. Thus, the change to (75.8 / 1024.0) was made whose numerator
can be derived by dividing 5V by 66mV. The way the code works is that it
samples alternating voltage values and it calculates the root mean square
and then it applies the multiplier whose value depends on the ACS712 unit.
43
This multiplier signifies the change in voltage, 66mV in 30A ACS712 units,
the analog port is uses. The device relies on the 5V supply from the MC to
set its zero value of 2.5V. Furthermore, ACS712 Modules OUT pin is
physical forces that may distort any readings. Any form of physical force
that may cause the jumper wires to dislodge may cause significant changes
in the reading.
5.1.4 SSR-UT-01
Setup:
connecting the SSR to the lamps and AC source. A simple modified Blink
sketch is then uploaded. We should be able to see the lamps turn on and
44
5.1.5 ESP-UT-01
The ESP8266 Unit Test is used to verify the Rx/Tx capabilities of the
Setup:
either of the two can receive and transmit information when used as Telnet
communication between the Arduino and the Android Device both directly
5.2.1 AAC-IT-01
an Arduino Sketch that uses a Software Serial Objects will be used to send
the AT Commands and the completed Android App without the feedback
45
Setup:
The modules and components used are the following: Arduino Uno,
The main goal of this test was to make the Arduino establish a server
the use of the SoftwareSerial Library. Furthermore, this test was to make
the Android App connect to the Arduino with just one click. Both of the goals
were achieved.
5.2.2 SW-IT-01
the goal of the set-up is to test the performance of the system of the modules
Setup:
The modules used are Arduino Uno, ESP8266 Wi-Fi Module, Four-
Android Device with the application already installed. This test will involve a
black-box testing type of test. Every possible input was run and each
46
Table 5.1 Switching via WI-Fi Integration Test
INPUT OUTPUT
the application
Do nothing
turned on
47
Tapping the second icon on Both, lamp 2 and second
turned on
turned on
48
Dragging the seekbar to its Dragging the seekbar
minimum to maximum.
49
possible user inputs while observing the behavior of the Arduino via the
Serial Monitor. Here are the most important observations that were made:
connections via a router. This seems like a dead end where the
studies.
5.2.3 SWF-IT-01
Setup:
Still the same with previous test but with the Feedback Module
already in place. The same with SW-IT-01, this involves black-box testing.
Given the results of the previous integration test, this test focuses on
the feedback functionality of the system. By running all possible user inputs
50
with the lamps installed and removed, the system can successfully detect
any loss in electrical connection and is able to notify the Android App of it.
give correct feedback. It was also observed that the wiring connections must
5.3.1 ST-01
The first system test is the Range Test, ST-01, and involves
measuring the maximum distance the device can be operated from via an
Setup:
Measuring tape and chalk will be used for measuring the distance
and leaving marks where we left off. And proceeding further until there will be no
and is booted up. Using a tape measure, the proponents marked the
51
showing any signs of reduced quality in performance. The space did not
allow for the experiment to go over 50 meters and it was already a pleasant
surprise to the proponents to have reached such distance given that the
Distance Lamp 4
Lamp 1 Lamp 2 Lamp 3
(meters) (Dimmer)
ON OK
ON OK ON OK ON OK OFF- OK
10
OFF- OK OFF- OK OFF- OK
DIM OK
ON OK
ON OK ON OK ON OK OFF- OK
20
OFF- OK OFF- OK OFF- OK
DIM OK
ON OK
ON OK ON OK ON OK OFF- OK
30
OFF- OK OFF- OK OFF- OK
DIM OK
ON OK
ON OK ON OK ON OK OFF- OK
40
OFF- OK OFF- OK OFF- OK
DIM OK
ON OK
ON OK ON OK ON OK OFF- OK
50
OFF- OK OFF- OK OFF- OK
DIM OK
5.3.2 ST-02
The second system test is the Range Test, ST-01, and involves
measuring the maximum distance the device can be operated from via an
52
Android Device, with physical obstructions. The test was conducted in a
two-storey building with the device placed at the second floor. The farthest
distance it can be operated from outside the room in the second floor was
measured. It was also operated from the first floor directly below.
Setup: The same setup will be done in this test but placing the server inside
a room and trying to establish a connection from the outside. Getting further until
CentraLight was placed inside a room and was operated from the
outside. The maximum distance of operation from the same floor was 30
meters, where at the 25-meter mark the connection begins to drop. It was
also successfully operated from the first floor directly. Table 5.2 details this
experiment.
ON OK
ON OK ON OK ON OK OFF- OK
10
OFF- OK OFF- OK OFF- OK
DIM OK
ON OK Connection
ON OK ON OK ON OK OFF- OK begins to
20
OFF- OK OFF- OK OFF- OK drop at 25
DIM OK m
53
ON OK Connection
ON OK ON OK ON OK OFF- OK
30 is very
OFF- OK OFF- OK OFF- OK
DIM OK weak
ON OK
From 1st ON OK ON OK ON OK OFF- OK
Floor OFF- OK OFF- OK OFF- OK
DIM OK
5.3.3 ST-03
This test involves multiple users operating the device. This test is to
make sure that lights can be operated by more than one user without a
hitch.
Setup:
Multiple users can operate CentraLight if they have the WiLight app
but they cannot be updated of the changes each individual user makes right
away. Each user can only be updated using the Check States button, but
54
5.4 Modifications during the Tests
remarkable success. There are a few points that have come up through
experimentation and the proponents have come to terms with. These observations
The Wi-Fi communication does not have any visible delays. As soon
the MC via the ESP8266 Module. The problem occurs when the received
data is interpreted, where the MC does not always successfully store and
execute the received data. There have been various variations in the set-
1.) Hardware
The first change that was implemented was the change from a shield
to a Module. This did not change anything virtually. The second change,
which was the baud rate was considered. Various programmers on online
Baud Rate to 9600. The default baud rate of ESP8266 Wi-Fi Module was
55
115200. The proponents made the baud rate change but still no verifiable
router, thus the second variation of all integration tests. This presented no
56
CHAPTER 6
The system was successfully packaged into a scalable commercially viable device.
there are significant conclusions that were made that show the imperfections of
the system which were observed during the various experimentation phases.
One major problem that was encountered was the erratic behavior of the
unit and integration test phase, we observed that the Arduino runs in a continuous
loop and there are windows or time intervals in each iteration where the Arduino
cannot parse the data it receives via the ESP8266 Module. This behavior is best
shown through successive clicking or tapping of the buttons of the App. There were
no experiments that was able to help us determine the cause of latency in the
execution of the data but we can conclude that there are no visible delays in
transmission. This is evidenced by the fact that the String information is reflected
in the serial monitor every time it was sent. The problem is that the Arduino doesnt
always get to interpret and save this data for it to execute the appropriate
commands. One other possible explanation is that the ESP8266 has limitations in
the facilitating of data when used as a TelNet Server or using the default AT
Firmware.
57
One other problem was the sensitivity of Arduino Uno analog ports and
ACS712 connections where reliability is put at stake. There were many instances
where the current sensing module of the system does not return correct feedback
that even replacing the parts did not alleviate. By rigorous connecting and
6.2 Recommendations
firmware
system by introducing another way to control the lights. This way, control becomes
more flexible. By including the option of manually switching the lights, another
identify anomalies in the network or in the electrical system more correctly and this
58
can enable them to troubleshoot accordingly. This also includes increasing the
range of lamps that can be used, whether they are low-powered or otherwise.
A good addition will also include a power monitor to monitor the voltage
level, current, or power level of the circuit. This helps in identifying low voltages or
monitoring technologies into the system. This can further increase space
convenience and control which will allow for better living environments. With the
the conditions of the environment like natural light from windows, the lights can
switch off or switch on on their own. This, along with a more inclusive control
system in terms of types of load can open doors for other smart systems that
59
REFERENCES
A. Online Sources
Chao. (2013, October 10). ACS712 Current Sensor Read. Retrieved April 27 2017
from http://www.electrodragon.com/acs712-current-sensor-read/
B. Unpublished Works
Rojo, R. C., Samaranos K. M., & Tuban C. M. (2016). ControlL: A Wireless Android
To Arduino Lighting Control System Via Wi-Fi. Mindanao State University
General Santos City
60
APPENDICES
61
APPENDIX A
This section details the materials used for the construction of CentraLight,
particularly photo documentation, their names, and purpose. Also included in this
A connector used to
Binding Posts
attach a single wire
62
A device that
Heat Sink absorbs unwanted
heat
An electrical
connector where a
Terminal Block wire is held by the
tightening of the
screw
An electronic
component allowing
Diodes
current to flow in
one direction only
An electronic
Integrated Circuit IC: component that
MOSFET (top) and function as an
Optocoupler (bottom) amplifier, oscillator,
timer,
63
microprocessor or
even computer
memory
Jumper Wires
An electrical wire
F/M(top) and M/M(bottom) interconnecting
components without
soldering
Used for
Universal PCB construction of
circuits
Light Bulbs
64
Used to connect to
C7 and C8 Shotgun
the AC mains,
connector (Male mounted
opted for
on the box)
convenience of use
65
APPENDIX B
into five (5) subsections: (1) CentraLight.ino, (2) LightBulb.h, (3) LightBulb.cpp, (4)
LightBulb and DimmerLight are the classes the proponents made and then
B.1 CentraLight.ino
#include <SoftwareSerial.h>
#include "DimmerLight.h"
#include "LightBulb.h"
SoftwareSerial ControlL(1, 0); //change to (2,3) to see Serial Monitor
LightBulb lamp1(6, A0);
LightBulb lamp2(7, A4);
LightBulb lamp3(8, A2);
DimmerLight dimmer(9, 10, A3);
int connectedId, lampNumber, lampState, dimming;
String receivedVal, feedback;
String ssid = "HUAWEI-E5330-AE51";
String PASSWORD = "rg0at5r8";
void setup() {
ControlL.begin(115200);
sendATtoSetup();
setupPins();
}
void loop() {
if (ControlL.available()) {
if (ControlL.find("+IPD,")) {
connectedId = ControlL.read() - 48;
delay(10);
ControlL.find(":");
delay(10);
lampNumber = ControlL.read() - 48;
delay(10);
lampState = ControlL.read() - 48;
delay(10);
if (lampNumber == 4) {
int temp = ControlL.read() - 48;
lampState = (10 * lampState) + temp;
delay(10);
}
66
feedback = "";
executeCommand(lampNumber, lampState);
lampNumber = 0;
lampState = 0;
}
}
}
void executeCommand(int lampNum, int lampSta) {
switch (lampNum) {
case 1:
lamp1.toggleLight(lampSta);
feedback += lampNum;
feedback += lamp1.readState();
delay(100);
sendCIPData(connectedId, feedback);
break;
case 2:
lamp2.toggleLight(lampSta);
feedback += lampNum;
feedback += lamp2.readState();
delay(100);
sendCIPData(connectedId, feedback);
break;
case 3:
lamp3.toggleLight(lampSta);
feedback += lampNum;
feedback += lamp3.readState();
delay(100);
sendCIPData(connectedId, feedback);
break;
case 4:
dimmer.setDimLevel(lampSta);
feedback += lampNum;
feedback += dimmer.readState();
delay(100);
sendCIPData(connectedId, feedback);
break;
case 8:
actionOnNewConnection(connectedId);
break;
}
}
int checkState(int lampNum) {
switch (lampNum) {
case 1:
feedback += lampNum;
feedback += lamp1.readRelayState();
initialCIPData(connectedId, feedback);
delay(100);
break;
case 2:
feedback += lampNum;
feedback += lamp2.readRelayState();
initialCIPData(connectedId, feedback);
delay(100);
break;
case 3:
67
feedback += lampNum;
feedback += lamp3.readRelayState();
initialCIPData(connectedId, feedback);
delay(100);
break;
case 4:
feedback += lampNum;
feedback += dimmer.readRelayState();
initialCIPData(connectedId, feedback);
delay(100);
break;
}
}
void actionOnNewConnection(int connectedId) {
for (int i = 1; i <= 4; i++) {
checkState(i);
feedback = "";
delay(100);
}
}
void sendCIPData(int connection, String message) {
message += ">";
String cipSend = "AT+CIPSEND=";
cipSend += connection;
cipSend += ",";
cipSend += message.length();
cipSend += "\r\n";
sendCommand(cipSend, 150);
sendCommand(message, 100);
}
void initialCIPData(int connectedId, String message) {
message += ">";
String cipSend = "AT+CIPSEND=";
cipSend += connectedId;
cipSend += ",";
cipSend += message.length();
cipSend += "\r\n";
sendCommand(cipSend, 400);
sendCommand(message, 400);
}
void sendATtoSetup() {
sendCommand("AT+RST\r\n", 2000);
sendCommand("AT+CWMODE=2\r\n", 1000);
sendCommand("AT+CIFSR\r\n", 1000);
sendCommand("AT+CIPMUX=1\r\n", 1000);
sendCommand("AT+CIPSERVER=1,1221\r\n", 1000);
}
void sendATtoSetupViaRouter() {
sendCommand("AT+RST\r\n", 2000);
sendCommand("AT+CWJAP=\"" + ssid + "\",\"" + PASSWORD + "\"\r\n",
8000);
sendCommand("AT+CWMODE=1\r\n", 1000);
sendCommand("AT+CIPMUX=1\r\n", 1000);
sendCommand("AT+CIPSERVER=1,1221\r\n", 1000);
sendCommand("AT+CIFSR\r\n", 1000);
}
void sendCommand(String command, const int timeout) {
68
ControlL.print(command);
delay(timeout);
}
void setupPins() {
lamp1.initialize();
lamp2.initialize();
lamp3.initialize();
dimmer.initialize();
}
B.2 LightBulb.h
#ifndef LightBulb_h
#define LightBulb_h
#include "Arduino.h"
class LightBulb {
private:
int relay, analog, lampNumber, lampState;
String receivedVal, feedback;
//variables below are for current sensing
long sampleTime, numSamples, sampleInterval;
int adc_zero;
public:
LightBulb();
LightBulb(int relayArdPort, int analogArdPort);
float current;
void initialize();
void CurrentSense();
void toggleLight(int lampState_);
int readState();
int readRelayState();
};
#endif
B.3 LightBulb.cpp
#include "Arduino.h"
#include "LightBulb.h"
LightBulb::LightBulb();
LightBulb::LightBulb(int relayArdPort, int analogArdPort) {
relay = relayArdPort;
receivedVal = "";
feedback = "";
lampState = HIGH;
analog = analogArdPort;
current = 0;
sampleTime = 100000UL;
numSamples = 250UL;
sampleInterval = sampleTime / numSamples;
adc_zero = 512;
69
}
void LightBulb::initialize() {
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
pinMode(analog, INPUT);
}
void LightBulb::CurrentSense() {
unsigned long currentAcc = 0;
unsigned int count = 0;
unsigned long prevMicros = micros() - sampleInterval ;
while (count < numSamples)
{
if (micros() - prevMicros >= sampleInterval)
{
int adc_raw = analogRead(analog) - adc_zero;
currentAcc += (unsigned long)(adc_raw * adc_raw);
++count;
prevMicros += sampleInterval;
}
}
int LightBulb::readState() {
CurrentSense();
if (current == 0 && lampState == 1) {
feedback = 9;
}
else {
feedback = lampState;
}
return feedback.toInt();
}
int LightBulb::readRelayState() {
int state = !(digitalRead(relay));
CurrentSense();
if (lampState == 1) {
if (current == 0) {
state = 9;
}
}
70
else state = !lampState;
return state;
}
B.4 DimmerLight.h
#ifndef DimmerLight_h
#define DimmerLight_h
#include "Arduino.h"
class DimmerLight {
private:
int relay, analog, dimmerPin, dimming, lampNumber, lampState;
String receivedVal, feedback;
//variables below are for current sensing
long sampleTime, numSamples, sampleInterval;
int adc_zero;
public:
DimmerLight();
DimmerLight(int relayArdPort, int dimmerArdPort, int
analogArdPort);
int dimmerLevel;
void initialize();
void setDimLevel(int lampState_);
float current;
void CurrentSense();
int readRelayState();
int readState();
};
#endif
B.5 DimmerLight.cpp
#include "Arduino.h"
#include "DimmerLight.h"
DimmerLight::DimmerLight() {}
DimmerLight::DimmerLight(int relayArdPort, int dimmerArdPort, int
analogArdPort) {
relay = relayArdPort;
dimmerPin = dimmerArdPort;
receivedVal = "";
feedback = "";
lampState = HIGH;
dimmerLevel = 1;
analog = analogArdPort;
current = 0;
sampleTime = 100000UL;
numSamples = 250UL;
sampleInterval = sampleTime / numSamples;
adc_zero = 512;
71
}
void DimmerLight::initialize() {
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
pinMode(dimmerPin, OUTPUT);
analogWrite(dimmerPin, 0);
pinMode(analog, INPUT);
}
void DimmerLight::CurrentSense() {
unsigned long currentAcc = 0;
unsigned int count = 0;
unsigned long prevMicros = micros() - sampleInterval ;
while (count < numSamples)
{
if (micros() - prevMicros >= sampleInterval)
{
int adc_raw = analogRead(analog) - adc_zero;
currentAcc += (unsigned long)(adc_raw * adc_raw);
++count;
prevMicros += sampleInterval;
}
}
72
}
int DimmerLight::readState() {
CurrentSense();
if (current > 1) {
feedback = lampState;
}
else if (current == 0) {
feedback = 9;
}
return feedback.toInt();
}
int DimmerLight::readRelayState() {
return dimmerLevel;
}
73
APPENDIX C
This section provides the complete source codes of the various sketches
we studied and adopted into the final complete Arduino Source Code. This section
includes (1) ControlL Complete Arduino Source Code and (2) Current Sensing
Code.
#include <SoftwareSerial.h>
SoftwareSerial wifi(0, 1); //change to (2,3) to see Serial Monitor
int relay[5];
int analog[5] = {A0, A1, A2, A3, A4};
int dimLevel;
int dimmerPin;
void setup() {
//put your setup code here, to run once:
wifi.begin(115200);
//configure wifishield
sendCommand("AT+RST\r\n", 2000);
sendCommand("AT+CWMODE=3\r\n", 1000);
sendCommand("AT+CIPMUX=1\r\n", 1000);
sendCommand("AT+CIPSERVER=1,1221\r\n", 1000);
initializePins();
}
void loop() {
if (wifi.available()) {
if (wifi.find("+IPD,")) {
int connectedId = wifi.read() - 48;
delay(10);
wifi.find(":");
delay(10);
int lampNumber = wifi.read() - 48;
delay(10);
int lampState = wifi.read() - 48;
delay(10);
String receivedVal = "";
receivedVal += lampNumber;
receivedVal += lampState;
74
String feedback = "";
if (receivedVal == "88") {
actionOnNewConnection(connectedId, receivedVal);
} else if (receivedVal == "99") {
feedback = receivedVal;
} else if (lampNumber >= 1 && lampNumber <= 3) {
digitalWrite(relay[lampNumber], !lampState);
delay(30);
if (digitalRead(relay[lampNumber] == !lampState)) {
delay(30);
feedback = receivedVal;
}
else {
feedback += lampNumber;
feedback += 9;
}
} else if (lampNumber == 4) {
int dimming;
if (lampState >= 1 && lampState <= 5) {
digitalWrite(relay[lampNumber], LOW);
delay(10);
dimming = 255 - (51 * lampState);
analogWrite(dimmerPin, dimming);
dimLevel = lampState;
feedback = receivedVal;
} else if (lampState == 0) {
digitalWrite(relay[lampNumber], HIGH);
delay(10);
if (digitalRead(relay[lampNumber] == !lampState)) {
delay(10);
dimLevel = lampState;
feedback = receivedVal;
}
}
else {
feedback += lampNumber;
feedback += 9;
}
}
if (feedback != "") {
sendCIPData(connectedId, feedback);
}
lampNumber = 0;
lampState = 0;
}
}
}
void sendCommand(String command, const int timeout) {
wifi.print(command);
delay(timeout);
}
void actionOnNewConnection(int connectedId, String receivedVal) {
for (int i = 1; i <= 4; i++) {
String s = "";
s += readLightStates(i);
initialCIPData(connectedId, s);
}
75
initialCIPData(connectedId, receivedVal);
}
String readLightStates(int pinNumber) {
String currentState = "";
if (pinNumber >= 0 && pinNumber <= 3) {
int state = !(digitalRead(relay[pinNumber]));
currentState += pinNumber;
currentState += state;
}
else if (pinNumber == 4) {
currentState += pinNumber;
currentState += dimLevel;
}
return currentState;
}
void initializePins() {
for (int i = 1; i <= 4; i++) {
relay[i] = i + 9;
pinMode(relay[i], OUTPUT);
pinMode(analog[i], INPUT);
}
dimmerPin = 9;
dimLevel = 5;
pinMode(dimmerPin, OUTPUT);
analogWrite(dimmerPin, 0);
}
void sendCIPData(int connection, String message) {
message += ">";
String cipSend = "AT+CIPSEND=";
cipSend += connection;
cipSend += ",";
cipSend += message.length();
cipSend += "\r\n";
sendCommand(cipSend, 250);
sendData(message, 150);
}
void initialCIPData(int connectedId, String message) {
message += ">";
String cipSend = "AT+CIPSEND=";
cipSend += connectedId;
cipSend += ",";
cipSend += message.length();
cipSend += "\r\n";
sendCommand(cipSend, 200);
sendData(message, 100);
}
void sendData(String message, const int timeout) {
wifi.print(message);
delay(timeout);
}
76
C.2 Current Sensing Code
This source code is gotten directly from a link provided by the YouTube
channel Electrical World in his video AC current Sensing Using ACS 712 Current
Sensor. The program samples voltage levels of the OUT pin of the ACS712 read
through analogRead and a root mean square is calculated. From here the current
is solved.
float current = 0;
const int currentPin = A0;
const unsigned long sampleTime = 100000UL;
const unsigned long numSamples = 250UL;
const unsigned long sampleInterval = sampleTime / numSamples; const int
adc_zero = 510;
void setup()
{
Serial.begin(9600);
}
void loop()
{
CurrentSense();
Serial.println(current);
delay(1000);
void CurrentSense()
{
unsigned long currentAcc = 0;
unsigned int count = 0;
unsigned long prevMicros = micros() - sampleInterval ;
while (count < numSamples)
{
if (micros() - prevMicros >= sampleInterval)
{
int adc_raw = analogRead(currentPin) - adc_zero;
currentAcc += (unsigned long)(adc_raw * adc_raw);
++count;
prevMicros += sampleInterval;
}
}
77
if (rms < 0.20)
{
rms = 0;
}
current = rms;
}
78
APPENDIX D
This section is intended for the internet resource sample codes used in
implementing the circuit reference and a schematic diagram of the dimmer circuit
Sample code:
Based on the circuit, the brightness of the lamp is controlled using the PWM pins
79
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
pinMode(led, OUTPUT);
void loop() {
analogWrite(led, brightness);
fadeAmount = -fadeAmount ;
delay(30);
As a result, from this code, the lamp fades from OFF to its maximum state
and vice-versa. The code was retrieved from the basic example codes of Arduino
IDE.
80
Appendix E
Working AT OK
AT+CWQAP
AT+CWMODE=1 STA
AT+CWMODE=2 AP
AT+CWMODE=3 BOTH
81
Set up TCP AT+CIPSTART=? Query
or UDP
connection (CIPMUX=0) AT+CIPSTART = id = 0-4, type = TCP/UDP, addr = IP address, port= port
<type>,<addr>,<port>
(CIPMUX=1) AT+CIPSTART=
<id><type>,<addr>, <port>
(CIPMUX=1) AT+CIPSEND=
<id>,<length>
Set as server AT+ CIPSERVER= mode 0 to close server mode; mode 1 to open; port =
<mode>[,<port>] port
82
Firmware AT+CIUPDATE 1. +CIPUPDATE:1 found server
Upgrade 2. +CIPUPDATE:2 connect server
(from Cloud) 3. +CIPUPDATE:3 got edition
4. +CIPUPDATE:4 start update
Received +IPD (CIPMUX=0): + IPD, <len>:
data
(CIPMUX=1): + IPD, <id>, <len>: <data>
83
CURRICULUM VITAE
84
DAVID JAYSON B. OQUENDO
Address: Anastacio Subdivision, Polomolok,
South Cotabato
Mobile Number: +639082960062
Email Address: davidjaysonoquendo@gmail.com
Personal Information:
Gender : Male
Citizenship : Filipino
Occupation : Employee
Educational Background:
85
Affiliations:
Engineering Students Organization (ESO)
Member, 2012- 2017
Achievements:
86
Recipient - Journalist of the Year Award
16th Kabantugan Awards
May 13, 2017
87
JER-MICHAEL F. GIMPAYAN
Citizenship : Filipino
Occupation : Housewife
Occupation : Seaman
Educational Background:
88
Affiliations:
Engineering Students Organization (ESO)
Member, 2012- 2017
Achievements:
89