Sunteți pe pagina 1din 103

CENTRALIGHT: AN ARDUINO-BASED WIFI-ENABLED

CENTRALIZED LIGHTING SYSTEM

An Undergraduate Thesis Proposal

Presented to the Faculty of

Electrical and Electronics Engineering Department

College of Engineering

Mindanao State University

General Santos City

In Partial Fulfillment

of the Requirements for the Degree of

Bachelor of Science in Electrical Engineering

David Jayson B. Oquendo

Jer-michael F. Gimpayan

NOEL S. GUNAY, Ph. D

Adviser

May 2017
i
ABSTRACT

Presented in this paper is CentraLight, one of two studies on a lighting system

operated through wireless communication between Arduino and Android via Wi-

Fi. CentraLight focuses on the development of a box-type command center

equipped with an ESP8266 Wi-Fi Module, which shall be in charge of

communications, a 4-Channel Solid-State Relay, which shall be in charge of

switching, a Dimmer Module, which shall be in charge of enabling dimming

capabilities, a Feedback Module, which uses ACS712 technology and will enable

the system to detect malfunctions caused by loss of electrical connection, and

finally, an Arduino Uno, to serve as the prime mover of all aforementioned

modules. Through a three-phase experimentation process, Unit, Integration, and

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.

As a result, a box-type device was developed that is capable of establishing

communication, switching, dimming, and current detection. However, there were

significant limitations that were observed in the ability of the ESP8266 to facilitate

the data exchange.

Keywords: Wireless Control, Arduino Uno, ESP8266 Wi-Fi Module, 4-Channel


Solid State Relay, ACS712 Hall Effect Current Sensor

ii
ACKNOWLEDGMENT

To be able to endure such a gargantuan task as research and product

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

assistance and moral support.

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

during the conduct of our study.

Finally, we would like to acknowledge that scientific research and discovery

is not only defined by what we are able to discover but also by finding out how

much left there is to find out.

This study is dedicated to this eternal pursuit of knowledge, to the people

who believe in itto the people who believe in us.

iv
TABLE OF CONTENTS

Page

Approval Sheet i

Abstract ii

Acknowledgement iii

Table of Contents v

List of Tables xii

List of Figures xiii

CHAPTER 1: INTRODUCTION 1

1.1 Background of the Study 1

1.2 Objectives of the Study 2

1.3 Significance of the Study 3

1.4 Scope and Delimitation 4

CHAPTER 2: REVIEW OF LITERATURE 6

2.1 Related Researches 6

2.1.1 ControlL: A Wireless Android to Arduino

Lighting Control System via Wi-Fi

v
(Rojo, Samaranos, & Tuban, 2016) 6

2.2 Related Online Literature 7

CHAPTER 3: RESEARCH AND DESIGN METHODOLOGY 8

3.1 Research Design 8

3.1.1 Data Gathering 9

3.1.1 Deconstructing the ControlL Trainer 9

3.1.2 Testing ControlL 9

3.1.2 System Design 9

3.1.3 Hardware 11

3.1.3.1 Arduino Uno 12

3.1.3.2 ESP8266 Wi-Fi Module 12

3.1.3.3 Relay Module 12

3.1.3.4 Dimmer Module 13

3.3.3.5 ACS712 Hall-Effect Current Sensor 14

3.3.3.6 Power Circuit 15

3.1.4 Software 16

3.1.4.1 Arduino Programming 16

vi
3.1.5 Integration 16

3.2 Research Methods 17

3.2.1 Accessing the Wi-Fi Shield 17

3.2.1.1 Android Codes 17

3.2.2 Modifying and Testing of the Codes 17

3.2.2.1 Arduino Codes 17

3.2.3 Testing Communication 18

3.2.4 Constructing the Dimmer, Relay, and ACS712 Modules 18

3.2.5 Constructing the Package 18

3.3 Test Methods 19

3.3.1 Unit Test Phase 19

3.3.1.1 Microcontroller Unit Test (MC-UT-01;02;03) 20

3.3.1.2 Dimmer Module Unit Test (DM-UT-01) 20

3.3.1.3 ACS712 Unit Test (ACS-UT-01) 21

3.3.1.4 Solid State Relay Unit Test (SSR-UT-01) 21

3.3.1.5 ESP8266 Unit Test (E-UT-01) 21

3.3.2 Integration Test Phase 22

vii
3.3.2.1 Android to Arduino Communication

Integration test (AAC-IT-01) 22

3.3.2.2 Switching via Wi-Fi Integration Test

(SW-IT-01) 22

3.3.2.3 Switching via Wi-Fi with Feedback Integration Test

(SWF-IT-01) 23

3.3.3 System Test Phase 23

3.3.3.1 Range System Test (ST-01) 24

3.3.3.2 Range with Obstruction System Test (ST-02) 24

3.3.3.3 Multiple User System Test (ST-03) 24

3.3.4 Summary of Test Methods 25

3.3.4.1 Unit Tests 25

3.3.4.2 Integration Tests 26

3.3.4.3 System Tests 27

CHAPTER 4: HARDWARE AND SOFTWARE COMPONENTS 28

4.1 Construction and Use of Modules 28

4.1.1 Arduino Uno 28

viii
4.1.2 ESP8266 Wi-Fi Module 29

4.1.3 Relay Module 30

4.1.4 Dimmer Module 31

4.1.5 Power Circuit and the Whole System Connection 32

4.2 The Arduino Code 33

4.2.1 Establishing the Connection 33

4.2.2 Data Exchange 35

4.2.3 The Software Serial Library 36

4.3 The Physical Setup 37

CHAPTER 5: PRESENTATION, INTERPRETATION, AND ANALYSIS OF

DATA

5.1 Unit Tests 39

5.1.1 MC-UT-01, MC-UT-02, MC-UT-03 38

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 System Tests 50

5.3.1 ST-01 50

5.3.2 ST-02 51

5.3.3 ST-03 53

5.4 Modifications during the Tests 54

5.4.1 Integration Tests 54

CHAPTER 6: CONCLUSIONS AND RECOMMENDATIONS 57

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 3.1 Summary of Unit Tests 25

Table 3.2 Summary of Integration Tests 26

Table 3.3 Summary of System Tests 27

Table 4.1 Seek Bar to PWM pin Output to Brightness Conversion Table 31

Table 4.2 Coding Guide for the WiLight and CentraLight 34

Table 4.3 CentraLight to WiLight Data Communication 36

Table 4.4 Software Serial Functions used in the CentraLight Sketch 37

