Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Android Controlled Light PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 113

i

ANDROID CONTROLLED LIGHT


SWITCHING WITH PERSON COUNTER

An Undergraduate Student Research Design Project Presented to the Faculty of


School of Technology
College of Engineering
First Asia Institute of Technology and Humanities
Tanauan City, Batangas

In Partial Fulfillment of the Requirements for the


Degree of Bachelor of Science in Engineering

Dator Ottobrei G.
De Castro, Vianca Minette M.
Tawat, Gregorio S.

April 2016
ii

ABSTRACT

Manual switching of lights proves to be a drag in every class and often leads to

distraction not only in the part of students but also in the part of the instructor and often

leads to unnecessary usage of lights. This study tends to control the switching of the

lights using an android application and also, automatically turn off the lights if the count

reaches zero or there is no one in the room. The Bluetooth module is used to connect with

smartphone to control the lights wirelessly along with the IR sensor that count the person

entering and exiting the room. Prescriptive Model is the methodology used in the study.

The implementation proves to add convenience in controlling the switching of the lights

and minimize unnecessary usage of room lights.


iii

ACKNOWLEDGEMENT

The completion of this student research project would not be possible without the

assistance of other people. All their help and support regardless of its complexity is a

great contribution to the accomplishment of the paper. In line with this, we would like to

offer this endeavor to our Almighty God for the wisdom He bestowed upon us, the

strength, peace of mind and good health in order to finish this research. We also thank

our adviser, Engr. Stanley Aquino for his support and guidance throughout the research.

We also appreciate Engr. Francis Malabanan for giving his valuable comments and

advices that helped us in the completion and success of the study.

A special thanks to the staffs of Tinkbox for assisting us in purchasing the hardware

part of the research. And lastly, we are grateful to our family, Guardino-Dator,

Magsumbol-De Castro, and -Tawat, for their undying moral support, for their

unconditional love and for their unending encouragement throughout the completion of

the paper.
iv

DEDICATION

The researchers would like to dedicate this study to the following:

First and foremost to the Almighty God who gives us strength and determination to

accomplish this research;

To our respective families who always believe and understand us;

To our classmate who supports each other in times of happiness and hardships;

To all the engineering professors for their motivations and advices.


v

TABLE OF CONTENTS

Page

TITLE PAGE i

ABSTRACT ii

ACKNOWLEDGMENT iii

DEDICATION iv

TABLE OF CONTENTS v

LIST OF FIGURES viii

LIST OF TABLES x

LIST OF APPENDICES xii

I. INTRODUCTION 1

Background of the Study 1

Objectives of the Study 2

Scope and Limitations of the Project 2

Significance of the Study 3

Definitions of Terms 4

II. REVIEW OF RELATED LITERATURE 5

III. RESEARCH METHODOLOGY 15

Research Design 15

Method of Data Collection 18

Generation of Alternatives 19
vi

Evaluation of Alternatives 23

IV. TECHNICAL STUDY 29

Project Design 29

Materials and Components Specifications 30

Block Diagram 38

Person Detector 38

Wireless Controller 38

Light Controller 39

Flow Chart 40

State Diagram Machine 40

Hardware Verification 42

V. PRESENTATION AND ANALYSIS OF RESULTS 43

Bluetooth Module Testing and Results 43

Testing using Arduino Serial Monitor 46

Testing of the IR sensor 50

Testing the Android Application 57

Testing of the Prototype 59

VI. SUMMARY, CONCLUSIONS AND RECOMMENDATIONS 64

Summary 64

Conclusions 65

Recommendation 66
vii

BIBLIOGRAPHY 67

APPENDICES 68
viii

LIST OF FIGURES

Page

2.1 Microcontroller Block Diagram 5

2.2. Gizduino Board 7

2.3. Basic UART packet format 8

2.5. Arduino and Android communication architecture 13

3.1. A Five-stage Prescriptive Model of the Design Process 15

4.1. Block diagram of app controlled lighting system 29

4.3. Gizduino X (ATMEGA1281) 31

4.4. Gizduino X board including its parts 31

4.5. Direct Incidence 32

4.6. Indirect Incidence 32

4.7. IR – Photo Diode Sensor circuit 33

4.8. HC – 05 Bluetooth Module 34

4.7. HC – 05 Bluetooth Module 37

4.8 MIT app inventor layout platform 37

4.9 MIT app inventor block diagram platform 38

4.10 Block Diagram for Person Detector 38

4.11. Wireless Controller Block Diagram 39

4.12. Light Controller Block Diagram 39

4.13. Flow chart of the algorithm of light control system 40


ix

4.14. State Diagram of light control system 41

4.15. Hardware Implementation 42

5.1 Sample Serial Monitor simulation 47

5.5 LED responses to different commands 47

5.2 Sample Serial Monitor simulation with simultaneous input 48

5.3 Serial monitor testing of the person counter system 50

5.4. Direct Incidence 51

5.4. Indirect Incidence 51

5.6 Physical representation Direct incidence system 53

5.7 Physical representation Indirect incident system 54

5.8 Actual testing of the sensor 54

5.9 Android application interface 57

5.10 Received commands from the android app 58


x

LIST OF TABLES

Page

3.1 Morphological Chart of Design Alternative 19

3.2 Priority Benchmark of the chosen alternatives for wireless interface 25

3.3 Priority Checkmark for evaluation of alternative of Person detection 27

4.1. AT Commands 36

5.1. Testing of Bluetooth connection range 43

5.2. Testing of Bluetooth module connection limit 44

5.3. Testing of Bluetooth connection time 45

5.4. Bluetooth module connection duration 45

5.5 LED responses to different commands 47

5.6 Person counter using two sensors 50

5.7 Testing of direct incidence Distance Range 52

5.8 Testing of Indirect incidence Distance Range 53

5.9 Testing of the IR Sensor as a person counter ( 5’’ apart) 55

5.10 Testing of the IR Sensor as a person counter ( 10’’ apart) 55

5.11 Testing of the IR Sensor as a person counter ( 20’’ apart) 55

5.12 Results of testing the Android application 59

5.13 Manual switching of lights 61

5.14 Testing of the counter (Entering) 61

5.15 Testing of the counter (Exiting) 62


xi

5.16 Test 1 of the counter in automatic mode 62

5.17 Test 2 of the counter in automatic mode 63


xii

LIST OF APPENDICES

Page

A Prototype Pictures 69

B Source Codes 71

C Specification Documents 80

D Gantt Chart 86

E Curriculum Vitae 89
1

CHAPTER I

INTRODUCTION

Background of the Study

Automation is today’s fact, where things are being controlled automatically, often

used to turn devices OFF/ON automatically. Automation lowers the human judgment to

the lowest degree possible but does not completely eliminate it making things easier and

more innovative.

Nowadays, smart phones are becoming more powerful with reinforced processors,

larger storage capacities, rich entertainment function and more communication methods

and one of the most popular platform for a smartphone is the “Android” operating system

which enables us to create software that runs on it and makes use of its features, such as

multi-touch screen, camera, accelerometer, GPS and Bluetooth. One of the most useful

features of a smart phone is its Bluetooth technology which is used for wireless data

transfer between Bluetooth enabled devices to exchange digital information over short

distances.

In this study, we tend to use an android device to control the lighting system in

the classroom. Also, the presence of students/teachers in the classroom is monitored to

automatically control the lights. Microcontroller, IR sensors and Bluetooth slave module

have been utilized. Microcontroller is used to control the lighting system in the

classroom. IR sensors were used to monitor the number of students in the classroom and

lastly, the Bluetooth module is used to communicate with the android device wirelessly.
2

Objective of the Study

The aim of this project is to design an app – controlled lighting system along with the

following objectives:

 To implement a controlled lighting system in a classroom.

 To implement a wireless controlled light switching using an android application

as an interface.

 To implement universal asynchronous receiver/transmitter (UART) for the

connection of the system to the smart phone.

 To minimize unnecessary usage of room light.

 To know the advantages of using wireless devices to control the lights in the room

 To monitor the presence of students/teachers in the classroom.

 To serve as basis for other studies involving wireless controller.

Scope and Limitation of the Project

The purpose of the project is to provide a light control system for school’s

laboratory room that is implemented using the ARDUINO microcontroller using android

application as the interface. The system also includes a person counter to detect the

presence of people or a person in the classroom. The accessibility of the system is only

limited to teachers and school officials.

With the vast scope of the project come certain limitations. The system is limited

only to certain types of devices basically those with an android operating system. It is not

inclusive of other mobile devices such as an apple device or a windows device. Only one
3

mobile device can only be connected to the Bluetooth module. Using Bluetooth, the

system is limited only for certain distance. The person counter cannot support

simultaneous entering and exiting of a person. The person detection relies primarily on

count and the accuracy of the count is limited.

The research project serves only the purpose of controlling the lighting system

either ON or OFF of the room via android smartphone.

Significance of the Study

This section provides brief description on various significances of the study.

To students and researchers. This study can serve as a reference for students

and researchers in interfacing an arduino to mobile device via Bluetooth. It also provides

information about systems that are useful for further and future studies.

To teachers. This project provides them the convenience of controlling the

lighting system in the classroom. Also it helps them monitor the security of the