Table 5.1 Switching via Wi-Fi Integration Test 48

Table 5.2 Range Test without Obstruction Results 52

Table 5.3 Range Test with Obstruction Results 53

xii
LIST OF FIGURES Page

Figure 3.1 Research Design Diagram 8

Figure 3.2 Deployment Diagram 10

Figure 3.3 System External Circuitry 11

Figure 3.4 Diagram showing the sequence of the Test Phases 19

Figure 4.1 Wiring Diagram for ESP8266 Wi-Fi Module to Arduino Uno 29

Figure 4.2 The Connection of the Relay to the Arduino 31

Figure 4.3 CentraLight Lighting System Physical System 38

xiii
CHAPTER 1

INTRODUCTION

1.1 Background of the Study

The ever-growing and ubiquitous influence of modern-day technology

cannot be ignored so much so that it has become an integral part of everyday

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

use of one or two measly devices.

With Arduino and Android technology as gateway to the more complex and

integrated Internet of Things, the study will focus in the communication between

the two aforementioned technologies to create a smart environment through

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.

A smart home may be defined as a well-designed structure with sufficient

access to assets, communication, controls, data, and information technologies for

enhancing the occupants quality of life through comfort, convenience, reduced

costs, and increased connectivity (Zipperer et al, 2013).

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

convenience and a better living condition.

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.

With ControlL: A Wireless Android to Arduino Lighting Control System Via

Wi-Fi by Rojo, Tuban, Samaranos the backbone of the study, the proponents

intend to develop ControlL into a commercially viable centralized wireless

switching system.

1.2 Objectives of the Study

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

the improvement of the existing ControlL system. To be specific, the proponents

aimed to develop CentraLight, an Arduino-based Wi-Fi Enabled centralized

lighting device. To be even more specific, the proponents aimed to accomplish the

following:

1. To improve the existing functionalities of ControlL trainer.

2. To experiment with available feedback technology to further improve the

systems performance.

3. To implement the feedback technology into the system.

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

used in the study.

5. To design and develop hardware modules that can be easily packaged

into a box-type end product that is space-efficient.

6. To integrate the hardware and software system components and test

the overall performance.

7. To package the whole system into a box-type end product that is aimed

to be commercially viable.

1.3 Significance of the Study

The proponents believed that the study would benefit the following:

The Community. By introducing an improved level of convenience

by creating spaces with advanced lighting control systems, this technology

has the technology to help the community which will in turn awaken its

general interest in this kind of technology, subsequently allowing the

technology to advance in the future and develop further, thereby also

improving the quality of living in community in the long term.

The University. The current status of our universitys infrastructure

still fare poorly as opposed to other state universities in the country. With a

fully functional, commercially viable system, proponents foresee a wireless

lighting system in every building in the vicinity as to provide convenience

3
and ease of access which can mitigate the already problematic learning

environment of the school.

The College of Engineering. This study can help raise the

educational strategies taught by the college by actual application which can

be implemented in the rooms inside the college. This, being an outcome-

based undergraduate thesis, encourages the graduating students in the

future to follow suit.

The Students. This study encourages future innovations to be

developed as this study serves as a benchmark for future studies.

1.4 Scope and Delimitation

This study is limited to the development of a wireless lighting control system

via Wi-Fi. An Android device installed with a separately developed Android

Application called WiLight will be used to remotely control the system.

Incandescent lamps will be used in this study since it can be dimmed.

An Arduino Uno Microcontroller and an ESP8266 Wi-Fi Module connected

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

behaviors involving multiple users.

5
CHAPTER 2

LITERATURE REVIEW

This chapter aims to review the current knowledge including substantive

findings as well as theoretical and methodological contributions to the study.

Moreover, this chapter reviews the similar studies and finds its gaps and

limitations.

2.1 Related Researches

2.1.1 ControlL: A Wireless Android to Arduino Lighting Control

System via Wi-Fi (Rojo, Samaranos, & Tuban, 2016)

This study served as the springboard of our whole research, it being

the trainer level of our system. Using familiar methodologies and the same

hardware components, sans Feedback Modules, this study has developed

a trainer for a wireless android operated lighting control system.

The main objective of the study is to develop a wireless Android to

Arduino Lighting Control System controlled via Wi-Fi. The researchers of

the study used existing Arduino Webserver codes from the internet and

modified them to operate as a Telnet Server. They developed an Android

App that they programmed to be a Telnet client. A dimmer circuit was also

constructed using circuits from the internet. Finally, they packaged the

whole system into a trainer.

From the conclusions and recommendations of the study, it can be

inferred that the system was open-loop lacking feedback functionalities.

6
Therefore, it cannot detect any malfunctions in the system, particularly

broken lights, loose connections, or short circuits. However, through deeper

analysis, the system appears almost as a quasi-closed loop system, having

the functions necessary for a complete and working closed loop system in

terms of programming. What it lacked mainly was the inclusion of Current

sensing hardware and software functions and methods that would complete

it.

The study being at trainer level cannot be commercialized in its

current state. Fortunately, closer inspection shows its scalability to

commercial level.

The study, being well-written, provided a well-rounded framework for

our study.

2.2 Related Online Literature

2.2.1 ACS712 Hall Effect Sensor

There are various online sources explaining the operation of the Hall

Effect Sensor. The sensor is non-intrusive feedback device and what it

basically does is to take advantage of the hall effect that is exhibited when

a voltage is produced through a conductor when a transverse electric

current is present. By taking multiple samples of voltages using a

Microcontroller, a root mean square voltage can be calculated. From there,

various measurements can be made, including, current, power, and energy.

7
CHAPTER 3

RESEARCH AND DESIGN METHODOLOGY

3.1 Research Design

DATA GATHERING

SYSTEM DESIGN

HARDWARE SOFTWARE

INTEGRATION

(Package Design)

EVALUATION/
EXPERIMENTATION

Figure 3.1 Research Design Diagram

3.1.1 Data Gathering

In data gathering, all variables are taken into account starting from

the engineering aspect of the system up to the economic aspect. With the

engineering aspect as the first priority in all other considerations, extensive

8
research and elaborate discussions have been made for the proponents to

be able to choose the best components and methods to be used to

implement the best design within their capabilities.

3.1.1.1 Deconstructing the ControlL Trainer

In order to gather sufficient information on the engineering

involved with the construction of the trainer, the proponents

deconstructed the trainer after reading the ControlL study

thoroughly. This is where the proponents gathered data on the

different nuances in the construction of the trainer that were not

sufficiently explained in their paper. Specifically, these are, (1) Use

of a 4n25 Opto Coupler as opposed to a 4n35 Opto Coupler, (2) Wire

Sizes, (3) Use of LED indicators, and (4) Considerations on the

casing.

3.1.1.2 Testing ControlL

Black Box testing was conducted before the proponents

proceeded with the construction.

3.1.2 System Design

The system Design consists of hardware and software components.

The deployment diagram shown in Figure 3.2 shows the general flow of the

system. The dashed lines represent wireless connections while solid lines

represent wired connections. The heart of the system is the communication

9
of the Android Device (WiLight) and Arduino Uno via the ESP8266 Wi-Fi

Module (CentraLight). The Arduino Uno in CentraLight will operate with a

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

in Arduino-to-Arduino communication. Once the Arduino receives the

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

be further discussed in Chapter 4.

Android Wi-Fi Module


Device (ESP8266)

LEGEND:

Wireless (Dotted Lines)


Arduino

Wired (Solid Lines)

Driver Module
Connected to Light/Luminaires
(Blue Lines)

Power Circuit

Figure 3.2 Deployment Program

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

components as shown in Figure 3.3. It consists of a relay module which will

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

Driver Module Power Circuit

Relay Module Dimmer Module

Feedback
Module

Figure 3.3 System External Circuitry.

3.1.3 Hardware

The Hardware is one of the most essential part of this project. It

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

Module is responsible for controlling the brightness of the light fixture

11
depending of what the user wants. Lastly, SSR, just like any other relays

serves as a switch. Finally, the ACS712 Hall-Effect Current Sensor enables

the device to detect current flow which will serve as the Feedback Module

of the device.

3.1.3.1 Arduino Uno

There are a variety of board styles and a multitude of vendors

selling development boards in which picking a Wi-Fi enabled

microcontroller can be exhausting. The prime consideration of the

proponents in selecting such board is the Arduino Uno R3. The

proponents vetoed/disregarded other microcontrollers such as

Raspberry Pi, Arduino Yun, etc. because we consider the

microcontrollers cost, size, how fast it takes to boot up and the

availability of the OS we have. This Arduino Uno R3 will power up

the Wi-Fi Module and the ACS712 current sensor.

3.1.3.2 ESP8266 Wi-Fi Module

There are various modules available in the market that will

enable Android to Arduino Communications, however, the

proponents have chosen ESP8266 because it is cheaper and its size

is more convenient for this project.

12
3.1.3.3 Relay Module

Many electronic designs can take advantage of the improved

performances of solid-state relay (SSRs) relative to that of electro-

mechanical relays (EMRs) that perform the same circuit function.

The advantage of solid-state relays includes the following:

SSRs are typically smaller than EMRs, conserving valuable

space in printed-circuit board applications

SSRs offer improved system reliability because they have

no moving parts or contacts to degrade

SSRs provide state-of-the-art performance, including no

requirement for driver electronics and bounce-free switching

SSRs provide improved system life-cycle costs, including

simplified designs with reduced power supply and heat dissipation

requirements.

SSRs can be provided as surface-mount technology (SMT)

parts, which means lower cost and easier SMT printed-circuit board

manufacture (Advantages of Solid-State Relays Over Electro-

Mechanical Relays, 2014).

For the purpose of this study given the advantages listed we

will be using a solid state relay. Four lamps will be switched ON/OFF,

thus, a 4-channel solid state relay will be used.

13
3.1.3.4 Dimmer Module

By means of dimming the lamp a dimmer module will be vital.

A dimmer module is relatively made by two basic ways, among these

are Pulse Skip Modulation and Pulse Width Modulation.

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.

By using PSM for the dimming function, a major delay to the

data process occurred. The delay was due to the dimmable lamps

interrupt. If a current flows through the lamp, the dimmer circuit

detects the zero crossing which is then fed to the Arduino default

interrupt pin. Every time the Arduino detects the zero-crossing point

of the waveform, it executes the specific part of the program on the

Arduino to maintain the brightness and to eliminate some of the

timing issues introduced by this dimmer. For 60Hz, the zero-crossing

is detected every 8.333 ms. Imagine how can this dimmer give so

much delay to the system. Since theres no perfect hardware, the

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,

Samaranos, & Tuban, 2016).

14
3.1.3.5 ACS712 Hall-Effect Current Sensor

A feedback system will be implemented for this project. The

proponents decided to use a current sensor, ACS712 Hall Effect

current sensor because it provides economical and precise way of

sensing AC and DC currents based on Hall-effect. This type of

current sensor is based on the principle of Hall-effect which states

that when an electrical current passes through a sample placed in a

magnetic field, a potential proportional to the current and to the

magnetic field is developed across the material in a direction

perpendicular to both the current and to the magnetic field.

The sensor only senses if there is a current flowing through it.

It then sends a signal to the microcontroller where it is connected to

and reads the analog value sent. It can measure positive and

negative currents which ranges from -5A to +5A and is supplied by

5V from the microcontroller. A 2.5V, middle sensing voltage, is still

sensed when there is no current.

3.1.3.6 Power Circuit

For the purposes of this study, especially in experimentation,

the earlier parts of development will involve the use of 4 light bulbs

connected similar to the trainer circuit used by Rojo, Samaranos and

Tuban (2016) in their study. However, in the final stages, this will be

removed in favor of a set-up that will allow the device to be connected

15
differently, as in a house for example. This is further discussed in

detail in Chapter 4.

A box-type chassis is used for enclosing the modules. The

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

device. Furthermore, the purchased box is made of plastic material

that is ideal for wireless communication devices because it does not

cause significant interference.

3.1.4 Software

3.1.4.1 Arduino Programming

The programming for the Arduino was done in the free

Arduino IDE available for download in their website and with the

language that is normally used. The sketch will be based mainly on

the final source code of Rojo, Samanaros, and Tubans study.

Modifications are made as to make the code more efficient.

3.1.5 Integration (Package Design)

The proponents produced a device that is commercially viable and

therefore opted to design a box-type output that will include the different

modules described so far and to be discussed later on. This will be

controlled by a separately developed fully-functional Android Application

that will also be commercially viable as a partner to the physical device.

16
3.2 Research Methods

3.2.1 Accessing the Wi-Fi Shield

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

Android device as a Telnet client.

3.2.2 Modifying and Testing of the codes

The code we modified and tried to perfect was the Code used by

Rojo and his team.

3.2.2.1 Arduino Code

The existing Arduino Code has a few problems. For one,

although the Arduino has almost no delay in receiving information