classroom.

To the school community. This project helps in saving electricity and at the same

time provide additional energy saving method.


4

Definitions of Terms

For clearer understanding of the terms used in this research study, below are the

meanings of the following:

 Analog-to-Digital Converter (ADC). It is a device that converts a continuous

physical quantity to a digital number that represents the quantity’s amplitude.

 Arduino. It is a single board microcontroller to make the use of electronics in

multidisciplinary projects and more accessible. The hardware consists of an open

source hardware board designed around an 8-bit Atmel AVR microcontroller, or a

32-bit Atmel ARM. The software consists of standard programming language

compiler and a booth loader that executes on the microcontroller.

 Bluetooth. It is a wireless protocol for short-range communications and intended

to replace the cables. With its low energy consumption and low cost, Bluetooth is

a good choice of communication technology for sensor network.


5

CHAPTER 2

REVIEW OF RELATED LITERATURE

This chapter presents the related literature and studies after the thorough and in-depth

search done by the researchers. All the technologies discussed in this chapter are further

used to support the implementation of the research. This chapter will also present the

conceptual framework to fully understand the research to be done.

The Microcontroller

According to Axelson (2014), a microcontroller is a computer-on-a-chip, or a

single-chip computer. The word “Micro” suggests that the device is small, and the word

“controller” suggests that the device can be used to control objects, processes, or events.

Another term to describe a microcontroller is embedded controller, because the

microcontroller and its support circuits are often built into, or embedded in, the devices

they control. A microcontroller is similar to the microprocessor inside a personal

computer. Examples of microprocessors include AT89 series, AT90, ATtiny, ATmega,

ATxmega series (AVR architecture), AVR32 (32-bit AVR architecture), Intel’s 8086,

Motorola’s 68000, and Zilog’s Z80. Standard block diagram of a microcontroller is

shown in figure 2.1.

Figure 2.1. Microcontroller Block Diagram


6

The Arduino Device

According to McRoberts (2011), Arduino is an open-source electronics

prototyping platform. The hardware consists of a simple open-source hardware board

designed around an 8-bit Atmel AVR microcontroller. In another term, an Arduino is a

tiny computer that you can program to process inputs and outputs between the device and

external components you connect to it. The Arduino board is made up of an Atmel AVR

microprocessor, a crystal or oscillator and a 5V voltage regulator.

To program the arduino, the Arduino IDE, which is a piece of free software that

enables you to program in the language that the Arduino understands, is used. The IDE

enables you to write a computer program, which is a set of step-by-step instructions that

you then upload to the Arduino. The Arduino will then carry out those instructions and

interact with whatever you have connected to it. These programs are known as

“sketches”.

Arduino is available in different variants. The most common arduino is the

Arduino Uno. Different variants of arduino is available such as Due Leonardo,

Duemilanove, Mega 2560, Mega ADK, Fio, Arduino,Ethernet, Mini, Nano, Lilypad, and

Bluetooth Arduinos. The choice of arduino board is based on the application. Figure 2.2

shows the gizduino board. The Gizduino is a microcontroller board based on the

ATmega328 and ATmega168.


7

Figure 2.2. Gizduino board

UART (Universal Asynchronous Receiver/Transmitter) Capability of the Arduino

According to George (2011), UART which stands for “Universal Asynchronous

Receiver/Transmitter”, is a serial communication which uses two lines for sending (TX)

and receiving (RX) data. It is an asynchronous communication interface which means a

clock is not needed to send as opposed to synchronous communication. Most

microcontrollers like the Arduino has a built in USART (Universal Synchronous

Asynchronous Receiver Transmitter) which can be configured in UART (Universal

Asynchronous Receiver/Transmitter), USRT (Universal Synchronous

Receiver/Transmitter) Master/Slave.

The Asynchronous Receiving and Transmitting Protocol

According to Kong (2010), asynchronous transmission allows data to be

transmitted without the sender having to send a clock signal to the receiver. The sender

and the receiver, thus, must agree on timing parameters such as the baud rate before the

transmission and special bits are added to each word to synchronize the sending and

receiving units. The sender sends a Start bit, 5 to 8 data bits (LSB first), an optional

Parity bit, and then 1, 1.5 or 2 Stop bits.


8

The start bit is to inform the data is about to send thereby forcing the clock in the

receiver to be in sync with the clock in the transmitter. The receiver and the transmitter

must have an identical baud rate. The individual bits are then being send beginning with

the Least Significant Bit (LSB). Stop bit will be sent to indicate the end of transmission.

If the Stop Bit does not appear when it is supposed to, the UART considers the entire

word to be garbled and will report a Framing Error to the host processor when the data

word is read. Transmitting and receiving UARTs must be set at the same baud rate,

character length, parity, and stop bits for proper operation. The typical format for serial

ports used with PC connected to modems is 1 Start bit, 8 data bits, no Parity and 1 Stop

bit. Figure 2.3 shows a basic UART packet format, 1 Start bit, 8 data bits, 1 Parity bit and

1 Stop bit.

Figure 2.3. Basic UART packet format

Most microcontrollers including arduino uses the simplest UART format which is the

TTL (Transistor-transistor Logic) level UART to communicate with different ICs. Figure

2.4 illustrates how microcontroller connects with different devices.


9

Figure 2.4. Basic UART packet format

Wireless Communication Technologies

Wireless telecommunications enable the transfer of information between two or

more points that are not physically connected. Distances can vary depending on the

environment and technology used for the data transmission. This work focuses mainly on

short-range technologies such as Bluetooth and Wi-Fi.

Wireless Communication using Bluetooth

According to Huang (2009), Bluetooth is a way for devices to communicate with each

other wirelessly over short distances. Every Bluetooth chip ever manufactured is

imprinted with a unique 48-bit address, which is referred to as the “Bluetooth address” or

“device address” so for one Bluetooth device to communicate with another, it must have

some way of determining the other device’s Bluetooth address. This address is used at all

layers of the Bluetooth communication process, from the low-level radio protocols to the

higher-level application protocols. Bluetooth devices will almost always have a user-

friendly name which is usually shown to the user in lieu of the Bluetooth address to

identify a device but it is the Bluetooth address that is used in actual communication. It

will usually take an average of 5 seconds before a device is connected to another device

via Bluetooth connection because the device is changing frequencies is changing

frequencies more than a thousand times a second and there are only 79 possible

frequencies that it can transmit on. It divides the 2.4 GHz band into 79 channels and

employs channel hopping techniques so that Bluetooth devices are always changing
10

which frequencies they’re transmitting and receiving on. Many Bluetooth protocols are

used for communication of devices such as RFCOMM and L2CAP. Once a numerical

address and transport protocol are known, is to choose the port number. Table 1.1 shows

different protocols and their assigned ports.

Table 1.1. Protocol and their assigned ports

Bluetooth Connection Range

Huang (2009), classified Bluetooth devices into three categories depending on

the transmission power levels. Table 1.2. shows the different classifications and their

range. Almost all Bluetooth-enabled cell phones, headsets, laptops, and other consumer-

level Bluetooth devices are class 2 devices.

Table 1.2. Bluetooth power classes

Bluetooth Communication Speed

According to Huang (2009), Theoretically, two Bluetooth devices have a

maximum asymmetric (only one Bluetooth device is transmitting) data rate of 723.2
11

kilobits per second (kb/s) and a maximum symmetric data rate (both Bluetooth device is

transmitting) of 433.9 kb/s. Bluetooth devices is strongly limited by how far apart they

are.

Bluetooth Modules

Huang (2009) describes a Bluetooth modules as devices that provides classes

and utility functions useful for the most common Bluetooth programming tasks.

Bluetooth modules can be classified in either a master/slave – only or a master and slave.

Two or more Bluetooth devices that are communicating with each other and using the

same channel hopping configuration (so that they’re always using the same frequencies)

form a Bluetooth “piconet”. In each piconet, there are a maximum of 8 devices connected

to it. .One device on every piconet is designated the master and the rest is the slave. The

master coordinates communication throughout the piconet. It can send data to any of its

slaves and request data from them as well. Slaves are only allowed to transmit to and

receive from their master. They can’t talk to other slaves in the piconet.

Android

According to Burnette (2008), android is an is an operating system, powered by

Google, for mobile devices such as tablets, smart phones and PDAs. Android is an open

platform which means that this platform can be customized to fit a certain requirements

or real life applications. Android is that popular that there are approximately 300 million

activated android devices in the world. Looking at its architecture, the operating system is

comprises of 5 layers namely Linux kernel, Android runtime environment, Libraries,


12

Application framework, and Application layer. Each one has its designated functions.

The Application Framework layer lies on top of these layers and is the layer used by

developers to create applications.

Analysis and Comparison of SmartHomes

Srirama et al., (2012) made a study that analyses and compares Smart homes

implementation. He tackles different smart home implementations and the medium used

in each implementation.

He reviews different smart home implementations such as Insteon, X10, Z-

Wave, Android@Home, ZigBee and the domotichome. For choosing the best

implementation, several factors such as reliability, Ease of Installation, Communication,

Scalability, and cost must be considered. The cheaper the system the harder it is to install.

The more there are devices the more interference in the environment.