from the Android device, it doesnt always get to interpret this

information thus causing delays and/or confusion for the Android App

and the user. The proponents intend to eliminate this problem.

Furthermore, the current code is not object-oriented. This

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

implementation. This will allow different iterations of the device that

17
may utilize more than just four lightbulbs. The object-oriented sketch

will also provide a framework for

3.2.3 Testing Communication

The communication is between a client and a server, with the

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.

We also explored the use of a router as an access point and the

Android device and the Arduino with the Wi-Fi Module as station points. The

router IP is static.

3.2.4 Constructing the Dimmer, Relay, and ACS712 Modules

The dimmer module was constructed in a PCB and it utilized the

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

using a PCB as a placeholder of the store-bought modules.

3.2.5 Constructing the Package

The package is a box-type device that can be installed in an electrical

system of either a house or a school, etc. Each module was constructed

individually. Once they were finished, they were bolted in rectangular acrylic

placeholder. The placeholders dimensions were based on the chassis.

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

mounted on the box which will be inserted a female C7 shotgun connector

that is two-pronged in the other end. The box also has a switch. Fuse

holders were mounted on the box for electrical safety.

3.3 Test Methods

Figure 3.4 System External Circuitry

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

The unit tests involved treating individual components of the device

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

Modules or Units to be tested have already been constructed to suit its

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

replacements for components of the modules or workaround solutions can

or must be made in order to achieve 100% success.

3.3.1.1 Microcontroller Unit Test (MC-UT-01; MC-UT-02; MC-UT-

03)

This involved testing the programmable capabilities of the

Microcontroller and how it will power and carry out the sketch

uploaded to it.

The set-up included the Arduino Uno, LEDs, a potentiometer,

a 9V battery, a breadboard, and a Personal Computer to upload the

codes

3.3.1.2 Dimmer Module Unit Test (DM-UT-01)

This involved testing the dimming capabilities of the

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.

3.3.1.3 ACS712 Unit Test (ACS-UT-01)

This involved testing the ability of the ACS712 to detect

currents. This did not involve measuring the current.

The set-up included the ACS712 connected in series with a

lamp, an Arduino Uno, and a Personal Computer to upload and view

the feedback detection of the ACS712.

3.3.1.4 Solid State Relay Unit Test (SSR-UT-01)

This involved the switching capabilities of the store-bought

solid-state relay.

The set-up included the store-bought four-channel solid-state

relay module connected accordingly to a set of lamps and an Arduino

Uno.

3.3.1.5 ESP8266 Unit Tests (E-UT-01)

There are three steps involving the ESP8266 Wi-Fi Module.

The first step involves setting the module as an Access Point

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

connect to a router and if it can receive and send data.

The set-up included an Arduino Uno, an ESP8266 Wi-Fi

Module, and an Android Device that has a Telnet Application.

3.3.2 Integration Test Phase

Integration tests involved taking two or more modules at a time and

testing their functionality as an aggregate. The integration tests are function-

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

necessary modifications to the codes or connections must be made in order

to achieve 100% success rate.

3.3.2.1 Android to Arduino Communication Integration test

(AAC-IT-01)

This test involved testing if the Arduino UNO with Wif-Fi

Module can receive and send data to the Android device using the

modified codes.

The modules and components used are the following: Arduino

Uno, ESP8266 Wi-Fi Module, 4-Channel Solid-State Relay, Personal

Computer, and the Android Device with the application already

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.

The modules and components used are the following: Arduino

Uno, ESP8266 Wi-Fi Module, Four-Channel Solid-State Relay,

Dimmer Module, Personal Computer, and the Android Device with

the application already installed.

3.3.2.3 Switching via Wi-Fi with Feedback Integration Test

(SWF-IT-01)

This test involved mainly if the current detection functions

programmed to the Arduino Uno works.

This test followed a similar set-up as the previous test but with

the ACS712 Module.

3.3.3 System Test Phase

System Test Phase is mainly about categorizing defects and

the assessing the quality level of the device. The System Tests are

function-oriented and performance-oriented. They also focus on

reliability and behavior during special conditions. To enter this phase,

the device must be constructed completely.

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

all its system and engineering requirements.

3.3.3.1 Range System Test (ST-01)

This test involved measuring the maximum distance the

device can be operated via an Android Device without any physical

obstructions.

3.3.3.2 Range with Obstruction System Test (ST-02)

This test involved placing the device inside a room and

measuring the maximum distance it can be operated from outside

the room.

3.3.3.3 Multiple User System Test (ST-03)

This test involved multiple users operating the device. This

test is to make sure that lights can be operated by more than one

user without a hitch.

24
3.3.4 Summary of Test Methods

3.3.4.1 Unit Tests

Table 3.1 Summary of Unit Tests

Test Name Functionality Test ID

Microcontroller MC-UT-01;
Verifies Microcontroller Functionalities needed for
MC-UT-02;
Unit Test the operation of CentraLight
MC-UT-03

Dimmer Module Tests the dimming capabilities of the constructed


DM-UT-01
Unit Test module

Tests the ability of the ACS712 Hall-Effect


ACS712 Unit Test ACS-UT-01
Current Sensor to detect currents

Solid State Relay Checks the switching capabilities of the 4-


SSR-UT-01
Unit Test Channel Solid State Relay

ESP8266 Unit
Checking Connectivity Capabilities of the Module ESP-UT-01
Test

25
3.3.4.2 Integration Tests

Table 3.2 Summary of Integration Tests

Test Name Modules Used Functionality Test ID

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

Arduino Uno, Tests if the Arduino


ESP8266 Wi-Fi Uno can drive the
Switching via Wi-
Module, Four-Channel different modules SW-IT-01
Fi Integration Test
SSR, Dimmer Module, depending on the
PC, Android Device commands

Arduino Uno, Tests if the Arduino


ESP8266 Wi-Fi Uno can drive the
Switching via Wi- Module, Four-Channel different modules
Fi with Feedback SSR, Dimmer Module, depending on the SWF-IT-01
Integration Test PC, Android Device, commands and send
ACS712 Hall-Effect back the appropriate
Current Sensors Feedback

26
3.3.4.3 System Tests

Table 3.3 Summary of System Tests

Test Name Functionality Test ID

Tests the maximum distance the


Range Test ST-01
device can be operated

Tests the maximum distance the


Range with Obstruction
device can be operated with ST-02
Test
physical obstructions

Tests the behavior of the device


Multiple User Test ST-03
when there are multiple users

27
CHAPTER 4

HARDWARE AND SOFTWARE COMPONENTS

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.

4.1 Construction and Use of Modules

4.1.1 Arduino Uno

The proponents used an Arduino Uno R3 microcontroller that is store

bought and ready-to-use.

The microcontroller will serve as the command hub of the whole

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

condition of the lamps, whether they are on, off, or broken.

28
4.1.2 ESP8266 Wi-Fi Module

The proponents used an ESP8266 Wi-Fi Module that is store-

bought. The Wi-Fi Module is responsible for receiving and sending data

from the Arduino to other devices.

The module is connected to the Arduino Uno via five pins Figure 4.1

shows these connections.

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

The proponents used an Active Low Four-Channel Solid-State Relay

that is store-bought.

The Four-Channel Solid-State Relay will act as a switch that can be

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

SSR is given a 0 input and turn off otherwise.

The connections of the Relay to the Arduino is shown in Figure 4.2

Connections

DC+ to 5V

DC- to GND

CHANNELS to DIGITAL
(1 TO 4) I/O PINS

Figure 4.2 Wiring Diagram for Four-Channel Solid-State Relay Module to


Arduino Uno (Made using Fritzing)
30
4.1.4 Dimmer Module

The proponents constructed a dimmer module that was also used

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

from the microcontroller then be connected to the modules opto-coupler to

control the current flow on the MOSFET. By default, the PWM Arduino pin

can output 0-255 which maps to 100% to 0% of brightness.

The list of materials for constructing a dimmer module is provided below.

1) 1N4001 OR 1N4007 Diode (5) 6) 4n25 Optocoupler (1)

2) 100 uF, 350-400V Capacitor (1) 7) 330-470 ohm Resistor (1)

3) 100K ohm, 0.5-.6 Watt Resistor (1) 8) IRF730 or STP10NK60 MOSFET (1)

4) 6k8 ohm, Watt Resistor (1)

5) 15V, .5 Watt Zener Diode (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

Seek Bar Level PWM pin Output Brightness (%)

0 255 0

31
1-17 252-207 1.18 18.82

18-34 204-156 20 38.82

35-51 153-105 40 58.82

52-68 102-54 60 78.82

69-85 51-0 80 100

Based on the results from Rojo, Samaranos, and Tubans research,

the proponents opted to veto PSM and directly applied PWM. Following the

same circuit from Instructables, we have been able to construct a dimmer

circuit. Note, however, that instead of a 4n35 Opto Coupler, we have

decided to use 4n25 Opto Coupler. The reasons for this are detailed in

Chapter 5.

4.1.5 Power Circuit and the Whole System Connection

The proponents used a store-bought acrylic box that is ready to

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

it will be in series with the power circuit. An overcurrent protection device,

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

shotgun connector C7 and C8 are attached together and is plugged in to an

outlet.

4.2 The Arduino Code

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

them in case there are some changes in the programming.

4.2.1 Establishing the Connection

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

to variables and from these variables, a command is executed.

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

a two-character command but rather sends it to the Android Device. Table

4.2 shows this coding method along with a few examples.

Table 4.2 Coding Guide for the WiLight and CentraLight

Lamp Coding Example


type

Light [lamp number][state] ; state can 1. 31 means lamp 3 is


bulbs be 0, 1, or 9 which means OFF, turned on
ON, or Broken respectively 2. 29 means lamp 2 is
broken

Dimmer [lamp number][dimmer level]; 1. 400 means lamp 4 is


dimmer level can range from 0 to turned on to MAX.
85. Dimmer level is 9X if its broken. 2. 49 means lamp 4 is
broken

34
4.2.2 Data Exchange

As a system, Arduino acting as a server should always respond to any

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

lamp 4, eighty-five dimmer states are programmed. Corresponding for 0-85

characters for 0 -100%. If problem is encountered Centralight will send a lamp

state of 9 indicating that an error occurred in the process.

The next table depicts what data has been sent, how it functions and its feedbacks.

Table 4.3 Centralight to Wilight Data Communication

Data Function Feedback Expected

11 Turning lamp 1 on on

10 Turning lamp 1 off off

21 Turning lamp 2 on on

20 Turning lamp 2 off off

31 Turning lamp 3 on on

30 Turning lamp 3 off off

0 Turning Dimmer off on

1-17 Adjusting Brightness 1.18 18.82 %


brightness

18-34 Adjusting Brightness 20 38.82 %


brightness

35
35-51 Adjusting Brightness 40 58.82 %
brightness

52-68 Adjusting Brightness 60 78.82 %


brightness

69-85 Adjusting Brightness 80 100 %


brightness

19 Lamp 1 Electrical problem Broken

29 Lamp 2 Electrical Problem Broken

39 Lamp 3 Electrical Problem Broken

4.2.3 The Software Serial Library

The Arduino sketch utilizes the Software Serial Library which

enables the creation of a Software Serial object. The software serial object

will be responsible for most of the codes operations, including data

reception, data parsing, and data transmission. Table 4.3 lists down the

functions from the Software Serial Library used in the sketch. The

information listed down Table 4.3 is from the Arduino website.

Table 4.4 Software Serial Functions used in the CentraLight sketch


Function Name Function

SoftwareSerial is used to create an instance


SoftwareSerial(rxPin, txPin)
of a SoftwareSerial object, whose name you
need to provide.

.begin(baudRate) Sets the Baud Rate for serial


communication

.available() Get the number of bytes (characters)


available for reading from a software serial

36
port. This is data that's already arrived and
stored in the serial receive buffer

.find() Reads data from the serial buffer until the


target string of given length is found. The
function returns true if target string is found,
false if it times out

.read() Return a character that was received on the


RX pin of the software serial port. Note that
only one SoftwareSerial instance can
receive incoming data at a time

.print(string) Prints data to the transmit pin of the


software serial port

.println(string) Prints data to the transmit pin of the


software serial port, followed by a carriage
return and line feed.

4.3 Physical Setup

Figure 4.3 CentraLight Lighting System Physical Setup

37
LEGEND

A Power Circuit

B FUSE (for the lamps)

C Arduino Uno Microcontroller

D 4-Channels Solid State Relay

E ACS712 Hall-Effect Current Sensor

F Dimmer Circuit

G Binding Posts (Lamp 1)

H Binding Posts (Lamp 2)

I Binding Posts (Lamp 3)

J Binding Posts (Lamp 4, Dimmer)

K Switch

L Fuse (for the switch)

38
CHAPTER 5

PRESENTATION, INTERPRETATION, AND ANALYSIS OF DATA

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.

5.1 Unit Tests

5.1.1 MC-UT-01, MC-UT-02, MC-UT-03

The microcontroller (MC) unit test is used to verify the condition of

the Microcontroller, specifically in terms of giving output or receiving output

in its digital and analog pins.

Three simple sketches were uploaded to the MC and these can be

found in the Examples from the Arduino IDE. They are Blink, Fade, and

ReadAnalogVoltage. These sketches will help verify the functionalities of

the MC that are crucial to the operation of the system.

The first sketch allows us to see if the digital I/O pins from the MC

can give a digital LOW or HIGH output.

Setup:

A LED is connected to one digital pin in the MC via a breadboard.

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

The second sketch allows us to see the PWM output capabilities of

the PWM pins of the MC.

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

them), namely, pins 3, 5, 6, 9, 10, and 11.

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