The study focuses more on the Implementation of Wireless-based Home

Automation Systems which rely on two different wireless communication technologies

namely the Bluetooth and the Wi – fi. The system uses arduino and an android app for

communication medium of the system. Arduino was used because it is open hardware

and compared to other prototyping platforms it is the cheapest plus it has a strong and

active community as opposed to other implantation system which is relatively expensive.

Android was considered because of its popularity. In addition, Arduino is highly Android

compatible.
13

For the architecture of the project using Bluetooth, the study uses Arduino

microcontroller with Bluetooth-connectivity, Android phone with Bluetooth-connectivity

and arduino modules such as the LED module for controlling the LED and the thermistor

module for sensing the temperature of the room. For the interface used for

communication of the android and arduino, the app called “Amarino” was chosen. It is an

application developed by Bonifaz Kaufmann which enables the communication channels

for sending and receiving data via Bluetooth between an Arduino-based device and an

Android phone. The block diagram for the this communication is shown in figure 2.5. A

sketch that runs on the Arduino board uses the MeetAndroid library, which uses a serial

port of the Arduino to send and receive data to manage incoming and outgoing messages.

Identifiers such as integers, letters and alphabets are used for communication.

Figure 2.5. Arduino and Android communication architecture

Bluetooth based home automation system


14

This paper describes an application of Bluetooth technology in home

automation and networking environment which proposes a network, which contains a

remote, mobile host controller and several client modules (home appliances) which

communicate with the host controller through Bluetooth devices. The result of this

project is a Home Automation Protocol (HAP), developed by the authors in order to

facilitate the master–slave communication in a home automation network which allows

the user to monitor and control different appliances connected over a Bluetooth network

in home environment. They suggested a parallel interface for faster communication of

devices. In their project, one device is associated with one Bluetooth module thus

increasing the controlling appliances also increases the needed Bluetooth module or one

device per one Bluetooth module is suggested. They also suggested the use of the

internet to integrate the design and to allow better control for the appliances.
15

CHAPTER III

RESEARCH METHODOLOGY

This chapter outlines the research methodology used in conduct of this study. This

chapter includes the Research Design, Methods of Data Collection, Generation of

Alternatives and Evaluation of alternatives.

Research Design

A Prescriptive research methodology was used for this study. This model

prescribes what must be done during the design process. This model includes five phases

namely the Problem Definition, Conceptual Design, Preliminary Design or Embodiment

of Schemes, Detailed Design and Design communication. Figure 3.1 shows each phase

showing the input(s) to that phase.

Figure 3.1. A Five-stage prescriptive model of the design process


16

As shown, the design stages are represented by rectangles with round corners and

its corresponding outputs are represented by ovals.

Problem Definition. In this phase, the problem statement is clearly defined,

clarifying objectives, identifying constraints, establishing functions, and gathering the

other information. The study aims on designing and implementing an app – controlled

room lighting system that prevents unnecessary usage of room lights of unauthorized

students or teachers. The study also aims to give comfort in controlling the lights in the

classroom. The device has to detect the presence of students or teachers inside the

classroom and automatically turn the lights “off” when there is no student in the

classroom. The device can only be controlled by an authorized teacher or personnel to

prevent students from using classroom lights when they are not unauthorized to do so.

Conceptual Design. After clarifying objectives, identifying constraints, and

establishing functions, its conceptual design is initiated by generating or creating design

concepts. The conceptual design focuses on room light control system objectives,

constraints and functions. Design of alternatives focuses on implementation of wireless

communication and person detection system. Several alternatives for wireless

communication are considered including Wi – Fi communication, GSM, and Bluetooth

communication. The wireless communication will be used to communicate wirelessly

with the smartphone. For person detection system, several sensors are considered as

alternatives such as PIR sensor, thermal sensor and IR sensor.

Preliminary design. After the conceptual design is initiated, the chosen concept is
17

embodied with preliminary versions of their most important attributes. The chosen design

is modeled, analyzed, test and evaluated. The specific wireless communication and sensor

will be selected as the design implementation. Authorized personnel will access the

device by connecting to it via smartphone. A password will be exclusive only to certain

personnel to limit the usage of lights. A command will be sent to the device if automatic

control of lights will be initiated via smartphone. The sensor will then count the number

of person going in or out of the room. Once the count reaches zero, the lights will be

automatically turned off. The lights can be accessed again if exclusive personnel are to

access the lights again by connecting to the device.

Detailed Design. After the chosen design is modeled, analyzed, test and evaluated

the design is refined by working to optimize it. In detail design, the hardware

implementation as well as the android application implementation will be specified.

Detailed design for person detection includes two sensors which will be placed on the

door with one sensor followed by the other. If one sensor sensed first before the other, it

indicates either a person exiting or entering. An android application will be created to be

installed in a smartphone. The detailed design for the android application includes

sending serial information to the wireless module connected to the microcontroller to

command the light control to either turn on or off the lights. The serial information will

be the signal to transition from one state to another. The detailed design for light

controller will also be included.

Documentation. In this phase, the design process is presented in written report including
18

the resulting final design, and its fabrication specifications or prototyping specifications.

Method of Data Collection

Data collection is the process of gathering and measuring information on targeted

variables in an established systematic fashion, which then enables the researchers to

answer relevant questions and evaluate outcomes. In this section, the data collection

method used by the researchers is presented.

Document studies and observation are data collection methods that are used by

the researchers. Observation is methods by which an individual or individuals gather

firsthand data on programs, processes, or behaviors being studied. Observation is used as

it provides opportunity to collect data on a wide range of behaviors, to capture a great

variety of interactions, and to openly explore the research topic. In particular, a structured

observation will be used as the researcher has some prior knowledge about problem. The

operations that are to be observed and the various features that are to be noted or recorded

are decided well in advance. It also produces a large quantity of data with relative case

and also, the observation can begin or stop at any time. Observation will be used to

perceived data. The lighting activity of the classroom will be observed and carefully

analyze if the changes to be made will be beneficial and practical. Document studies

include browsing and analyzing public documents published or produced by an

organization, a group of people or an individual. Documents include public records,

personal papers, secondary data and multimedia. Documents related to the studies are

analyzed to serve as reference.


19

Generation of Design Alternatives

Table 3.1 Morphological chart of design alternatives

Table 3.1 shows the morphological chart developed for the generation of

alternatives. There are at least three possible means of implementing each of the desired

functions. There are also 36 possible design combinations available.

The features of this study include detecting the presence of students or teachers

inside the classroom and controlling the lights wirelessly using microcontroller. These

features can be implemented in several ways and can be considered as design

alternatives. Implementations of wireless communication that are considered are internet,

Global System for Mobile Communications (GSM) and Bluetooth. For human detection,

The OMRON D6T thermal sensor, PIR sensor and an IR – photodiode sensor module are

considered. Lastly, for controlling the lights, servo light switch flicker and relay is

considered.

Implementation for wireless communication. Implementation for wireless

communication to interface with the android smartphone and the microcontroller can be

implemented in several ways. The researchers considered three of the most used wireless

communication that can interface with the Arduino microcontroller. The implementations

of each are as follows.

Internet. The implementation of internet to interface with the microcontroller and a


20

smartphone includes a router and an Ethernet shield. The Ethernet shield which is

connected to a router provides IP for the Arduino which is used to connect to the internet.

The Wi – Fi Arduino library then allows the arduino to serve as either a server accepting

incoming connections or a client making outgoing ones by making an HTTP to which

command requests between the microcontroller and the smartphone exchanges. The

smartphone application then sends a JavaScript Object Notation (JSON) request to the

HTTP which sends serial command to the microcontroller to control the external devices

connected to the microcontroller (i.e., relay switches). Several built – in applications for

connecting Arduino through smartphones are available like Blynk and DomoticHome.

Global System for Mobile Communications (GSM). For the implementation GSM to

interface with the microcontroller, a GSM Shield is required. The GSM shield along with

GSM library allows Arduino to place and receive voice calls, send and receive SMS, and

connect to the internet over a GPRS network. The GSM shield has a modem that transfers

data from a serial port to the GSM network. The modem executes operations via a series

of AT commands. The smartphone app can send data to GSM network which then the

library abstracts low level communications between the modem and SIM card and

translate information into a serial command to control devices like lights connected to the

Arduino.

Bluetooth. The implementation of Bluetooth to interface with the microcontroller and a

smartphone includes a Bluetooth module. A Bluetooth module serves as the slave in the

piconet connection. The Bluetooth module (slave) accepts serial commands from the
21

smartphone or any device connected to it (master). A smartphone connected to the

Bluetooth module, sends serial information and the Bluetooth module translate this

commands to control external devices connected to the Arduino. Several built – in

android application such as “Bluetooth Terminal” and “Amarino” can be downloaded to

the smartphone to allow Bluetooth communication between the smartphone and the

Bluetooth module connected to the Arduino.

Person Detection. Person detection inside the classroom can be implemented using

different sensors. There are many sensors that can be used to detect the presence of a

person inside the classroom. Some of which are motion sensor, heat sensor, CO2 sensor,

face recognition and humanoid shape recognition. In this study, the researchers

considered three alternatives for implementation. The implementations of each are as