capabilities of the Analog Pins of the MC.

Setup:

In this test, a potentiometer is used with a 9V battery to give a

varying DC Voltage input into the analog pins.

Using a serial monitor or a serial plotter, the value should exhibit the

change in voltage as the potentiometer knob is adjusted. This is MC-UT-03.

40
Results and Discussions:

Using the aforementioned sketches, all MC unit tests were

successful. The Arduino Uno has successfully supplied enough DC voltage

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

Analog ports. However, there is a notable degree of sensitivity when using

the analog ports. Distortions as simple as physically moving the jumper

wires cause erratic change in measurements. It is concluded that it is best

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

problematic in the use of current sensors.

5.1.2 DM-UT-01

The Dimmer Unit Test is used to verify the dimming capabilities of

the constructed dimmer module given a PWM output by the MC.

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-

UT-02 Fade test.

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,

the dimmer circuit did not experience any problems anymore.

5.1.3 ACS-UT-01

The ACS712 Unit Test is used to verify the detection capabilities of

ACS712.

Setup:

By connecting the terminal blocks of the ACS712 sensor in series

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

Youtube Channel Electrical World, the presence of a current should be

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

putting the lamp back in place.

42
The code from Electrical World was dissected and verified. The code

was modified and is as follows:

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;
}
}

float rms = sqrt((float)currentAcc / (float)numSamples) * (75.8


/ 1024.0);
rms = rms - .05;
if (rms < 0.15)
{
rms = 0;
}
current = rms;
}

Results and Discussions:

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

is not applicable to the unit we have in hand, which is a 30A ACS712

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,

for every unit rise in the analog value.

One other significant observation is the sensitivity of the device and

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

connected to an analog port, which is, as mentioned in MC-UT-03, prone to

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

The 4-Channel Solid-State Relay Unit Test allows us to determine if

the SSR is capable of switching.

Setup:

The SSR is connected to the Arduino as shown in Figure 4.2, and

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

off in one second intervals.

Results and Discussions:

The 4-Channel Solid-State Relay showed no problems and we were

able to switch the lamps on and off without a hitch.

44
5.1.5 ESP-UT-01

The ESP8266 Unit Test is used to verify the Rx/Tx capabilities of the

Wi-Fi Module when set as an Access Point and as a Station Point

connected via a router.

Setup:

Using the Serial Monitor and an Android Device, we can observe if

either of the two can receive and transmit information when used as Telnet

Servers and Clients.

Results and Discussions:

By using a downloadable TelnetClient App, we were able establish

communication between the Arduino and the Android Device both directly

and via router. There were no virtual differences between connecting

directly or via router. There are no virtual delays either.

5.2 Integration Tests

5.2.1 AAC-IT-01

In the first integration test, Arduino to Android Communication Test,

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

functionality to send and receive commands and lamp conditions.

45
Setup:

The modules and components used are the following: Arduino Uno,

ESP8266 Wi-Fi Module, 4-Channel Solid-State Relay, Personal Computer,

and the Android Device with the application already installed.

Results and Discussions:

The main goal of this test was to make the Arduino establish a server

without having to manually input AT commands into the serial monitor by

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

In the second integration test, Switching via Wi-Fi Integration Test,

the goal of the set-up is to test the performance of the system of the modules

used together below.

Setup:

The modules used are Arduino Uno, ESP8266 Wi-Fi Module, Four-

Channel Solid-State Relay, Dimmer Module, Personal Computer, and the

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

response is recorded and compared to the expected response.

46
Table 5.1 Switching via WI-Fi Integration Test

INPUT OUTPUT

All lamps are turned off

as well as the icons on

the application
Do nothing

Tapping the first icon on the Both, lamp 1 and first

application icon on the app, are

turned on

47
Tapping the second icon on Both, lamp 2 and second

the application icon on the app, are

turned on

Tapping the third icon on the Both, lamp 3 and third

application icon on the app, are

turned on

48
Dragging the seekbar to its Dragging the seekbar

maximum brightness. The from left to right also

level of brightness can be manifests the levels of

adjusted through the use of brightness of the

seekbar dimmable lamp from

minimum to maximum.

Results and Discussions:

This set-up basically emulates the whole system of ControlL. With

the modules we have constructed, we tested the system by running all

49
possible user inputs while observing the behavior of the Arduino via the

Serial Monitor. Here are the most important observations that were made:

1.) The Arduino ALWAYS receives the data sent by the

Android Device with NO DELAYS.

2.) The Arduino DOES NOT ALWAYS execute the

commands sent to it by the Android Device.

These observations remained true even after making the

connections via a router. This seems like a dead end where the

proponents decided to come terms with it. The latency in the

transmission or the execution of data cannot be determined. The

proponents suggest using different firmware or libraries for future

studies.

5.2.3 SWF-IT-01

This will be the final integration test where an additional module,

feedback module, is tested.

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.

Results and Discussion:

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.

However, as discussed in ACS-UT-01, the sensitivity of the ports and of the

ACS712 module play a major role in maintaining the quality of performance.

The proponents had to replace some modules because of their inability to

give correct feedback. It was also observed that the wiring connections must

be made secure so as to avoid any errors.

5.3 System Tests

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

Android Device, without physical obstructions.

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

detected connection by the android device.

Results and Discussions:

The first range test was set-up by placing CentraLight in a hallway

and is booted up. Using a tape measure, the proponents marked the

distance from which it was to be operated. With significant success,

CentraLight and WiLight was able to perform even up to 50 meters without

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

expected radius of operation of the module is only 30 meters.

Table 5.2 Range Test without Obstruction Results

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

such time that loss of connection takes place.

Results and Discussions:

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.

Table 5.3 Range Test with Obstruction Results


Distance Lamp 4
Lamp 1 Lamp 2 Lamp 3 Notes
(meters) (Dimmer)

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 devices will try to connect on the server and making an

attempt to be able to control the lamps.

Results and Discussions:

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

even that is only a workaround. The ESP8266 relies on delays to operate

properly and cannot handle successive influx of information. Therefore,

CentraLight and WiLight is really limited in terms of multi-user operation.

54
5.4 Modifications during the Tests

The proponents have successfully undergone each phase of testing with

remarkable success. There are a few points that have come up through

experimentation and the proponents have come to terms with. These observations

were made after completing all three phases.

5.4.1 Integration Tests

The Wi-Fi communication does not have any visible delays. As soon

as a button is pressed in the Android App the data is instantly received by

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-

up made to try and eliminate this problem.

The following factors were modified:

1.) Hardware

2.) Baud Rate

3.) Network Topology

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

programming stackexchange communities have suggested lowering the

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

improvement in performance. Finally, a router was introduced to act as the

router, thus the second variation of all integration tests. This presented no

change at all, except for the prospect of bigger operating radius.

56
CHAPTER 6

CONCLUSIONS AND RECOMMENDATIONS

The system was successfully packaged into a scalable commercially viable device.

The feedback technology was successfully implemented. The three-phase

experimentation process was executed throughout the construction. However,

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

microcontroller in executing received data. Through experimentation during 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

reconnecting, the module began to work again, albeit imperfectly.

6.2 Recommendations

The system has the potential to improve on the following:

1.) Integrating manual switching that is reflected in the Android App

2.) Developing a reliable Feedback Module that will is not too

sensitive to distortions and one that can detect other possible

anomalies in the circuit.

3.) Inclusion of a power monitor

4.) Exploration of the use of new ESP technology or use of other

firmware

5.) Integrating monitoring technologies that enable smart-switching.

The inclusion of manual switching further fortifies the versatility of the

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

command must be programmed for CentraLight where it sends the appropriate

information to the Android Device regarding the state of the lamps.

By developing a more reliable feedback module, users may be able to

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

poor power quality.

Finally, the system can be taken to new heights by trying to implement

monitoring technologies into the system. This can further increase space

convenience and control which will allow for better living environments. With the

introduction of monitoring technologies, smart-switching is possible. By analyzing

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

control air conditioning by detecting temperature changes in the environment.

59
REFERENCES

A. Online Sources

Advantages of Solid-State Relays Over Electro-Mechanical Relays. (2014)


(Application Report No. 145-R03). Retrieved from IXYS Integrated Circuits
Division website: http://www.ixysic.com/home/pdfs.nsf/www/AN-
145.pdf/$file/AN-145.pdf

Chao. (2013, October 10). ACS712 Current Sensor Read. Retrieved April 27 2017
from http://www.electrodragon.com/acs712-current-sensor-read/

IoT Wi-Fi Modules Comparison Table ESP8266 vs CC3000 vs RN131 vs


HDG204. (2015) Retrieved January 20, 2017 from http://www.cnx-
software.com/2015/06/15/iot-wi-fi-modules-comparison-table-esp8622-vs-
cc3300-vs-rn131-vs-hdg204/

Software Serial Library. (n.d.). Retrieved April 28, 2017 from


https://www.arduino.cc/en/Reference/SoftwareSerial

Zipperer, A. et al. (2013). Electric Energy Management in the Smart Home:


Perspectives on Enabling Technologies and Consumer Behavior.
Proceedings of the IEEE Proc. IEEE, 101(11), 2397-2408.
doi:10.1109/jproc.2013.2270172 Meet Android Studio. (n.d.). Retrieved
from https://developer.android.com/studio/intro/index.html

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

section are photo documentation of the construction process.

Image Name Purpose

Acrylic Box Chassis Serves as an


Color: Black enclosure

A connector used to
Binding Posts
attach a single wire

This are electrical


safety devices for
Fuse Holder and Fuse
overcurrent
protection

62
A device that
Heat Sink absorbs unwanted
heat

Resistors (Left to Right)


A circuit element
6k8, 330 470, 100k that implements
electrical resistance

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

A plastic tube that


shrinks when
Heat Shrink
heated and used to
insulate wires

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

Complete Arduino Source Code

This section provides the complete Arduino Sketch of CentraLight. This is

into five (5) subsections: (1) CentraLight.ino, (2) LightBulb.h, (3) LightBulb.cpp, (4)

DimmerLight.h, and (5) DimmerLight.cpp. CentraLight.ino is the main file and

LightBulb and DimmerLight are the classes the proponents made and then

imported to the main file.

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::toggleLight(int lampState_) {


lampState = lampState_;
digitalWrite(relay, !lampState);
}

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;
}
}

float rms = sqrt((float)currentAcc / (float)numSamples) * (75.8 /


1024.0);
rms = rms - 0.05;
if (rms <= 0.2)
{
rms = 0;
}
current = 10*rms;
}

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::setDimLevel(int lampState_) {


lampState = lampState_;
//ON
if (lampState >= 1 && lampState <= 85) {
digitalWrite(relay, LOW);
delay(10);
dimming = (255 -(3 * lampState));
analogWrite(dimmerPin, dimming);
dimmerLevel = lampState;
feedback = receivedVal;
}
//OFF
else if (lampState == 0) {
digitalWrite(relay, HIGH);
delay(10);
if (digitalRead(relay == !lampState)) {
delay(10);
dimmerLevel = lampState;
feedback = receivedVal;
}
}
}

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;
}
}

float rms = sqrt((float)currentAcc / (float)numSamples) * (75.8 /


1024.0);
rms = rms - .05;
if (rms < 0.18)
{
rms = 0;
}
current = rms;

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

Other Arduino Source Codes

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.

C.1 ControlL Complete Arduino Source Code

This is the complete Arduino Source Code for ControlL by Rojo,

Samaranos, and Tuban.

#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;
}
}

float rms = sqrt((float)currentAcc / (float)numSamples) * (50 /


1024.0);
rms = rms - 0.10;

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

was also provided.

The PWM diagram depicted below is from Instructables AC PWM dimmer