follows:

OMRON D6T thermal sensor. This sensor uses thermal sensor to detect room

occupation by sensing the body heat. This sensor can be placed in the middle of the room

to detect human presence. This sensor has a wide range of detection and can easily detect

if there is a person or none even if they aren’t moving. This sensor has a digital output

that can be connected the microcontroller. Also, by connecting this thermal sensor into

an image or video capturing device, this sensor can tell where the person is in a specified

area.

Passive Infrared (PIR) Sensor. PIR sensors primarily sense motion, almost always used

to detect whether a human has moved in or out of the sensors range. This sensor is
22

sensitive to the infrared energy emitted by every living thing. When a person walks into

the detector’s field of vision, the detector “sees” a sharp increase in infrared energy

signaling that a person has passed. Two PIR sensors are needed for this implementation.

One PIR sensor is placed before the other. When one of the sensors detects motion before

the other it means that a person entered or exited the room.

IR-Photodiode sensor. This Sensor module works on the principle of Reflection of

Infrared Rays from a surface. A continuous beam of IR rays is emitted by the IR LED.

Whenever a reflecting surface (white/obstacle) comes in front of the Receiver (photo

diode), these rays are reflected back and captured. Whenever an absorbing surface

(Black/No Obstacle) comes in front of the Receiver, these rays are absorbed by the

surface and thus unable to be captured. Like the PIR sensor, two IR-Photodiode sensor

will be used in for this implementation. One sensor is placed before the other. When one

of the sensors detects motion before the other it means that a person entered or exited.

Light Controller. The microcontroller outputs either high or low signal. The low signal

corresponds to 0 volts DC and the HIGH signal corresponds to 5 volts DC. The high

signal is not capable of turning an AC light bulb thus, a light controller is needed. Two

light controller implementation is considered in this study.

Relay. A relay uses an electromagnetic switch operated by a relatively small electric

current that can turn on or off a much larger electric current. Relay is usually used along

with microcontroller because microcontroller outputs either HIGH (5V) or LOW (0)

signal. This small voltage can be used for switching relays that is connected to a load
23

requiring a high current. In this implementation, relay will be used to switch the lights in

the classroom.

Servo light switch flicker. Servo light switch flicker uses servo motor to flip the light

switch “on” or “off”. It uses the capability of a servo motor to rotate in 180 degrees to

flip the light switch in either direction.

Evaluation of Alternatives

In this section, alternatives that are considered are compared and evaluated to

implement the best design. The advantages and disadvantages of each alternative is

considered and compared. The priority checkmark method for the evaluation of

alternatives is used for the evaluation of alternatives. It is a simpler, qualitative version of

the numerical evaluation matrix. Objectives with high priority are given three checks;

those with medium priority are given two checks, while objectives with low priority are

given only one check.

Implementation for wireless communication. For the implementation of wireless

communication, the cost, the range and the place of installation is considered.

The main advantage of using the internet as the implementation for wireless

communication is its capability to be controlled everywhere. Since the commands can be

exchange through HTTP created by the microcontroller, a commands can be exchanged

everywhere as long as there is an internet connection. The module also has a considerable

price. On the other hand, this implementation requires a router which almost every

classroom lacks. Also, implanting this with a router connected to the AC supplied
24

contradicts one of the objective which is reduction of power consumption. Also, because

it is connected to the internet other unauthorized device anywhere can also send and

receive information. Also, programming Arduino to connect to the internet is a very

complex process and requires knowledge for creating HTML.

The main advantage of using the GSM is it provides a wide scope in controlling

things remotely from any place by just sending an SMS. GSM also provides ease to

easily communicate in a more robust way. Also, the GSM module allows the

microcontroller to be connected to the internet via GPRS. One of the major drawbacks

from using GSM is its cost. One of the most important factors for implementation of a

device is its cost. The GSM module is relatively expensive compare to other.

The main advantage of using Bluetooth as the means of wireless communication

is the ease of connection and the cost. The Bluetooth module can be connected to a

smartphone in less than a minute by just pairing the smartphone and the Bluetooth

module. Also, the availability of Bluetooth in almost every smartphone is a greater

advantage. Considering the cost, the implementation of Bluetooth as the wireless

communication is cheaper compared to other two. The main disadvantage of using this is

the range of connectivity between the Bluetooth module and the smartphone. Also, one

Bluetooth module can only be connected to one device.

Comparing the three alternatives, Bluetooth communication is chosen. Although

the GSM module is the best among the alternatives in terms of functions, Bluetooth

module is chosen as for prototyping purposes. It is much cheaper compared to other two
25

alternatives and appropriate for prototyping. Also, its one to one connectivity and

password ready capability is suitable for the operation of the design. It is also easier to

establish connection between the Bluetooth module and the smartphone. Table 3.2 shows

the priority benchmark of the three alternatives. As shown, the GSM module and the

Bluetooth module each have 9 checks.

Table 3.2 Priority benchmark of the chosen alternatives for wireless interface

Constraint and Priority Bluetooth GSM Wi - Fi


Objective
O: can interface    
with an android
application
O: minimize power    ----
consumption
C: range  ----  
C:power    -----
C: cost   ---- ---
Total  9 9 3

Person Detection. For person detection, accuracy, cost and availability of devices are

factors that are considered for choosing the best alternative.

The OMRON D6T thermal sensor can detect human presence inside a room in a

wide scope. The main advantage of using this thermal sensor is its capability to detect

person with ease in a wide scope. Once placed in an area, this thermal sensor can detect a

person based on its body temperature. The main disadvantage for using this sensor is its

availability. This sensor is produced abroad and not yet available in this country.

The PIR sensor has a great advantage in terms of cost and availability. This sensor

are small, inexpensive, low-power, easy to use and don't wear out. For that reason they
26

are commonly found in appliances and gadgets used in homes or businesses. The

disadvantage in using this sensor is that it only detects motion. Once the person is still,

the PIR sensor will not trigger, hence, there will be an inconsistency in detection. When

used in counting, the PIR sensor is not accurate due to its wide scope and time delay.

The last sensor considered is the IR – Photo Diode sensor. This sensor is capable

of detecting object in front of it. When used in this study, the IR – Photo Diode sensor be

used to detect a person passing in front of it and can be used to count the person entering

or exiting the room. Also, this sensor is cheaper compared to PIR and Omron thermal

sensor. Like the PIR sensor, the IR – Photo Diode sensor can be inaccurate when

counting the person going in or out of the classroom.

Among the alternatives, the OMRON D6T thermal sensor is the best alternative

considered but IR – Photo diode sensor is preferred to use for person detection in this

study. Although the OMRON D6T thermal sensor is the most accurate among the

alternatives, its unavailability is a major drawback for prototyping purposes. Considering

the cost, the PIR sensor and the IR – photo Diode sensor are both cheap and can be used

for prototyping purposes but IR – Photo diode sensor is more accurate than the PIR

sensor.
27

Table 3.3 Priority checkmark for evaluation of alternative of Person detection

Constraint and Priority IR sensor OMRON PIR sensor


Objective thermal
sensor
O: Can monitor    ----
presence of a
person
O: minimize power    ----
consumption
O:Can interface    
with the
microcontroller
C: accuracy  ----  ----
C:range  ----  -----
C:size
Total  8 14 3

The priority benchmark suggest that OMRON D6T is also the best among alternatives as

shown in table 3.3. The OMRON D6T and IR sensor complies with the three alternatives

as shown in the total number of checks. In terms of accuracy and range, the OMRON

D6T is much superior to the IR sensor.

Light Controller. After evaluating the alternatives for person detector and wireless

communication, the alternatives for light controller are evaluated.

Relay is commonly used for prototyping projects involving large current or

voltage. Aside from being a low cost device, it does not affect other devices connected in

the circuit. One disadvantage of using relay is the danger in operating such currents.

Although relay is isolated, there is always a risk involve in operating large currents.

Servo light switch flicker eliminates the risk of operating large currents or

voltages. The servo motor will flip the switch in either on or off direction. One
28

disadvantage of this device is that it is only exclusive for specific type of switch. Also,

the servo motor is complicated and hard to control. It is also more expensive than relay

because one servo motor can only switch one light.

For light controller, the servo light switch flicker is chosen. Aside from the being

safer than relays, it can be implemented in real classrooms. Because the rooms have

identical standard switches, one standard switch is only considered. For prototyping

purposes, the relay is used for it is much cheaper than the servo light switch flicker but

the concept of switching the lights is the same.


29

CHAPTER IV

TECHNICAL STUDY

This chapter covers the technical specifications of the design as well as its

implementation.

Project Design

The whole system is divided into two major parts namely: the central control

system and the wireless controller system. The central control system is composed of the

light controller system and the person detection system whereas the wireless controller

system is composed of the bluetooth module and the android application. The main

algorithm of the design is procesed by the the central control system that receives all the

incoming inputs coming from external devices. A block diagram showing the input and

output connections of the system are shown in figure 4.1.

Figure 4.1. Block diagram of app controlled lighting system


30

As shown, the central control system accepts input from Bluetooth module and person

detector and gives command to the light controller to control the lights in the room. The

smartphone gives serial command to the central control system to turn the lights on or off