for Arduino file (http://www.instructables.com/id/AC-PWM-Dimmer-for-Arduino/).

Sample code:

Based on the circuit, the brightness of the lamp is controlled using the PWM pins

on the Arduino. In the example below, pin 9 is used.

int led = 9; // the PWM pin the LED is attached to

int brightness = 0; // how bright the LED is

79
int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:

void setup() {

// declare pin 9 to be an output:

pinMode(led, OUTPUT);

// the loop routine runs over and over again forever:

void loop() {

// set the brightness of pin 9:

analogWrite(led, brightness);

// change the brightness for next time through the loop:

brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:

if (brightness == 0 || brightness == 255) {

fadeAmount = -fadeAmount ;

// wait for 30 milliseconds to see the dimming effect

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

This section includes a table of AT Commands that are used when


using ESP8266.

Function AT Command Response

Working AT OK

Restart AT+RST OK [System Ready, Vendor:www.ai-thinker.com]

Firmware AT+GMR AT+GMR 0018000902 OK


version

List Access AT+CWLAP AT+CWLAP


Points +CWLAP:(4,"RochefortSurLac",38,"70:62:b8:6f:6d:58",1)
+CWLAP:(4,"LiliPad2.4",-83,"f8:7b:8c:1e:7c:6d",1)
OK

Join Access AT+CWJAP? Query AT+CWJAP? +CWJAP:"RochefortSurLac" OK


Point
AT+CWJAP="SSID","Password"

Quit Access AT+CWQAP=? Query OK


Point

AT+CWQAP

Get IP AT+CIFSR AT+CIFSR 192.168.0.105


Address OK

Set AT+ CWSAP? Query ssid,


Parameters pwd
of Access AT+ CWSAP=
<ssid>,<pwd>,<chl>, <ecn> chl = channel, ecn = encryption
Point

WiFi Mode AT+CWMODE? Query

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>

TCP/UDP AT+ CIPMUX? Query

Connections AT+ CIPMUX=0 Single

AT+ CIPMUX=1 Multiple

Check join AT+CWLIF


devices' IP

TCP/IP AT+CIPSTATUS AT+CIPSTATUS? no this fun


Connection
Status

Send TCP/IP (CIPMUX=0)


data AT+CIPSEND=<length>;

(CIPMUX=1) AT+CIPSEND=
<id>,<length>

Close TCP / AT+CIPCLOSE=<id> or


UDP AT+CIPCLOSE
connection

Set as server AT+ CIPSERVER= mode 0 to close server mode; mode 1 to open; port =
<mode>[,<port>] port

Set the AT+CIPSTO? Query


server
timeout AT+CIPSTO=<time> <time>0~28800 in seconds

Baud Rate* AT+CIOBAUD? Query AT+CIOBAUD? +CIOBAUD:9600 OK

Supported: 9600, 19200, 38400,


74880,

115200, 230400, 460800,


921600

Check IP AT+CIFSR AT+CIFSR 192.168.0.106


address OK

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>

Watchdog AT+CSYSWDTENABLE Watchdog, auto restart when program errors occur:


Enable* enable

Watchdog AT+CSYSWDTDISABLE Watchdog, auto restart when program errors occur:


Disable* disable

Retrieved from: http://www.pridopia.co.uk/pi-doc/ESP8266ATCommandsSet.pdf

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

Date of Birth : June 20, 1996

Place of Birth : General Santos City

Civil Status : Single

Citizenship : Filipino

Religion : Roman Catholic

Languages Known : Bisaya, Tagalog, and English

Mothers Name : Belinda B. Oquendo

Occupation : Government Employee

Fathers Name : Jacob Neptali J. Oquendo

Occupation : Employee

Educational Background:

Secondary: San Lorenzo Ruiz Academy of Polomolok


Polomolok, South Cotabato 2008-2012
Elementary: Mt. Matutum Christian School
Polomolok, South Cotabato 2002-2008

85
Affiliations:
Engineering Students Organization (ESO)
Member, 2012- 2017

Organization of Electrical and Electronics Engineering Students (OEECES)


Member, 2012- 2017
2nd Year Representative, 2013

Institute of Integrated Electrical EngineersCouncil of Student Chapters


Mindanao State University General Santos City Chapter (IIEE CSCMSU
GSC)
Member, 2014- 2017

BAGWIS-The Official Student Publication of MSU-GSC


Staff Writer, 2012-2013
Editor-in-Chief, 2013-2017

MSU-GSC Debate Society


Member, 2014-2015

Achievements:

1st place - 29th Regional EE Quiz Show


11th IIEE CSC Regional Student Conference
September 2015

Participant - 29th National EE Quiz Show


16th IIEE National Student Conference
February 18, 2017

1st place - 30th Regional EE Quiz Show


12th IIEE CSC Regional Student Conference
September 16, 2016

Participant - 30th National EE Quiz Show


17th IIEE National Student Conference
February 18, 2017

Participant - Research Poster Presentation


3rd Mindanao State University GSC In-house Review
May 9-10, 2017

2nd Place - Research Paper Presentation


3rd Mindanao State University GSC In-house Review
May 9-10, 2017

86
Recipient - Journalist of the Year Award
16th Kabantugan Awards
May 13, 2017

Recipient - Best Public Speaker Award


16th Kabantugan Awards
May 13, 2017

87
JER-MICHAEL F. GIMPAYAN

Address: 095 Romana Cahilsot St. Brgy West,


G.S.C.
Mobile Number: +639085591688
Email Address: gimpayanjermichael@gmail.com
Personal Information:
Gender : Male

Date of Birth : APRIL 10, 1996

Place of Birth : General Santos City

Civil Status : Single

Citizenship : Filipino

Religion : Roman Catholic

Languages Known : Bisaya, Tagalog, and English

Mothers Name : Florence F. Gimpayan

Occupation : Housewife

Fathers Name : Jeremias F. Gimpayan

Occupation : Seaman

Educational Background:

Secondary: General Santos City National High School


Brgy. Calumpang, General Santos City
2008-2012
Elementary: Dadiangas West Central Elementary School
Magsaysay Ave. Brgy. West G.S.C
2002-2008

88
Affiliations:
Engineering Students Organization (ESO)
Member, 2012- 2017

Organization of Electrical and Electronics Engineering Students (OEECES)


Member, 2012- 2017
Fourth Year Representative, 2015-2016

Institute of Integrated Electrical EngineersCouncil of Student Chapters


Mindanao State University General Santos City Chapter (IIEE CSCMSU
GSC)
Member, 2014- 2017
Vice President Internal, 2016-2017

Achievements:

2nd Place - Research Paper Presentation


3rd Mindanao State University GSC In-house Review
May 9-10, 2017

1st Place - Folk Dance (Lowland)


53rd Mindanao State University Intramurals

1st Place - Folk Dance (Lowland)


55th Mindanao State University Intramurals

89

S-ar putea să vă placă și