wirelessly. The person detector detects the number of person coming in or out of the

room. If the count becomes zero, the central control system will automatically turn the

lights off.

The main devices used in the system are microcontroller specifically gizduino, IR –

Photo Diode sensor, Bluetooth module and android smartphone. The microcontroller

accepts input from the Bluetooth module and the IR – photodiode sensor and gives

command to control the light controller.

Materials and Components Specifications

Central Control system. The central control system is composed of two major

parts namely the light controller system and the person detection system. These parts are

controlled by specifically the Gizduino Microcontroller.

Gizduino. The gizduino microcontroller will accept inputs and output commands to

control the lighting system. Figure 4.3 shows the a Gizduino X board. It is the latest

addition to the family of Arduino compatible controllers. . It is based on an

ATMEGA1281 MCU, a family member of the ATMEGA1280 used in Arduino Mega

board. As shown in figure 4.4 ,the board offers 54 I/Os, 3 hardware SPI, 2- hardware

UART, 128K FLASH, 8K SRAM, and 4K EEPROM.


31

Figure 4.3. Gizduino X (ATMEGA1281)

Figure 4.4. Gizduino X board including its parts

IR – Photo Diode Sensor. IR – Photo Diode Sensor will be used to determine the

number of person in the room to automatically turn the lights on or off. The sensor works

on the principal in which IR LED emits IR radiation and Photodiode sense that IR

radiation. Photodiode resistance changes according to the amount of IR radiation falling


32

on it, hence the voltage drop across it also changes and by using a voltage comparator,

voltage change can be change and output accordingly.

IR LED and Photodiode can be place in two ways: Direct and Indirect. The

direct and indirect incidence is shown in figure 4.5 and 4.6 respectively. As shown, IR

LED and photodiode are kept in front of one another, so that IR radiation can directly

falls on photodiode. If an object falls between them, the falling of IR light on photodiode

stops. Whereas, in in Indirect Incidence, both the IR LED and Photo diode are placed in

parallel (side by side), facing both in same direction. When a object is kept in front of IR

pair, the IR light gets reflected by the object and gets absorbed by photodiode.

Figure 4.5. Direct incidence

Figure 4.6. Indirect incidence


33

Figure 4.7 shows the circuit for IR photo diode sensor. As shown, the Photo

diode is connected in reverse bias, inverting end of LM358 is connected to the variable

resistor, to adjust the sensitivity of the sensor and the non-inverting pin of the op – amp is

connected to the junction of photodiode and a resistor. When a person passes in front of

the IR pair, then IR emitted by IR LED is reflected by the object and absorbed by the

photodiode. When the reflected IR Falls on Photodiode, the voltage across photodiode

drops, and the voltage across series resistor R2 increases. When the voltage at Resistor

R2 gets higher than the voltage at inverting end, then the output becomes HIGH signaling

that an object passes.

Figure 4.7. IR – photo diode sensor circuit

Wireless controller system. The wireless controller system is composed of the android

app and the Bluetooth module. The Bluetooth module is used to connect wirelessly with

the android phone.


34

Bluetooth Module HC – 05. HC-05 module is an easy to use Bluetooth SPP (Serial Port

Protocol) module, designed for transparent wireless serial connection setup. Bluetooth

serial module is used for converting serial port to Bluetooth. These modules have two

modes: master and slaver device. The HC – 05 can be configured as slave or a master

module. Bluetooth module HC – 05 is shown in figure 4.8. The slave modules can not

initiate a connection to another Bluetooth device, but can accept connections, when in

master mode the module can initiate a connection to other devices. In this design, the

researchers only use the Bluetooth module as slave. The specifications of the Bluetooth

module are shown below.

Figure 4.8. HC – 05 Bluetooth module

 Protocol: Bluetooth Specification v2.0+EDR

 Frequency: 2.4GHz ISM band

 Modulation: GFSK

 Emission power: ≤4dBm, Class 2


35

 Sensitivity: ≤-84dBm at 0.1% BER

 Speed: Asynchronous: 2.1Mbps(Max) / 160 kbps, Synchronous: 1Mbps/1Mbps

 Security: Authentication and encryption

 Profiles: Bluetooth serial port

 Power supply: +3.3VDC 50mA

 Working temperature: -20 ~ +75 Centigrade

The HC-05 Bluetooth Module has 6 pins namely the Vcc, GND, TX, RX, Key,

and LED. It comes pre-programmed as a slave. The range for Bluetooth communication

is usually 30m or less. The module has a factory set pin of “1234” which is used while

pairing the module to a phone. To change the default password to make the connection

more secure, the module needs to be configured by going into the AT Command mode.

This is done by connecting the KEY pin to a digital pin and sending AT commands. The

commands for configuring the baud rate, the Bluetooth module name and the password is

shown in table 4.1. The connection of the Bluetooth module to the microcontroller is

shown in figure 4.7. A voltage divider is placed in the TX pin of the microcontroller

going in the RX pin of the Bluetooth module to limit the voltage to 3.3 Volts since the

Bluetooth module can only handle such voltage input.

Table 4.1. AT commands

Command Info

AT+BAUD<setting> Set baud rate


36

1 – 1200

2 – 2400

3 – 4800

4 – 9600

5 – 19200

6 – 38400

7 – 57600

8 – 115200

9 – 230400

A – 460800

B – 921600

C – 1382400

AT+NAME<name> Name – Max 20 characters

AT+PIN<number> PIN – 4 digit number


37

Figure 4.7. HC – 05 Bluetooth module

MIT app inventor. To create the application for the smartphone, the MIT app inventor is

used as it requires little knowledge in JAVA programming. The layout platform and the

block diagram platform of the MIT inventor is shown in figure 4.8 and 4.9. In layout

platform, all the buttons and the designs for the app are placed whereas, in the block

diagram platform, the functions needed for the app to operate is created.

Figure 4.8 MIT app inventor layout platform


38

Figure 4.9 MIT app inventor block diagram platform

Block Diagram

The block diagram for person detector is shown in figure 4.10. As shown, two

sensors are placed as implemented to count the person going in and going out of the

room.

Figure 4.10 Block diagram for person detector

The block diagram for wireless controller is shown in figure 4.10. As shown,

the transmitter pin of the Bluetooth module is connected to the receiver pin of the

microcontroller.
39

Figure 4.11. Wireless controller block Diagram

The block diagram showing the transaction of commands from the


microcontroller to the light controller to control the lights is shown in figure 4.11.

Figure 4.12. Light controller block diagram

Flow Chart for the entire system

The flowchart showing how the entire system will operate to control the lighting

system in the classroom is shown in figure 4.13. As shown, the user needs to connect to

the system using a smartphone with Bluetooth capability using the application installed in

the smartphone. The smartphone can then control the lights by sending serial commands

in the microcontroller. The commands are hidden in the block diagram of the buttons

available in the app. The user can command the light controller to automatically turn off

the lights if there is no person available in the in the room.


40

Figure 4.13. Flow chart of the algorithm of light control system

State Machine

The state diagram of the system is shown in figure 4.14. As shown, the system

comprises of four states namely, the “not connected” state, the “connected”, “automatic”,

“lights on”, “lights off” state. The first state is the “not connected” state where no

smartphone is connected to the smartphone. When a smartphone connects to the device,

the system goes in the connected state. When in this state, the lights can be turned either

on or off. When in “connected” state, automatic counting or monitoring can be accessed

by giving the automatic mode command. This allows the device to monitor the presence

of a student in the room. When the count of student reaches zero, the device will go on

“lights off” state. When in “lights on” or “lights off” state, the lights can still be control.
41

In any state, the smartphone can be disconnected returning back to the “disconnected”

state.

Figure 4.14. State diagram of light control system

Hardware implementation

The hardware implementation for the device is shown in figure 4.15. The front

and back door light installation is shown. As shown, the light controller is located besides

the back door along with a sensor module and the Bluetooth module to count the number

of person exiting the room. The light sensor is to be placed at the light switch to control

the lights. One IR sensor is then placed at the front part of the door to count the number

of person entering the room. A model of which is to be created to serve as the

representation of the project.


42

Figure 4.15. Hardware implementation

Hardware Verification

This section includes the verification plan for hardware implementation of the

system. This includes the test plan for the design. The verification focuses on the

accuracy of the person detection. Two IR – photodiode sensor will be placed with one

sensor following the other. The IR sensor will be tested in certain distances and the count

will be monitored via serial monitor available in the arduino IDE. The Bluetooth

connection range will also be tested to evaluate the distance of control. Lastly, the

android application will be tested by sending serial information and observing the

response of the MCU via serial monitor.


43

CHAPTER V

PRESENTATION AND ANALYSIS OF RESULT

This chapter presents and analysis results of different test cases implemented to

both the hardware and software implementation of the study.

Bluetooth Module Testing and Results

Bluetooth connection range. The Bluetooth module used in the implementation is

the HC – 05 master/slave module which is used to exchange information from the

smartphone to the microcontroller. The connection range of the module is tested first to

be determined its limitations in terms of connection and control range. Table 5.1 shows

the result in testing the connection range of the module. The test consists of 7 trials and

each trial has different distances. The Bluetooth module is powered by a microcontroller

device. Once the device is paired with the Bluetooth module, the android application can

control the lighting system in the classroom through the android application. Table 5.1

shows the range of connection of the Bluetooth device. HC – 05 datasheet indicates that

the distance that the device can be connected to another Bluetooth device is 30 feet or

approximately 10 meters but table 5.1 shows that when in 30 feet range, the connection

become weak and sometimes unable to recognize.

Table 5.1. Testing of bluetooth connection range

Trial Distance (feet) Connection


1 5’ Strong
2 10’ Strong
3 15’ Strong
4 20’ Strong
44

5 25’ Strong
6 30’ Weak
7 35’ No connection

Bluetooth module connection limit. The number of devices that can connect to the

Bluetooth module is also tested. This test is conducted to determine if more than one

device can be connected to the Bluetooth module. Table 5.2 shows the result of the test

conducted for testing the limitation of the number of devices the HC – 05 can be

connected with. As shown, the number of devices that can be connected in the Bluetooth

module simultaneously is only limited to one. It means that the system can be

implemented as one to one connection or one Bluetooth module per device.

Table 5.2. Testing of bluetooth module connection limit

Number of
Can be
Trial Devices at the
connected?
same time
1 1 
2 2 X
3 3 X
4 4 X
5 5 X

Bluetooth connection time. For Bluetooth connection time, different android devices

including smartphones and tablets are tested and the time for connection is determined.

The result is shown in figure Table 5.3. As shown, the test consists of five trials.

Different devices (smartphone or tablet) is used to connect to the Bluetooth module

in each test and the time of connection is recorded. Based on the result, the time of

connection is almost identical to every device. Each device can successfully connect to
45

the Bluetooth module. It means that, almost every device with Bluetooth capability can

connect to the system. The Lenovo (A5000) is chosen to be used for testing the features

of the system as it acquires the fastest connection time and its updated android Operating

system.

Table 5.3. Testing of bluetooth connection time

Time of
Trial Device
connection
1 Myphone (A848) 3s
Lenovo (Tab2
2 3s
A7-30H)
3 Samsung () 3.5s
Lenovo
4 2.5s
(A5000)
5 Alcatel 3.5s

Bluetooth module connection duration. The duration of the Bluetooth connection

is also tested to determine how long the device can stay connected to a smartphone. The

test is conducted by keeping an uninterrupted power supply in the Bluetooth module and

connecting it to an android device given the device will not close the Bluetooth

connection. The result is shown in table 5.4. After 30 minutes, the connection status is

checked. There are six periods in this test which corresponds to three hours. This time is

set according to the maximum length one class. As shown, there is no interruption in the

connection of the Bluetooth module and a smartphone.

Table 5.4. Bluetooth module connection duration

Connection
Time
status
0 
46

After 30 minutes 
After 1 hour 
After 1 hour and

half
After 2 hours 
After 2 hours and

a half
After 3 hours 

Testing using Arduino Serial Monitor

The key part of making this design work is the transfer of serial information from

the smartphone device to the microcontroller. This means that, testing the program of the

microcontroller using the built – in serial monitor in the “Arduino” application is a must

before testing the device using the created android application. The Arduino serial

monitor is used for communication between the Arduino board and a computer or other

devices. The built – in serial monitor is used for verifying codes created by observing

outputs that were force to display in the serial monitor to check if the code goes to a

certain state.

In our design, the main component is the exchange of serial information from the

smartphone to the microcontroller. In these tests, the serial monitor will act as the android

application by sending serial commands to the microcontroller. The researchers then will

see the response of the microcontroller by observing the serial monitor.

In our design, three lights are chosen to be controlled. In this test, the lights are

represented by LEDs. The sample serial monitor output is shown in figure 5.1. The table

showing the response of the system in different serial commands is shown in table 5.5.
47

Figure 5.1 Sample serial monitor simulation

Table 5.5 LED responses to different commands

Command LED1 LED2 LED3 MODE


sent
A ON OFF OFF MANUAL
B OFF OFF OFF MANUAL
C OFF ON OFF MANUAL
D OFF OFF OFF MANUAL
E OFF OFF ON MANUAL
F OFF OFF OFF MANUAL
N OFF OFF OFF MANUAL
Y OFF OFF OFF AUTOMATIC
A OFF OFF OFF AUTOMATIC
B OFF OFF OFF AUTOMATIC
C OFF OFF OFF AUTOMATIC
D OFF OFF OFF AUTOMATIC
E OFF OFF OFF AUTOMATIC
F OFF OFF OFF AUTOMATIC
Y OFF OFF OFF AUTOMATIC
N OFF OFF OFF MANUAL
A ON OFF OFF MANUAL
C ON ON OFF MANUAL
E ON ON ON MANUAL
48

Figure 5.2 Sample serial monitor simulation with simultaneous input

As shown in figure 5.1, the serial monitor output the response of the device in certain

inputs. An input of ‘a’ will turn the first light ON and input of ‘b’ will turn it OFF. Inputs

‘c’ and ‘d’ will turn the light 2 on and off respectively. Inputs ‘e’ and ‘f’ will turn the

light 3 on and off respectively. The command ‘y’ enables the “automatic mode” of the

device whereas the command ‘n’ disables it. As shown in the figure 5.2, as observed,

the program accepts two or more characters and still recognized the commands even

without a delimiter. This characteristic is helpful in making the android application as the

microcontroller accepts multiple character input simultaneously.

Table 5.5 shows the system response in consecutive inputs. The tested system has a count

of zero, or no person has entered the room. As shown, each light can be switched on and

off separately and independent from each other. Also, as shown in the result, while in

“Manual” mode, the lights can be switched on or off regardless of the count. Enabling the
49

“automatic” mode switches off the lights when the count is zero as assumed. The lights

cannot be turned off or on when the count approaches to zero unless the ‘n’ command is

sent again or when someone entered the room that will increase the count. The lights

however can be turned on or off when in “automatic” mode when the count does not

reach zero.

The person counter system is also tested using the serial monitor first. The IR sensor is

replaced first by two push buttons as the concept for detection is similar. The IR sensor

will be tested separately. This test is conducted to determine if the program is functioning

well in terms of its features before placing the real sensors.

Table 5.5 summarizes the result of the test involving the person detection system. The

sensor sends a HIGH signal when triggered an object or a person passed in front of it, and

LOW signal when there is no obstacle in front of it. This characteristic leads the

researchers to use the interrupt concept for counting the person. The interrupt is triggered

at RISING edge meaning if the signal change from HIGH to LOW, the sensor is

triggered. Table 5.6 summarized how the system works. If the sensor 1 is triggered first

than the second, it means that, a person has entered and the count is increased by 1.

Otherwise, if the sensor 2 is triggered first than the second, it means that a person has

exited the room and the count is decreased by 1. If one sensor is triggered but not the

other, it means that the person does not enter nor exit and the previous count is retained.

Lastly, if one sensor is triggered many times but not the other the previous count is also

retained. This method increased the accuracy of counting person.


50

Figure 5.3 Serial monitor testing of the person counter system

Table 5.6 Person counter using two sensors

Detector Sequence Count status


Sensor 1 (not triggered) -> Sensor 2 Retain
(not triggered)
Sensor 1 (triggered) -> Sensor 2 (not Retain
triggered)
Sensor 1 (not triggered) -> Sensor 2 Retain
(triggered)
Sensor 1 (triggered) -> Sensor 2 Increased
(triggered)
Sensor 2 (not triggered) -> Sensor 1 Retain
(not triggered)
Sensor 2 (triggered) -> Sensor 2 (not Retain
triggered)
Sensor 2 (not triggered) -> Sensor1 Retain
(triggered)
Sensor 2 (triggered) -> Sensor 1 Decreased
(triggered)
Sensor 2 (triggered) - > Sensor 2 Retain
(triggered)
Sensor 1(triggered) -> Sensor 1 Retain
(triggered)

Testing of the IR sensor

The range and the accuracy of the IR sensor will be tested in this section. Two

configurations of the IR sensor is considered namely the Direct and Indirect. In Direct

incidence, In Direct incidence, IR LED and photodiode are kept in front of one another,

so that IR radiation can directly falls on photodiode. If an object is placed between them,
51

then it stops the falling of IR light on photodiode. In indirect incidence, both the IR LED

and Photo diode are placed in parallel (side by side), facing both in same direction. In that

fashion, when a object is kept in front of IR pair, the IR light gets reflected by the object

and gets absorbed by photodiode. Figure 5.4 shows the Direct Incidence while Figure 5.5

shows the indirect incidence.

Figure 5.4 Direct incidence

Figure 5.5 Indirect incidence

Table 5.6 shows the distance the distance between the photodiode and IR LED

must be in order to detect obstacle passing by. As shown, when the photodiode and IR

LED is 22 inches apart or less, it can detect object passing between it. More than that

distance, the IR LED and the photodiode no longer communicate. Table 5.7 shows the

testing of the distance the direct incidence can cover. As shown, it covers only a very
52

short distance. When the distance between the object and the photodiode exceeds 3

inches, the IR sensor cannot detect it anymore.

Figure 5.7 and 5.8 shows the implementation considering the two configuration of

the IR Photodiode sensor. As shown, implementing the system in real application, the

distance between the IR LED and photodiode sensor when implemented as an indirect

incidence must be 2.3 feet. This measurement is based on width of the door opening in

FAITH rooms. When implemented as indirect incidence, the minimum distance that the

IR sensor must cover is 5.8 inches base on shoulder width of a person. The shoulder of

the person is considered because it is the widest part of the body. The result shown in

table 5.6 does not meet the target 2.3 feet but its range is enough and can be used to

detect the presence of a person. However, when indirect incidence is used, the system

cannot be used as a person detector. With this results, the direct incidence is chosen as the

implementation. Figure 5.8 shows the maximum distance the IR sensor can be

configured to detect a person passing. As shown, the two LEDS is still ON indicating that

the IR LED and photodiode is still within range.

Table 5.7 Testing of direct incidence distance range

Distance (in.) between the Direct Incidence


photodiode and IR LED
2 
4 
6 
8 
10 
12 
14 
16 
53

18 
20 
21 
24 (2 feet) 

Table 5.8 Testing of indirect incidence distance range

Distance (in) the IR sensor Direct Incidence


can detect
2 
3 
6 
8 
1 
1.2 

Figure 5.6 Physical representation direct incidence system


54

Figure 5.7 Physical representation indirect incident system

Figure 5.8 Actual testing of the sensor

Table 5.9 shows the result of testing the IR sensor for person counter. Object is

used to represent a person. Each object is given 10 seconds, 5 seconds and 2 seconds

interval before the next object will pass. The trial consists of 4 trials with different
55

distances as shown. The two IR sensor is separated by 5’’. Table 5.10 shows the result for

same test but the two IR sensors is separated by 10’’. Table 5.11 shows the result for

same test but the two IR sensors is separated by 20’’. The object with a width of 2.4’’ is

used for testing.

Table 5.9 Testing of the IR Sensor as a person counter ( 5’’ apart)

Trial Distance Object Object device Object device Object device


between IR actual count (10 count (5 count (2
LED and count seconds seconds seconds
photodiode interval) interval) interval)
Sensor
1 5’’ 10 9 6 7
2 10’’ 10 10 7 6
3 15’’ 10 11 5 7
4 21’’ 10 9 7 5

Table 5.10 Testing of the IR Sensor as a person counter ( 10’’ apart)

Trial Distance Object Person/object Object device Object device


between IR actual device count count (5 count (2
LED and count (10 seconds seconds seconds
photodiode interval) interval) interval)
Sensor
1 5’’ 10 10 7 5
2 10’’ 10 10 8 5
3 15’’ 10 10 8 7
4 21’’ 10 10 8 6

Table 5.11 Testing of the IR Sensor as a person counter ( 20’’ apart)

Trial Distance Object Person/object Object device Object device


between IR actual device count count (5 count (2
LED and count (10 seconds seconds seconds
photodiode interval) interval) interval)
Sensor
1 5’’ 10 10 9 6
56

2 10’’ 10 10 8 6
3 15’’ 10 10 8 7
4 21’’ 10 10 8 6

Observing the results of these tests, there are two factors to consider namely the

interval time between each object and the distance of two sensors. As shown in table 5.8,

in 10 seconds interval, the count is accurate, but decreasing the time interval to 5 seconds

or 2 seconds, the count became inaccurate. Decreasing the time interval to 5 seconds, the

count is slightly accurate to that of the actual count. In two second interval, the count is

delayed by almost 1 count per object meaning the count is almost only half of the actual

count. This is because the program is set to response to person not continuing to enter or

exit the room. The program is set such that for example, the sensor 1 is triggered but

sensor two is not triggered, the program will wait for 5 seconds for the sensor two to

trigger and if so, the count will increase, otherwise the count will refresh and ignore that

sensor 1 is already triggered. This suggests that sensor is not applicable to high speed

application. Table 5.9 shows more accuracy than that in table 5.8 due to the fact that the

distance is increased but in two second interval, the count is still inaccurate and almost

did not change. Table 5.10 shows much more accuracy in 10 second and 5 second

interval but the two second interval did not improve much. Observing the result, the

Distance between IR LED and photodiode Sensor is not really a factor as the count is

precise so the distance of 21’ between the IR LED and photodiode sensor is chosen as the

implementation for it occupies larger space. Considering the distance between the two

sensors, 20’’ is the best distance in terms of accuracy but considering the width of the
57

side of the door, the 10’’ distance is chosen. Observing the response of the system, the

system is not applicable in situations where the time difference between two people

entering or exiting is short. Also, the photodiode sensor and the IR LED should be align

with each other to increase the accuracy.

Testing the Android Application

Figure 5.9 shows the android application created using the MIT app inventor. It

consists of five buttons. The Bluetooth button is use to connect to the HC – 05 module

while the three buttons is use to control the switching of lights. The Automatic mode

button is used to allow automatic mode or disable automatic mode. In this test, the serial

monitor in the laptop displays the commands sent by the smartphone. The sample testing

using serial monitor is shown in figure 5.10.

Figure 5.9 Android application interface


58

Figure 5.10 Received commands from the android app

Table 5.12 shows the the result of testing the android application using the serial

monitor by displaying the result in serial monitor. As shown, when the light 1 button is

clicked when the button display “ON”, the command sent is ‘a’ meaning the light 1 will

turn on. When the light 2 button is clicked when the button display “ON” light 2, the

command sent is ‘b’ and light two will turn on and same goes to light 3 button but this

time command ‘c’ is sent. Otherwise, if the button display is initially “OFF” the process

will be reversed. Lastly, when the automatic mode button displays “ALLOW” initially,

command ‘y’ will be sent otherwise, command ‘n’ is sent. Also, when opening the app,

the display button is set to “ON” for three buttons and “ALLOW” for automatic mode

button.
59

Table 5.12 Results of testing the android application

Buttons clicked Button Display Commands sent Button Display

after

Light 1 ON a OFF

Light 2 ON c OFF

Light 3 ON e OFF

Automatic mode ALLOW y DONT ALLOW

Light 1 OFF b ON

Light 2 OFF d ON

Light 3 OFF f ON

Automatic mode DONT ALLOW n ALLOW

Testing of the Prototype

The prototype consists of model of classroom, one AC LED bulb, two 5 Volts DC

LED, the relay module, the Bluetooth module, two PIR sensors and the microcontroller.

The relay module is used as the controller of the LED bulb. A relay is an electrically

operated switch that allows you to turn on or off a circuit using voltage and/or current

much higher than the Arduino could handle. There is no connection between the low

voltage circuit operated by Arduino and the high power circuit. The relay protects each

circuit from each other. The two IR sensors are placed before the door to model the

counting system. The lights are placed at the roof the room model. Table 5.13 shows the
60

sequence of operation of manually controlling the lights. The “automatic mode” is

disabled. As shown, gray code is used to cover all possible scenarios. The result shows

that the three lights can be controlled independently. Table 5.14 shows the results of

testing the counter in 10 trials. Each trial, 8 objects entered the room. The actual count of

the object that has entered is compared to the count shown in the app. As observed, the

actual count does not match the count shown in the app. A test is also conducted when

the objects exits the model. Table 5.15 shows the result of that test which also consists of

10 trials and each trial is a continuation of the previous test. As shown, 8 objects have

exited and the count is zero which matches that of the count shown in the app. This is

because; the program does not accept negative numbers. Meaning, if the count reaches

zero, the count is no longer decremented. Although in final count, the actual count and

the count shown in the app is equal, table 5.16 and 5.17 shows the effect of incorrect

exiting count. Another test is conducted and from time to time, the actual count is

monitored. Two tests were conducted for verification. The system is switched to

“Automatic” mode. As shown, the count is already zero in the app and the lights turned

off even if the actual count does not reach zero. The result shows the inaccuracy of the

IR sensor as the sensor for person counter but the data shown are precise.
61

Table 5.13 Manual switching of lights

Table 5.14 Testing of the counter (Entering)


62

Table 5.15 Testing of the counter (Exiting)

Table 5.16 Test 1 of the counter in automatic mode


63

Table 5.17 Test 2 of the counter in automatic mode


64

CHAPTER VI

SUMMARY, CONCLUSIONS AND RECOMMENDATIONS

This section contains the summary, conclusions and recommendation based on the test

result of the study.

Summary

Manual switching of lights proves to be a drag in every class and often leads to

distraction not only in the part of students but also in the part of the instructor. Also,

manual switching of lights often leads to unnecessary usage of lights due to some

students using the classroom along with the lights in their vacant period. Due to these

situations, controlled switching of lights is necessary and this leads the proponents to

develop an android application to wirelessly control the switching of classroom lights

along with person counter to monitor the presence of students in the room to

automatically turn off the lights.

The function of the study is to control the switching of the lights using an android

application and also, automatically turn off the lights if the count reaches zero or there is

no one in the room. These functions are accomplished by the use of Bluetooth module,

the MIT app inventor and the IR Sensor. The Bluetooth module is used to connect with

smartphone to control the lights wirelessly. The IR sensor is used to count the person

entering and exiting in the room to automatically turn off the lights. A developed android

application is used to interface with the Bluetooth module to give serial commands to the

microcontroller to switch the lights.


65

Conclusions

After analysing the results gathered using several tests, the researchers were able

to conclude that:

 The light switching can be implemented wirelessly by an android application. The

wireless light switching is accomplished by sending serial commands to the

microcontroller to switch the desired lights.

 The advantage of using wireless devices such as smartphone to control the light

switching is the ease of installation and convenience in the part of the user.

 IR sensors can be used to detect the presence of students or teachers in the room

by using it as a counter.

 The usage of lights can be made exclusive to certain personnel by the use of

android application such that only allowed personnel is able to use the android

application and can be connected to the light controller that can minimize

unnecessary usage of lights.

Recommendation

For future researchers of the study, the proponents recommend to consider the

following:

 For Software Recommendation

 An app creator with better layout and features.


66

 For Hardware Recommendation

 Due to limited range of connection, a better wireless technology such as

WI – Fi can be used.

 Due to inaccuracy in counting, better and faster sensor for person

counter/detector is recommended.

 An added feature such as light dimming is recommended to control the

light intensity in the room.


67

BIBLIOGRAPHY

Huang et al., (2005), Bluetooth for Programmers.

Retrieved from:

http://people.csail.mit.edu/rudolph/Teaching/Articles/BTBook.pdf

Axelson (1998), The Microcontroller Idea Book.

Retrieved from:

https://www.bookdepository.com/Microcontroller-Idea-Book-Jan-

Axelson/9780965081900

N. Sriskanthan et al., (2002), Bluetooth based home automation system ,

Retrieved from:

https://pdfs.semanticscholar.org/a001/5665acb00ddf1491aec436e47cfb75835b82.pdf

Tartu (2012), Analysis and Comparison of Smart Homes.

Retrieved from:

https://comserv.cs.ut.ee/home/files/thesis.pdf

Dym et al., (2014) ENGINEERING DESIGN: A PROJECT-BASED INTRODUCTION

Retrieved from:

https://schoology.com
68

APPENDICES
69

APPENDIX A

Prototype Pictures
70
71

APPENDIX B

Source Codes

#include <TimerOne.h>//include libraries


// Pin 13 - LED
72

int led = 15;


int led2 = 14;
int led3 = 13;
int state;
volatile long previous_millis = 0;
volatile int enter = 0;
volatile int ex = 0;
volatile int person = 0;
volatile int count = 0;
volatile long previous_enter = 0;
volatile long previous_exit = 0;
int allow_automatic = 0;
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

pinMode(3, INPUT);
attachInterrupt(1, entering, RISING);

pinMode(21, INPUT);
attachInterrupt(2, exiting, RISING);
Timer1.initialize(500000);//0.5ms
Timer1.attachInterrupt(count_second);
}

void count_second ()
{
Serial.println(count);
}
void loop() {
if (Serial.available() > 0)
{
state = Serial.read();
}

if (state == 'a') {
if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
}
73

else if (state == 'b') {


if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led, LOW);
}

else if (state == 'c') {

if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))


digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
}

else if (state == 'd') {


if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led2, LOW);
}

else if (state == 'f') {


if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led3, LOW);
}

else if (state == 'e') {


if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led3, HIGH);
}
else if (state == 'n') {
allow_automatic = 0;
}
else if (state == 'y') {
allow_automatic = 1;
}

if (person == 2)
{
count ++;
Serial.println(count);
person = 0;
}
else if (person == 1)
{
count --;
74

if (count < 0 ) count = 0;


Serial.println(count);
person = 0;
}

if ((count == 0) && (allow_automatic == 1))


{
digitalWrite(led, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}

void entering()
{
if ((millis() - previous_millis) > 300)
{
previous_millis = millis();
if (ex == 1 && ((millis()- previous_exit) < 5000))
{
person = 1;
ex = 0;
}

else
{
enter = 1;
previous_enter = millis();
}

}
}

void exiting ()
{
if ((millis() - previous_millis) > 300)
{
75

previous_millis = millis();
if (enter == 1 && ((millis()- previous_enter) < 5000))
{
person = 2;
enter = 0;
}
else
{
ex = 1;
previous_exit = millis();
}
}
}

//for testing

#include <TimerOne.h>//include libraries


// Pin 13 - LED
int led = 15;
int led2 = 14;
int led3 = 13;
int state;
volatile long previous_millis = 0;
volatile int enter = 0;
volatile int ex = 0;
volatile int person = 0;
volatile int count = 0;
int allow_automatic = 0;
volatile long previous_enter = 0;
volatile long previous_exit = 0;
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

pinMode(3, INPUT);
attachInterrupt(1, entering, RISING);
76

pinMode(21, INPUT);
attachInterrupt(2, exiting, RISING);
Timer1.initialize(500000);//0.5ms
Timer1.attachInterrupt(count_second);
}

void count_second ()
{
// Serial.println(count);
}
void loop() {
if (Serial.available() > 0)
{
state = Serial.read();
}

if (state == 'a') {
if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

Serial.println("Input: 'a':Light 1 is ON");


state = 'j';
}

else if (state == 'b') {


if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led, LOW);
Serial.println("Input: 'b':Light 1 is OFF");
state = 'j';
}

else if (state == 'c') {

if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))


digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("Input: 'c':Light 2 is ON");
state = 'j';
}

else if (state == 'd') {


if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
77

digitalWrite(led2, LOW);
Serial.println("Input: 'd':Light 2 is OFF");
state = 'j';
}

else if (state == 'f') {


if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led3, LOW);
Serial.println("Input: 'f': Light 3 is OFF");
state = 'j';
}

else if (state == 'e') {


if (allow_automatic == 0 || (allow_automatic == 1 && count > 0))
digitalWrite(led3, HIGH);
Serial.println("Input: 'e': Light 3 is ON");
state = 'j';
}
else if (state == 'n') {
allow_automatic = 0;
Serial.println("Input: 'n' AUTOMATIC MODE OFF");
state = 'j';
}
else if (state == 'y') {
allow_automatic = 1;
Serial.println("Input: 'y' AUTOMATIC MODE ON");
state = 'j';
}

if (person == 2)
{
count ++;
Serial.write("A person has entered Count: "); Serial.println(count);
person = 0;
}
else if (person == 1)
{
count --;
if (count < 0 ) count = 0;
Serial.write("A person has exited Count: ");Serial.println(count);
person = 0;
}
78

if ((count == 0) && (allow_automatic == 1))


{
digitalWrite(led, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}

void entering()
{
if ((millis() - previous_millis) > 300)
{
// Serial.println("sensor 1, triggered");
previous_millis = millis();
if (ex == 1 && ((millis()- previous_exit) < 5000))
{
person = 1;
ex = 0;
}

else
{
enter = 1;
previous_enter = millis();
}

}
}

void exiting ()
{
if ((millis() - previous_millis) > 300)
{
//Serial.println("sensor 2, triggered");
previous_millis = millis();
if (enter == 1 && ((millis()- previous_enter) < 5000))
79

{
person = 2;
enter = 0;
}
else
{
ex = 1;
previous_exit = millis();
}
}
}
80

App Code
81
82
83
84
85
86

APPENDIX C

Schematic Diagrams
87
88
89

APPENDIX D

Device specifications
90
91
92
93
94
95

HC-05 -Bluetooth to Serial Port Module Overview HC-05 module is an easy to

use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial

connection setup. Serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR

(Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and

baseband. It uses CSR Bluecore 04-External single chip Bluetooth system with CMOS

technology and with AFH(Adaptive Frequency Hopping Feature). It has the footprint as

small as 12.7mmx27mm. Hope it will simplify your overall design/development cycle.


96
97
98
99

Most useful AT commands are


AT : Ceck the connection.
AT+NAME : See default name
AT+ADDR : see default address
AT+VERSION : See version
AT+UART : See baudrate
AT+ROLE: See role of bt module(1=master/0=slave)
AT+RESET : Reset and exit AT mode
AT+ORGL : Restore factory settings
AT+PSWD: see default password
More detailed AT commands are given in the 1st pdf.
For HC06: On arduino serial monitor type "AT" (without the quotes) and
press enter, "OK" will confirm AT mode. Unlike HC05, you can't see the
default name or baud rate. You can only change them. To change name type
AT+NAMEDESIRED NAME, notice that there should be no space between
the command and name. The module will reply OKyour set name. For
example, AT+NAMEPROTOTYPE will set the name to PROTOTYPE. To
change baud rate, type AT+BAUDX, where X=1 to 9.
1 set to 1200bps
2 set to 2400bps
3 set to 4800bps
4 set to 9600bps (Default)
5 set to 19200bps
6 set to 38400bps
7 set to 57600bps
8 set to 115200bps
so sending AT+BAUD4 will set the baud rate to 9600.
For Tera Term write down the commands somewhere else and paste it on the
console by right clicking. No need of pressing enter. The command will be
executed immediately and confirmed.
HC 06 AT commands are limited, all I could find are given here.
100

AT : check the connection


AT+NAME: Change name. No space between name and command.
AT+BAUD: change baud rate, x is baud rate code, no space between
command and code.
AT+PIN: change pin, xxxx is the pin, again, no space.
AT+VERSION
101

You might also like