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

1

LOW-COST RESIDENTIAL SECURITY SYSTEM

BACHELOR’S THESIS

Degree Programme in Automation Engineering

Valkeakoski, date

Thanh Tien Nguyen


2

ABSTRACT

Automation Engineering
Valkeakoski

Author Nguyen Tien Thanh Year 2018

Subject Low-cost Residential Security System

Supervisor(s)

ABSTRACT

The main focus of this thesis was home security system. The author provided
some information on security system and how they are usually designed in
modern days. The thesis topic is practical in a way that it covered many
aspects of a normal security system. However, the features that made it
specific were the low-cost accessories and easy-to-maintain feature. This
topic was appropriate for a Bachelor’s thesis for its reasonable depth of
knowledge. Moreover, the experience gained from completing the thesis
project was great for the author, especially in the field of home security.

The objective of the project was to provide a demonstration of how a basic


home security system works. The features included into the project were as
follows: a password locked door, intruder detector, an alarm system and a
wireless interaction between the system and its owner.

To accomplish the goal of this project, Arduino Uno was chosen as the main
controller, which controlled the whole system. Most of the work involved
coding with software Arduino version 1.8.5 for Windows.

After thoroughly studying the components and putting them together, the
system was put to a test and it completed the test successfully. The detection
devices worked as intended, as well as the security measures when the system
was triggered. The control panel also worked perfectly as a simple yet
effective communication method between the users and the system.

Keywords: Residential security, Arduino Uno, PIR sensor, 3x4 Keypad, 16x2 LCD I2C,
SIM900 module.

Pages: 50 pages including appendices 12 pages


3

CONTENTS

1 INTRODUCTION TO THE PROJECT ................................................................. 5

2 HOME SECURITY ................................................................................................... 6


2.1 History of home security ..................................................................................... 6
2.2 Statistics of home security................................................................................... 7

3 HOME SECURITY SYSTEM IN DETAIL............................................................ 7


3.1 Overview ............................................................................................................. 7
3.2 Control panel ....................................................................................................... 7
3.3 Sensor .................................................................................................................. 8
3.3.1 Door/window sensor ................................................................................ 8
3.3.2 Motion sensor ........................................................................................ 10
3.3.3 Gas sensor .............................................................................................. 11
3.4 Surveillance camera .......................................................................................... 12
3.5 High decibel siren.............................................................................................. 13
3.6 Security company signs and stickers ................................................................. 13

4 LOW-COST SECURITY SYSTEM COMPONENT DETAILS ........................ 14


4.1 Overview ........................................................................................................... 14
4.2 Controller – Arduino Uno ................................................................................. 14
4.2.1 Introduction of Arduino ......................................................................... 14
4.2.2 Characteristics of Arduino Uno ............................................................. 16
4.2.3 Arduino software (IDE) ......................................................................... 18
4.3 Control panel – Keypad and Liquid Crystal Display (LCD) ............................ 20
4.3.1 3x4 matrix keypad ................................................................................. 20
4.3.2 16x2 LCD .............................................................................................. 21
4.3.3 Inter-Integrated Circuit (I2C): ................................................................ 22
4.4 Motion sensor and Door/window sensor ........................................................... 24
4.5 Alarm................................................................................................................. 24
4.6 Security camera ................................................................................................. 25
4.7 Relay module..................................................................................................... 25
4.8 Wireless control - SIM900 module ................................................................... 27
4.8.1 SIM900 module introduction ................................................................ 27
4.8.2 UART communication protocol ............................................................ 27

5 LOW-COST SECURITY SYSTEM IN OPERATION ....................................... 28


5.1 System setting up .............................................................................................. 28
5.2 System communication ..................................................................................... 29
5.3 Security measures .............................................................................................. 30

6 ANALYSIS OF A LOW-COST SECURITY SYSTEM . ERROR! BOOKMARK


NOT DEFINED.

7 CONCLUSION ........................................................................................................ 35
4

REFERENCES ............................................................................................................... 36

APPENDICES
Appendix 1 ARDUINO PROJECT CODE
5

1 INTRODUCTION TO THE PROJECT

Home Security is not something new. It has been here since the Stone Age.
People at that time used rock, branches and weapons of all kind to keep
predators away. As time progressed, ways of protecting one’s property
changed gradually. And now, in our time, we use the much more advanced
and less lethal system to ensure safety of our property. That is the Automatic
Home Security System.

Home security has always been one of the most desired systems of every
household in the world. Not only does it scare those that have their eyes on a
residence with its visible components, for instance, a camera, but it also
works well when an intrusion does happen. The system helps saving a fortune
along with many people’s lives. However, the problem is that price for one
cheap security system is still costly, not to mention the cost for security
companies who will arrive in cases of intrusion, cost for faulty detection.
With so many things that need to be paid, people are extremely discouraged.
This is especially true in developing countries, where the number of
households that actually implement a security system occupies a small part,
hence the increase in theft and burglary.

From that thought, the project Low-cost Residential Security was born. It
aims to help those who do not want to invest too much in high end security
systems but still want to have a proper way to protect their property. The
system was built around an Arduino Uno as the controller. It has a motion
sensor, a combination of LEDs and a buzzer to scare away intruders, and a
password system to disable/enable the security. It also has wireless options to
disable/enable the system and provides a way to contact house owners if they
are not at home in case of intrusion.

In this thesis, there are three main parts. In the first part, the author provides
theory about history of home security, some information on a common
security system nowadays. After the first part, readers will get a general
understanding of a normal home security system. In the second part, the
system details, which include all the components along with their function,
are shown to give a better view of what this security system has to offer. By
carefully describing which role each component plays in the system, the
viability of this low-cost system can be proven, in terms of protection level
and its financial advantages, to some extent. In the last part, a comparison
between this system and common security systems is made to effectively
point out the advantages and disadvantages of the low-cost system.

The software used in this project was Arduino IDE version 1.8.5. This is a
program that helps write and loads codes into Arduino easily. It also contains
many useful libraries that help reduce the complexity of the code. The reason
why Arduino was chosen mainly was for its low price, flexible coding and it
being easy to be maintained or replaced, which served the aim of this project
nicely.

This project was carried out under the supervision of a HAMK UAS
professor. With his guidance and advice, the project was completed
successfully.
6

2 HOME SECURITY

2.1 History of home security

A security system consists of means or method with which something is


protected from being damaged or taken away unwillingly. Home security
system are networks of electronic devices put together with a central
processor to defend residents against burglars and thieves. This is the
definition that we see nowadays.

However, home security is not something new that appeared in the modern
time. It appeared long time ago. Some information of home security in the
past is as follows:
 Human, at first, used branches, rocks, weapons like slingshots and
bows to keep wild animals at bay. Later in time, people rescued wolf
cubs that were abandoned by their packs and raised them to secure
their possessions. This eventually led to guard dogs that we know of
today. In ancient Egypt, trenches were dug around towns, fortresses,
castles and filled with water, spikes in order to protect people from
intruders.
 When World War I ended, crime rate increased dramatically.
Therefore, the Americans tried to find ways to protect their property
and themselves. During this time, many homeowners subscribed to a
service which was called door shakers: a group of night watchmen
would shake doors of subscribers’ houses each night to make sure
they were locked. More advanced and wealthier people had their
hands on an alarm system which consisted of electromagnetic
contacts that were placed on doors and windows. Anytime doors or
windows were opened while having this system on, the alarm would
be set off and a central station monitoring the system would send a
guard to that residence.
 In the 1940s, video surveillance technology was developed. However,
it wasn’t until the 1970s that the technology would receive its
deserved attention and was used as part of a security system. In 1966,
Marie Van Brittan Brown, along with her husband Albert Brown,
invented the first video home security system with remotely-
controlled doors. This system consisted of four peepholes placed on a
front door and a motorized camera that could move up and down to
see through the peepholes. The control panel, located in a room
separated from the camera, had features such as an intercom to speak
to visitors, a switch to lock the door and an alarm button to activate
the alarm. This was meant for domestic uses only, but its
effectiveness had attracted many businesses and they began to install
the system also.
(Smith, 2016)

With technology ever evolving, home automation system is also in constant


development. Being one of the system’s most important parts, the field of
security system has never been left outdated or unwanted. For such reasons,
home security system is an extremely potential field that may still be one of
the main focuses of every automation system in the future.
7

2.2 Statistics of home security

The impact of security system on the world is unquestionable. To prove its


influence, here are some statistics:
 In 2016, a report by FBI showed that there were nearly 1.6 million
burglaries. Average loss because of burglaries was 2,361 dollars.
 There are only around 14% of burglary cases were solved, according
to FBI’s crime statistics of 2014.
 In 2010, there were roughly 36 million security systems in the United
States and half of which were in homes.
 In 2003, a study was conducted in United Kingdom and it showed
that residences without a security system are 2 to 3 times more likely
to be targeted by burglars than those with security measures.
 A study carried out by the University of North Carolina Charlotte
showed that among over 400 arrested burglars, over 80% of them said
that they would first try to figure out if a security system was installed
before making a break-in. Around 60% confirmed that they would
change targets if there was presence of an alarm.
(Home Alarm, 2018;
SafeWise, n.d )

These statistics further emphasize the importance of having a proper security


system, as the crime rate is increasing day by day. Moreover, knowing that a
proper security system is here guarding you puts your mind at ease for a good
night sleep.

3 HOME SECURITY SYSTEM IN DETAIL

3.1 Overview

There are many types of home security system. Some may have extra features
that others do not have. However, according to SafeWise(n.d), a security
system review site, a typical home security system consists of main features
as detailed below:
 A control panel that acts as the main controller of the system.
 Door sensors and window sensors, which are usually reed switches.
 Motion sensors inside and outside the house.
 Surveillance cameras, either wired or wireless ones.
 A siren with high decibel (125 decibel).
 Stickers on doors, windows or yard signs of the security company in
charge.

3.2 Control panel

The control panel is a device that exists in every type of an electrical system.
It acts as a common method of communication between users and the system.
It is a basic but extremely important part of a security system, where all
actions take place. These include:
8

 Arming/disarming the system


 Controlling devices like lights and siren.
 Triggering alarms or turning them off.
 Communicating with the company in charge of monitoring the alarm.
 Testing system for any broken part.
Some might come with extra features like voice command or being
programmed so they can be controlled with remote controls. As the centre of
a security system, the control panel has always been an effective tool to give
users a total control of their security. An example of a control panel can be
seen in Figure 1.

Figure 1. Frontpoint Security’s Control Panel


(Frontpoint Security, n.d).

3.3 Sensor

A sensor is a component whose purpose is to detect and make a response to


inputs from surrounding physical environment such as light, heat, motion,
pressure, moisture. From input reading, the sensor produces a signal which
can be used for processing or controlling system. Such features make sensors
exist as key parts in almost every electrical system in the world, and security
system is no exception.

In a security system, the selection of sensors is quite diverse. Most commonly


used ones are door/window sensors, motion sensors and gas sensors. These
types of sensors provide necessary protection for one’s property.

3.3.1 Door/window sensor

As mentioned above, these sensors are usually reed switches combining with
magnets and they prove to be very efficient in detecting intrusion. These
kinds of sensor are usually placed on doors and windows where burglars most
likely enter through.
9

Reed switch is basically an electromagnetic switch. It was first invented in


Bell Telephone Laboratories in 1936 (Magnasphere, n.d). A reed switch
consists of a pair or more of ferrous reeds. They are wrapped inside a glass
tube-like cover, which become magnetised and either move together (for
normally open reed switch) or separate (for normally closed reed switch)
when a magnetic field is present. A normally open reed switch is as shown in
Figure 2.

Figure 2. Principle of operation of a reed switch


(Cara Giaimo, 2013).

Figure 3. A reed switch (Sparkfun Electronics shop, n.d).

A typical reed switch is shown in Figure 3.


A reed switch acts like a normal mechanical switch while having advantages
such as:
 Zero mechanical wear: Having no physical pressure applied to it, the
switch remains unaffected by mechanical wear.
 Flexible operating environment: The switch can be developed in such
a way that even if it is placed deep within a system, it can still be
activated by a strong and discreet magnet.
 Does not need voltage supply: It is triggered by magnetism.
 Atmospheric corrosion protection: Being sealed within a glass tube
away from the atmosphere gives the reed switch protection from
atmospheric corrosion.
(first4magnets.com, n.d.)
10

In home security system, reed switches, as door sensors, are usually set up as
shown in Figure 4.

Figure 4. Door sensor


(Business Security Alarm, 2014).

Usually, a magnet is attached to the door or window and a normally open reed
switch is nearby but is not placed on the object like the magnet. This setup
creates a closed circuit. If the door or window is opened, the magnet is
consequentially pulled away from the reed switch, which breaks the circuit
and, in turn, triggers the alarm.

3.3.2 Motion sensor

A motion sensor’s function is, as its name implies, to detect any motion made
within its range of scanning. Having such use makes motion sensor a reliable
component of any home security system.

SafeWise(n.d) points out that there are quite many types of motion sensors
that are used in home security. Some of those are:
 Passive Infrared (PIR) Sensor: Made of pyroelectric sensor, it can
detect the amount of change in infrared radiation, or body heat,
emitted from objects within its detection range. If someone moves
within its field of view, the sensor will be triggered. (Figure 5)
 Microwave Sensor: It sends microwave pulses out and then analyses
the reflection that bounces off surfaces of objects. The area that the
microwave sensor covers is larger than that of an infrared sensor.
However, the sensor is more expensive and unprotected from
electrical interference. (Figure 6)
11

Figure 5. PIR sensor Figure 6. Microwave sensor


(Sumeet Eshop India, n.d) (IndiaMART, n.d)

Despite being quite effective, these sensors still make many false alarms,
which may prove troublesome. In order to reduce such event, many modern
motion detectors combine various technologies. This is called Dual-
Technology motion sensor. For instance, the two sensors mentioned above
can be combined. These types of sensors work in different areas of the
spectrum, PIR sensor is passive and Microwave sensor is active. In order to
trigger the alarm, both sensors must be triggered, which decrease the chance
of false alarms. However, this combination is not guaranteed free of false
alarms and it reduce detection probabilities, in turn increase the chance of
intruders bypassing the security system. Based on a security system’s design,
motion sensors selection may vary.

3.3.3 Gas sensor

Gas sensor has the ability to detect gas. It is created from tin dioxide (SnO 2)
semiconductor. This compound does not react much when in contact with
fresh air. However, when concentration of gas is present, its conductivity
increases accordingly. With an electronic circuit, the change in conductivity
can be converted to output signal of gas concentration. For example, MQ135
is a gas sensor, and it is sensitive to impure gases such as NH3, Benzene,
CO2, … Gas sensors are usually scattered around a building to ensure
maximum protection. (ThomasNet, n.d.)

As fire incidents occur at an increasing rate and burglars start to use extreme
methods like gas poisoning, the gas sensor’s presence is in demand more than
ever. Figure 7 is of the MQ135 mentioned above.
12

Figure 7. MQ135 gas sensor (IndiaMART, n.d).

3.4 Surveillance camera

Sometimes, sensors just do not work as intended, or some smart burglars


somehow manage to bypass the detection and successfully raid a house with a
security system installed. In such cases, a surveillance camera proves its
worth. The camera’s job is to record everything in its field of view. This
increases the chance of catching intruders in the event of them getting away.
Having surveillance cameras is one of the most effective way to protect one’s
property. A typical surveillance camera is shown in Figure 7.

There are many brands of surveillance cameras, each comes with its own
uniqueness. However, an effective camera will usually have following
features:
 Motion detection: The camera sends a notification to the house owner
when it detects motion within its range.
 Flexible movement: Being able to move around increases the field it
can cover and, as a result, reduces the number of cameras needed.
 Wi-fi connection: House owners can communicate with the camera
and vice versa wirelessly. This proves to be very handy for setting up
the security system.
 Night vision: Many criminal activities happen at night so this feature
is also necessary for a good surveillance camera.
 Environmental resistance: This is an important requirement for
outdoor cameras, especially in places with extreme weather
conditions.
13

Figure 8. Kerui Home Security IP Camera (AliExpress, n.d).

3.5 High decibel siren

In case of intrusion detected, there is no better way to warn house owners and
scare away burglars than a sudden loud noise. A high decibel siren does its
job nicely. The siren proves its effectiveness in fending off intruders by
making a loud, noisy sound that can be heard two blocks away. Its operating
principle is also fairly simple: If a security system is tripped, the siren will go
off. Figure 8 is a picture of a common siren.

Figure 9. A siren (Ebay, n.d).

3.6 Security company signs and stickers

Normally, a security system is controlled and observed by its security


company. In addition to all high-tech accessories, signs and stickers that can
glow at night of said security company are also provided to customers. This
may look like just a marketing strategy from the outside. However, it holds its
own ground in protecting property. These signs and stickers show that a
house having them on its yards or windows is protected by a security
14

company. This method helps decrease the chance of being targeted. Figure 9
is a yard sign on which words glow at night.

Figure 10. Frontpoint Security’s Yard Sign


(Frontpoint Security, n.d).

4 LOW-COST SECURITY SYSTEM COMPONENT DETAILS

4.1 Overview

As its name suggests, the project’s aim is to create a proper residential


security system with low cost items and easy-to-install nature. The system
covers most of the necessary features and uses components as follows:
 Main controller: Arduino Uno.
 Control panel: Combination of a 3x4 keypad and a 16x2 I2C Liquid
Crystal Display (LCD).
 Motion sensor: PID sensor.
 Door/window sensor: Reed switches.
 Alarm: Buzzer.
 Security camera: any security camera with SD memory slot.
 Wireless control method: SIM900.
 High voltage appliances control: Relay module Keyeys KY-019.

4.2 Controller – Arduino Uno

4.2.1 Introduction of Arduino

Arduino, in general, is an open-source electronics platform. It is a


microcontroller board whose purpose is to program interactions with
hardware devices such as motors, lights, sensors, and many others. Arduino is
suited for this project thanks to its versatility and ability to communicate with
various components that were used in the system.
15

Arduino first appeared in 2003 as a project of a student at Interaction Design


Institute Ivrea in Ivrea, Italy. At that time, a microcontroller called BASIC
stamp was used for students’ projects, which cost a considerable amount of
100USD. Hernando Barragán, the one who started Arduino project, created
“Wiring”, a development platform, for his Master’s thesis project, under the
supervision of Casey Reas and Massimo Banzi. The goal was to make a tool
that was more accessible and lower cost for creating digital projects. Later,
this project was split and named Arduino. Massimo Banzi, along with David
Cuartielles, Tom Igoe, Gianluca Martino, and David Mellis formed the initial
Arduino core team. Arduino was named after a bar where the team met each
other in Ivrea, Italy, which was named after King Arduin of Italy in the tenth
century. Although almost nothing was marketed, news of Arduino was
spreading rapidly thanks to good word of mouth from first users. It then
became so popular that many people decided to visit Ivrea just to visit the
place Arduino was born. (Circuitstoday.com, 2014.)

Figure 11. Arduino Mega 2560 Rev3 (Arduino, n.d).

Arduino has so many advantages over other platforms, which explains for its
excellent reputation. As pointed out by Romano (2014), the most notable
advantages of Arduino are described as follows:
 Easy to get used to: Arduino is an extremely easy-to-use application
development environment with its easy-to-understand programming
language that can be learned quickly even for people who are not so
familiar with electronics and programming.
 Open-source nature: Having open-source hardware and open-source
software, Arduino allows users to freely modify, improve it, which
help increase Arduino’s flexibility and accessibility.
 A huge amount of expansion boards: Same as PLC’s racks, to support
increasing demands in functions, a lot of Arduino expansion boards,
called “shields”, have been created. They can be stacked up on an
Arduino to activate their support functions. For instance, in order to
establish an internet connection for an Arduino, there is Ethernet
Shield, or to make phone calls, receive messages with Arduino, GSM
Shield is the one to choose.
 Great community: Anything can be asked and answered in a matter of
minutes. Arduino’s community is very supportive and full of
professionals.
16

Even though Arduino is a popular choice, it has some notable flaws:


 No internal debuggers: there is only one way to debug, and that is
uploading the code to Arduino board and then running it.
 Fairly over-priced: the price for an Arduino board, for example,
Arduino Uno, is around 20USD, which is not much. However, one
can get a Raspberry Pi Zero with around 10USD, which runs on
Linux operating system, possesses much more memory, can be
connected with a display and ethernet like a mini computer, while
being smaller than Arduino Uno.

All in all, Arduino is a suitable platform for making small range projects, of
which the Low-cost Security System is.

4.2.2 Characteristics of Arduino Uno

There are a lot of types of Arduinos with different specifications on the


market. For this project, Arduino Uno was chosen. Its specifications are as
follows:
 Microcontroller: ATmega328.
 Operating Voltage: 5V Input Voltage (recommended).
7-12V Input Voltage (limits) 6-20V.
 Digital I/O Pins: 14 (of which 6 provide PWM output).
 Analog Input Pins: 6.
 DC Current per I/O Pin: 40 mA.
 DC Current for 3.3V Pin: 50 mA.
 Flash Memory: 32 KB (ATmega328) of which 0.5 KB used by
bootloader.
 SRAM: 2 KB (ATmega328).
 EEPROM 1 KB (ATmega328).
 Clock Speed 16 MHz.
(Farnell, n.d, p.1-2)

For specific details of Arduino Uno’s hardware parameters, information is


given below:

 Power jack: power can be supplied to Arduino Uno through this port.
 USB connection: The USB port is a standard type B which is used for
both power and data transmission. In order to connect Arduino to a
computer, a standard A-B cable is required.
 ATmega 16U2: This microcontroller is in charge of USB/Serial signal
conversion by having a USB serial firmware uploaded on itself.
ATmega 16U2 supplies the main processor with serial data. It enables
communication between said processor and a host computer through a
USB port.
 ATmega 328P: This is Arduino’s main component. It is an 8-bit
microcontroller that executes instructions in a program. ATmega
328P intercepts and stores data from the 16U2 by having a firmware
uploaded on itself. It has three types of memory: 32KB of flash
memory which is used for storing application; 2KB of SRAM used
for storing variables that are used by the application; 1KB of
17

EEPROM memory used for storing data that are meant to be kept
even when Arduino board is turned off.
 In-circuit-serial-programming headers (ICSP): There are two of these
header pins on an Arduino Uno. Each microcontroller is supported by
one of this pin. Through these pins, programs can be uploaded
directly to the ATmega 328P to change or update existence firmware
in order to extend Arduino hardware’s functionality.
 16 MHz crystal oscillator: It is connected to ATmega 16U2, which is
crucial for synchronized serial communication.
 Pins: Arduino Uno has 28 pins, including power and I/O pins.
- Power pins: There are 4 power pins:
o VIN: Arduino Uno can receive input voltage from an
external power source through this pin. If the voltage is
supplied through power jack, said voltage can be accessed
through VIN pin.
o 5V: 5V supply for the microcontroller and every other
component.
o 3.3V: 3.3V supply, maximum current drawn is 50 mA.
o GND: Ground pin.
- Digital I/O: There are three ports: PORTB, PORTC, and PORTD.
Every pin in these ports can be used normally as a functional
digital I/O. Their operating voltage is 5V. Some of the pins have
alternate functions indicated by notations beside pin numbers. To
be more specific:
o Serial - pin 0 (RX) and pin 1 (TX): connected to the
ATmega 16U2’s corresponding pins, these 2 pins are used
to receive and transmit TTL serial data respectively.
o External interrupts – pin 2 and pin 3: They can be
constructed to trigger an interrupt on events
depending on the programming.
o PWM – pin 3, pin 5, pin 6, pin 9, pin 10 and pin 11: They
provide 8-bit PWM output.
o Serial Peripheral Interface (SPI) – pin 10 (SS), pin 11
(MOSI), pin 12 (MISO), pin 13 (SCK): They are used for
supporting SPI communication.
o LED – pin 13: This pin is connected to a built-in LED on
an Arduino Uno board. That LED can be turned on and
off depending on the state of the pin 13.
- Analog I/O: An Arduino Uno consists of 6 analog pins, which are
marked A0 through A5 on the board. These pins support 10 bits
of resolution. Like digital I/O pins, some of the analog pins have
alternative functionality:
o TWI - pin A4 (SDA) and pin A5 (SCL): These pins
support TWI (or I2C) communication.
- AREF pin: It supplies reference voltage for analog inputs.
- Reset pin: In order to reset the microcontroller, pull this pin to
LOW to reset Arduino.
(Technobyte, 2017.)
18

Figure 12. Detail of Arduino Uno (EEE Project, 2017).

4.2.3 Arduino software (IDE)

In order to program and upload codes to an Arduino Uno board, Arduino


Integrated Development Environment (Arduino IDE) is used. A program
created using the IDE is called sketch. The software’s programming language
is basically a C-based one with easy-to-understand commands. And just like
C programming software, the IDE comes with many libraries, many of those
are made by Arduino community, which help reduce the complexity of codes
and amount of work.

The IDE’s interface is designed nicely and easily for users to understand and
it contains all needed functions and information of Arduino board in use.
When IDE starts up, a window will appear which looks like the window
shown in Figure 12. The figure is full of marks on every information visible
on the interface of the IDE for better understandings. Explanations for the
marks are as detailed below:
19

Figure 13. Arduino IDE interface (Sparkfun Electronics – Arduino Guide)

1- Verify: Compiles code written in the area (8) and catches errors in syntax,
for example missing semicolons or parentheses.
2- Upload: Compiles code and then uploads it to the board.
3- New: Creates a new code window tab with the basic structure of a sketch.
4- Open: Opens a menu containing all existing sketches in a directory. These
sketches can then be loaded.
5- Save: Saves the current sketch.
6- Serial monitor: Opens a window displaying serial information transmitted
from Arduino board, which is very useful for debugging.
7- Sketch name: Shows name of the currently active sketch.
8- Code area: An area used for code writing.
9- Message area: An area used by the IDE to show what the board is doing
and show errors if any.
10- Text console: Shows full details of errors, which proves to be very useful
for debugging.
11- Board and Serial port: Shows the name of the board and serial port in
used. In this example, board Arduino Uno and port 23 were used.
(Sparkfun, n.d.)

Additionally, there are 5 menus which are: File, Edit, Sketch, Tools and Help.
These menus contain extra commands and tools that enhance users’
experiences with Arduino. Besides some common ones that exist in every
word processing application (Save, Open, New, etc…), many of the
20

commands are useful for customizing Arduino to suit one’s needs, for
example, updating the bootloader of Arduino board. Some worth noting
commands and tools which are commonly used are listed below:
 File
- Examples: Shows examples provided by the IDE or library. These
examples are organized by topics for easy access.
- Preferences: Opens the Preference window where IDE’s settings
can be changed, for instance, the language of the software.
 Edit
- Copy for Forum: Copies the code to the clipboard in a form,
complete with syntax highlighting, that is suitable for posting to
forums.
- Copy as HTML: Copies the code to the clipboard as HTML,
which is suitable for inserting in web pages.
- Comment/Uncomment: Places or removes comment marker (//) at
the beginning of each selected lines.
- Increase/Decrease Indent: Moves the text one space to the right or
remove one space at the beginning of the selected line.
 Sketch
- Upload Using Programmer: Uploads code using an external
programmer, which overwrites the bootloader.
- Export compiled Binary: Saves a file with .hex extension.
 Tools
- Auto Format: Organizes code nicely, for example indenting the
code so that opening and closing braces form a straight line.
- Archive Sketch: Stores a copy of the current sketch under .zip
format.
- Fix Encoding & Reload: Correct possible conflicts between the
editor char map encoding and other operating system char maps.
- Serial Plotter: Creates a real-time graph based on serial data
received from Arduino to the computer.
- Board: Allows users to choose the board currently in used.
- Port: Allow users to choose a serial port for connecting Arduino.
 Help: All commands in Help guide users to documents which contain
details about Arduino, information needed for getting used to Arduino
or troubleshooting problems.
(Arduino, 2015)

4.3 Control panel – Keypad and Liquid Crystal Display (LCD)

For this project, the combination of a 3x4 matrix keypad and a 16x2 LCD
serves as a way for users to communicate with the security system. They were
organized and programmed in a way that allows users to easily control the
system with some simple predetermined rules, which were discussed in
section 5.3.

4.3.1 3x4 matrix keypad

The keypad is a numeric matrix keypad with 12 buttons, arranged in a 3x4


grid (like a telephone). It is called matrix keypad because of its interface
technique. By applying such technique, matrix keypad requires fewer wires
than non-matrix one does.
21

I/O pins of the keypad are divided into two parts: rows and columns. When a
key is pressed, it creates a closed circuit between two specific pins based on
that key. The following example will be based on Figure 14.

Figure 14. 3x4 matrix keypad (GRobotronics Learning, n.d).

The example is given out as follows: This 3x4 keypad is connected to 7 pins
on the microcontroller. Three COL pins are set as OUTPUT while the four
ROW pins are set as INPUT, state LOW. Power runs through COL pins one
by one, separately, at very high speed from COL0 to COL2. If a key is
pressed, for instance, number 1, which is formed by pin 1 (COL 0) and pin 7
(ROW 0), the connection between pin 1 and pin 7 is formed. Therefore, the
microcontroller detects that output pin 1 (COL 0) is HIGH, and input pin 7
(ROW 0) receives HIGH signal from the pin 1, simultaneously. That’s how
the microcontroller detects which key is pressed.

The keypad is a simple yet effective device when it comes to communicating


with the Arduno. It can be easily programmed using the library “Keypad.h”
of the IDE.

4.3.2 16x2 LCD

The LCD (Liquid Crystal Display) is a widely common display module.


Often preferred over other display devices like seven segment and multi-
segment LEDs, the LCD has several features that interest users, such as low
cost, easy to be programmed, the ability to display special and custom
characters (like heart shape one), and so on.

16x2 means that the LCD can display two lines with a maximum of sixteen
characters each line. There are two registers inside the 16x2 LCD named Data
and Command. The data register stores data that is going to be displayed on
the LCD. The command one keeps the instructions that are designated to the
LCD, for example, initializing the LCD, setting cursor position, clearing
current display on the screen and some other features. Figure 16 is an
example of a 16x2 LCD.
22

There are in total 16 pins on a 16x2 LCD:


 GND: ground pin.
 Vcc: supply voltage (5V).
 Vee: contrast adjustment with a variable resistor.
 RS: choose between data and command register.
 R/W: choose whether to read or write to the register.
 EN: enable data transmission to data pins.
 DB0 – DB7: 8-bit data pins.
 Led+/Led-: backlight Vcc and backlight GND.
(LCD 1602 datasheet)

Figure 15. LCD 1602 (AliExpress).

Normally, an LCD requires at least eight pins in total to be controlled, which


takes away a lot of pins for an Arduino Uno. This problem can be overcome
by using an I2C module.

4.3.3 Inter-Integrated Circuit (I2C):

I2C, or Inter-Integrated Circuit, communication protocol is a serial protocol


used for communication between multiple slave digital integrated circuits and
one or more master circuits.

According to Dejan from HowToMechatronics (n.d), I2C requires only two


bidirectional buses, one for the clock signal (SCK or SCL) and one for the
data signal (SDA). The SCL line is for the clock signal, which is generated by
a master device, and it is the requirement for data transfer synchronization
between devices that are on the I2C bus. The SDA line carries data between
devices. Both of these lines are open-drain, which means that I2C master and
slave devices can only pull these signal lines low but cannot drive them high.
Therefore, bus contention where two devices try to drive the line differently
from each other is averted, which prevents potential damage. There is a pull-
up resistor on each communication line for restoring the signal back to high
when it is not driven low.
23

Figure 16. I2C data transmission (HowToMechatronics, n.d).

The data signal is a sequence of 8 bits. Data transmission of I2C works like
this: When a start signal is sent, which indicates by the SDA line being pulled
LOW while the SCL line is HIGH, then comes three 8-bit sequences. Each
sequence is followed by a bit called Acknowledge(ACK)/Not
Acknowledge(NACK). The first 7-bit sequence is of the slave’s address that
receives data with the last bit being R/W bit which determines the mode
being Read or Write. After the sequence is the ACK/NACK bit, which is used
by the slave to indicate if it receives the sequence successfully or not. At this
point, the master passes the control to the slave device. If the slave device
receives the sequence without a fault, it will pull the SDA line down. This
condition is Acknowledge. If it fails to do so, the condition is Not
Acknowledge. This scenario happens when the slave is, for example, busy, or
it cannot understand the data. The master device will decide what to do in
such a case.

The next sequence is the internal register’s address. The internal register is
the location in the memory of the slave device. It contains information and
data. The last sequence is the data sequence which starts either from the
master or the slave, depending on the R/W bit. After the last sequence is sent,
the transfer ends with a stop signal generated by the master device. The stop
signal is when there is a transition from LOW to HIGH (0 -> 1) on SCL,
followed by a transition from LOW to HIGH (0 -> 1) on SDA, while the SCL
stays HIGH.

I2C is best suited when the speed of the data transmission is not considered as
important as manufacturing cost and simplicity. There is also a dedicated
library called “Liquidcrystal_i2c.h” used for controlling the I2C LCD. All of
these great features make the I2C LCD the best choice for this project in term
of displaying information.

Figure 17. I2C module (AliExpress).


24

4.4 Motion sensor and Door/window sensor

The sensors are what make security system a good protection for one’s
properties. Although the cost is low, the components offer the must-have
function of every security system, which is detecting intrusion. Details of
these components were given in section 3.3 and 3.4.

For this project, PIR motion sensor is a HC-SR501 module and the
door/window sensor is a normal reed switch with a piece of magnet.

Figure 18. PIR sensor HC-SR501 and reed switches (AliExpress)

4.5 Alarm

Any kind of alarm buzzers would work. For the sake of easier demonstration,
a 5V electromagnetic buzzer was used for this project. If any high voltage
buzzer is used instead for real-life applications, it must be paired with a
separate power source and a relay before it can be controlled by Arduino.

Figure 19. 5V electromagnetic active buzzer (AliExpress).


25

4.6 Security camera

Basically, in order to capture an event that happens while the system is


triggered, any wall-mounted security camera with an SD memory card slot
will work. In this example of the project, D link IP camera is chosen.
However, most of the cameras require at least 12V of supply in order to work,
and Arduino can only deliver 5V at best. Therefore, to control the camera
using Arduino Uno, a relay module is usually used to safely provide needed
power supply for the camera while still letting Arduino in control.

Figure 20. DCS-932L Wireless Home Network Camera (Ebay).

Pairing the camera with sensors can help save energy and pinpoint the exact
time when an intrusion happens by activating the camera only when the
motion sensor or door/window sensor is triggered.

4.7 Relay module

A relay is an electromagnetic switch that can be operated by a small electric


current. The core of a relay is the electromagnet, which is essentially a coil of
wire that turns into a temporary magnet when there is electricity flow through
it. Having such a feature makes the relay a great tool for controlling high-
power electric devices or circuits with low-power signals, such as the
Arduino’s 5V output.
Figure 21 is an example illustration of a relay in a circuit. When there is
power flowing through the circuit (1), the electromagnet (the brown coil) is
activated, which generates a magnetic field that attracts the red contact which,
in turn, closes the circuit (2) and so creates a complete circuit. When the
power flowing through the circuit (1) is cut off, a spring connected to the
contact pulls it back to its original position, therefore switching the circuit (2)
off again. This example is of a NO, or Normally Open, relay, whose contact
is in the open position by default, and it needs to be closed by a flow of
current through the circuit (1). The other kind of relays is the NC, or
Normally Closed, relay which behaves the same, but in reverse. The NC relay
26

is in the closed position by default and will become open if there is current
flowing through the electromagnet.

Figure 21. NO Relay (explainthatstuff.com)

Figure 22 is the relay module Keyeys KY-019. This can be used to control a
security camera, which normally requires more than 5V output from Arduino.
The module contains useful components to create galvanic isolation between
Arduino, the relay and the camera, which ensures a safer environment for
Arduino in case the relay or the camera is damaged. It also provides both NO
and NC option for using the relay.

Figure 22. Keyeys KY-019 relay module (Ebay, n.d).


27

4.8 Wireless control - SIM900 module

4.8.1 SIM900 module introduction

Nowadays, when nearly everything is controlled wirelessly, a good security


system should also give users such ability. Being low cost does not mean that
such feature is left out. In this project, wireless communication between users
and the security system is carried out through a module called SIM900.

SIM900 is a complete Quad-band GSM/GPRS solution in a Surface-mount


technology (SMT) module that works with 5V DC power supply, which is
suitable for an Arduino’s power output. Having an interface with the
industrial standard, the SIM900 offers GSM/GPRS system with frequencies
of 800/900/1800/1900 MHz including SMS and making phone calls
functions. It also has an antenna to boost signal strength. Additionally, the
SIM900 has small dimensions along with low power consumption and
worthwhile solutions, which make it a fitting component for wireless options.
The communication protocol of the SIM900 module is UART, which is a
serial communication protocol wildly used and effective. (Epalsite
Electronics, 2016.) Arduino can be programmed to control the SIM900
effectively using the library “GSM.h”.

Figure 23 is a SIM900 GPRS Shield, which is compatible with Arduino Uno.

Figure 23. SIM900 GPRS shield (Ebay).

4.8.2 UART communication protocol

In order to exchange information between the SIM900 module and Arduino


Uno, both of these must share the same communication protocol. In this case,
a serial communication protocol is used which is called UART protocol.

According to Sparkfun (n.d), UART, which stands for Universal


Asynchronous Receiver/Transmitter, communication interface has been
around for some decades, yet it still proves to be extremely effective in a
world where new technology becomes outdated quickly. UART is a serial
communication interface. Therefore, instead of sending every single bits of
information at the same time, which is similar to parallel communication, bits
28

are sent one by one in serial communication. This helps decrease the number
of wires needed for data transfer between two devices greatly. Although the
serial communication suffers from lower speed and accuracy than the parallel
one, it is still very viable for its lower cost and easier to implement.

However, since the interface is asynchronous, there is no signal sent to the


receiver to ensure that data is received correctly (or synchronization of data
transmission). As a result, both devices: the transmitter and receiver must
agree with each other on the number of bits transferred per second, which is
called baud rate. If the nominal baud rates do not match, the data received
will surely be a mess.

Arduino Uno itself has pins for UART communication, which are pin 0 and
pin 1, and there is also a library called “SoftwareSerial.h” of the IDE that
allows UART communication without using those specific pins. Therefore,
Arduino Uno has no problem connecting to the SIM900 module.

Arduino controls the SIM900 by using AT commands. These commands are


used for controlling dial-up modems. They are also supported by GSM/GPRS
modems and mobile phones alike. Using these, Arduino can make/receive
phone calls, send/receive messages, and so on.

For this project, a GPRS Shield SIM900-based was used that can be stacked
upon Arduino Uno.

5 LOW-COST SECURITY SYSTEM IN OPERATION

5.1 System setting up

Figure 24 is an example of how the system can be set.


29

Figure 24. Example of system setup.

 1 and 2 - Combination of a reed switch and a magnet (door sensor):


The magnet is placed on the door (1) and the reed switch is right next
to it (2). This is the most common setup for this combination.
 3 - A motion sensor: The motion sensor is usually placed high on the
ceiling for its wide range of detection. The range can be tuned to suit
a house’s design.
 4 - 3x4 keypad + 16x2 I2C LCD: These are put away from the motion
sensor’s field of view.
 5 - A light source: This is usually placed on the ceiling near the
motion sensor.
 6 - The Camera: This should stay in the corner where it can record the
whole place where intrusions might happen.
 7 - Arduino Uno: It should be kept in a small junction box and close
to other components for easier connection.
 8 - The combination of the 3x4 matrix keypad and LCD I2C 1602
should be placed far from detection range of the motion sensor to
avoid accidental detections.

For safety reasons and easier demonstration, an LED was used instead of a
high voltage lightbulb with a relay. The combination of a camera and a relay
module was also not included into this project, but the relay’s ability was
detailed in section 4.7.

5.2 System communication

 When the system is idle:


If the system starts up for the first time, it will ask users to create a
new code, which consists of 6 characters between 0–9. After this,
users can access the system’s options.
30

The LCD screen stays off until someone presses any button on the
keypad. If triggered, it shows “Enter code (op x)” with “x” being the
option of security that is currently active. Then users must enter the
predetermined password. If the password is wrong, the LCD will
clear the old input and users must enter the password again. If it is
confirmed that the password is entered correctly, users can now
control the system with some options. The LCD will then show
numbers and abbreviations of corresponding options. After that, users
can input keys corresponding to the functions as follows:
- Key 1: mode OFF (details in section 5.3).
- Key 2: mode HOME (details in section 5.3).
- Key 3: mode AWAY (details in section 5.3).
- Key 4: mode MAX (details in section 5.3).
- Key 5: change password - when the key is pressed, users are
asked to input a new password and that password will overwrite
the current one.
- Key 6: change phone numbers- when the key is pressed, users can
choose any from 4 phone number slots to overwrite it with their
phone numbers. These numbers are used to give commands to
Arduino. Numbers that are not in any number slots cannot control
Arduino.
- Key #: return to sleep state.
- Key *: clear password input (or delete input).
 If the user is changing the phone numbers for
controlling the system, press “*” to save the phone
numbers he/she entered. The function to clear inputs
will be disabled then.

After some seconds without interactions with the control system, the
LCD will automatically be put back to idle state (turn off screen).

 When the system is triggered:


- Use either authorized numbers to call the system or the keypad to
input the code, which will reset the system.

 Wireless option:
- Key 1: mode OFF (details in section 5.3). While the system is
idle: Only SMS function is active. Users can use phones that
have authorized numbers to control the system with following
commands using text messages:
 Text “1” will disable the security (mode OFF).
 Text “2” will activate mode HOME.
 Text “3” will activate mode AWAY.
 Text “5” to reset the password to “000000”.
- While the system is triggered: Only calling function is active.

5.3 Security measures

There are in total four security modes to use with different setups. However,
every mode uses the following rules: When the system is triggered, the LED
blinks for 7 seconds, and the buzzer is turned on. Within this 7 seconds,
Arduino calls the first number in the saved slots, and the keypad is disabled to
avoid a conflict that may lead to the system freezing. After the duration, the
31

LED stays on along with the buzzer. Then after another 13 seconds, the LED
blinks again and Arduino calls the next slot (slot 2). Then this cycle continues
until the reset mechanic is activated. If the slot reaches the 4th slot, it goes
back to the 1st slot after that. There are two ways to reset the system:
 Using a keypad: Entering the code while the system is triggered will
reset the system. This will automatically set the mode to option 1,
which is mode OFF (more details below).
 Using a phone: Calling Arduino using authorized numbers within 13
seconds as mentioned above for the first time will prevent Arduino
from calling but the system stays triggered. Calling once more will
reset the system.

In Figure 25, there is a flowchart that shows how the system works with these
modes.

 Mode: OFF and MAX

- Mode OFF:
This mode is for turning off the system. It will deactivate every
component. This is also the mode that the system will start with
when it is turned on.

- Mode MAX (flowchart):


This mode is for users who wants maximum protection.

First, the system will wait for any of the sensors to be triggered.
If there is a signal from one of the sensors, every security
measure will be activated instantly, which includes turning on
LED, buzzer and calling house owners. The system can only be
reset back to its idle state if the house owners reset the system,
either using the keypad or their phones.

This is best used for apartments or households that do not have


pets who can create false detection and owners who prefer
maximum protection.

Figure 25. Operation mode MAX


32

 Mode: AWAY and HOME

- Mode AWAY in the flowchart in Figure 26:


This mode is for a situation when nobody is at
home but there are pets inside.

First, the system is in the idle state, waiting for the


sensors to be triggered. If either sensor is
triggered, the system will first wait for three
seconds before setting off the alarm. In the three-
second period, the LED will be activated, as
animals are startled if there is sudden light, so this
method can lure pets or animals away. If the
sensors are not triggered anymore after three
seconds, the system will go back to its idle state
with the LED turned off. If the opposite scenario
happens, then all the security measures will be
turned on, including buzzer sounding and calling
the house owners.

- Mode HOME in the flowchart in Figure 26:


This mode is nearly the same as the AWAY mode.
The difference is that when in the HOME mode,
the PIR motion sensor is bypassed, which means
detections from the motion sensor will not trigger
the security. The rest stays the same, including
door sensors.

Every time the system is triggered, it will keep on


calling the users with phone numbers registered to
Arduino and repeat, until it is turned off. This is to
help reduce the chance of users not seeing their
phones.

Figure 26. Operation mode AWAY


33

6 ANAYLYSIS OF A LOW-COST SECURITY SYSTEM

In order to effectively point out the advantages and disadvantages of the low-
cost security system, the following comparison in Table 1 was made with
detailed information and differences between the low-cost security system
created here and a common security system in the market. The details about
the common security system are based on information from Isaac Brown
(2018) of Alarm New England, a company specialised in security system.

Table 1. Comparison between Common Security System and Low-cost Security System

Points of comparison Common system Low-cost system


- Installation cost is approximately - Equipment cost falls around USD100 to
Cost of installation and USD100. USD200 at best.
devices - Equipment cost is around USD600
to USD1200.
- Monthly fee for monitoring is in - None.
Monthly fee between USD15 and USD100.
- Average is around USD30.
- Constant monitoring 24/7 from the - Cost less than a common security system.
security company in charge. - Has basic security measures.
- High quality components and - Easy to install, replace, maintain or
professional guards. upgrade the system.
- Many control options, including - Wireless option is GSM/GPRS based so it
Advantages wireless ones. can be used without an internet connection.
- Many great extra features such as - May have an online stream camera using
temperature measurement, voice D link IP camera.
recognition, camera streaming online.
- Recorded videos are stored in cloud.

- Equipment cost along with the - No constant monitoring.


monthly fees is enormous for - There is no security company in charge so
medium/low income families, if in case of intrusion, house owners must
especially in developing countries. deal with it themselves.
- Some security companies may - Limited control options.
require some years of commitment in - Shorter lifespan.
order to buy the services. - Arduino pins use female headers, so
- Compensation costs for false alarms. connection wires may be loosened
Disadvantages - Cost for cloud storage. regularly.
- The camera is not really a part of the
system. Therefore, Arduino cannot interact
with videos recorded at all.
- Sim900 GPRS Shield is equipped with an
antenna, which may cause misreading of the
PIR sensor when it receives or makes a
phone call or SMS.

- People with enough income for the - People with medium/low income,
Target customers security system and medium/large especially those in developing countries,
fortune that needs protection. small apartments, laboratories.
34

The most notable first problem of the low-cost system is that because of the
system being self-implemented, there cannot be constant monitoring or
professional guards when an intrusion happens. To counter this problem,
users can always ask for help from acquaintances nearby, such as neighbours,
or hire someone, to check the situation in case the system is triggered when
no one is at home.

In comparison with other security systems, the low-cost system’s control


options are quite limited comparing to a common security system. For
example, many of today’s security systems have their own mobile
applications for controlling the systems wirelessly or with remote controls,
instead of making phone calls and sending SMS.

Moreover, cameras used in the system are not exactly controlled by Arduino.
The ability to livestream videos or save the videos recorded to SD card is
entirely depending on which cameras are used for the system, as Arduino
only controls a relay that is connected to the camera’s power supply cable.
Therefore, what Arduino Uno can do with videos and images recorded by the
camera is non-existent. The reason for using such a method instead of using a
camera module for direct control is that Arduino Uno is incapable of
livestreaming videos online, and the resolution of the images and videos
taken is low, about 640x480 resolution. Because of these reasons, using a
camera module is not effective for the purpose of the system.

A PIR sensor misreading caused by the antenna of the GPRS module can be
prevented by leaving the sensor away from Arduino.

There are also several problematic issues with Arduino. For Arduino’s pins
header, it is best to replace female headers with male ones. The next issue is
its short lifespan. These are flaws that any Arduino-based systems face.
However, it is easy to buy and replace a new Arduino while keeping the old
setup. Implementation of the code for the new one is also easy. Therefore,
these problems can be dealt with.
35

7 CONCLUSION

The project was built with an Arduino Uno as the main controller, along with
many other components, including: a motion sensor, some window and door
sensors, a super bright LED, a loud buzzer, a wall-mounted camera with an
SD slot, a relay module, a 3x4 matrix keypad, an LCD 1602 with an I2C
interface and a SIM900 GPRS shield. The sensors acted as accurate
observers, while the buzzer and the LED provided a great warning measure,
along with the relay-controlled camera’s video recording ability. The system
was controlled directly through inputs from the keypad and the LCD, or
wirelessly through the SIM900 GPRS shield, using phone calls and text
messages. With a good setup and combination, the low-cost system provides
good protection against intruders. The system has some clear advantages and
disadvantages.

Some notable advantages of the low-cost system are its inexpensive cost,
relevancy and easy-to-customize nature. The system can also be easily
reprogrammed to have extra functions or running modes without too much
work. The SIM900 shield used in the system is quad-band which means it is
suitable to be used anywhere in the world.

On the other hand, there are disadvantages that lower the system’s quality.
The most notable disadvantages are: its inability to directly control videos
recorded by surveillance cameras and other extra wireless control methods. In
case of cameras get damaged, videos and images recorded may as well be
destroyed. That is why it is always necessary to have the ability to store
videos somewhere else automatically, something which Arduino Uno cannot
do. Other wireless control methods are useful when users want an easier way
to control the system without having to use their phones and go through some
extra steps.

Lastly, there are some suggestions that the author believes could help
improve the system’s features and reliability:
 Create an application for mobile phones that acts as a second wireless
control method for the system. This will help control the system in
general easier.
 Arduino Uno cannot record good quality videos. In order to improve
the system in this matter, it is best to switch the system from Arduino-
based to some other controllers that can support live-streaming with
good quality videos and send them to the users through email. This
feature along with connecting the controller to the internet will help
constantly update status of the system online so that users can manage
the system from afar.
 Most of the time, intruders can get access into a house thanks to the
front door lock’s ability to be opened from the outside. Therefore,
creating a mechanism for locking doors from the inside may further
enhance the system’s protection.
36

REFERENCES

Aliexpress. (n.d). 5V electromagnetic active buzzer. Retrieved 30th October


2018 from
https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20181031
090421&SearchText=buzzer

Aliexpress. (n.d). I2C module. Retrieved 30th October 2018 from


https://www.aliexpress.com/popular/i2c-lcd-module.html

Aliexpress. (n.d). Kerui Home Security IP Camera. Retrieved 30th October


2018 from
https://www.aliexpress.com/item/IP-camera-WIFI-Megapixel-720p-HD-
Outdoor-Wireless-Digital-Security-CCTV-IP-Cam-IR-Infrared-
SD/32549161202.html

Aliexpress. (n.d). LCD 1602. Retrieved 30th October 2018 from


https://www.aliexpress.com/w/wholesale-lcd-1602.html

Aliexpress. (n.d). PIR sensor HC-SR501 and reed switches. Retrieved 30th
October 2018 from
https://www.aliexpress.com/w/wholesale-pir-sensor-module.html
https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20181031
090344&SearchText=reed+switch

Arduino. (2012). Arduino Software (IDE). Retrieved 30th October 2018 from
https://www.arduino.cc/en/Guide/Environment

Arduino. (n.d). Arduino Mega 2560 Rev3. Retrieved 30th October 2018 from
https://store.arduino.cc/arduino-mega-2560-rev3

Brown, I. (2018). Home Security Cost Breakdown (2018). Retrieved 30th


October 2018 from
https://www.alarmnewengland.com/blog/how-much-do-home-security-
systems-cost

Business Security Alarm. (2014). Door sensor. Retrieved 30th October 2018
from
http://business-security-alarm.blogspot.com/2014/11/how-to-magnetic-door-
sensor-works.html

Circuitstoday.com. (2014). Story and History of Development of Arduino.


Retrieved 30th October 2018 from
http://www.circuitstoday.com/story-and-history-of-development-of-arduino

Dejan. (n.d). How I2C Communication Works and How To Use It with
Arduino. Retrieved 30th October 2018 from
https://howtomechatronics.com/tutorials/arduino/how-i2c-communication-
works-and-how-to-use-it-with-arduino/

Dejan. (n.d). I2C data transmission. Retrieved 30th October 2018 from
https://howtomechatronics.com/tutorials/arduino/how-i2c-communication-
works-and-how-to-use-it-with-arduino/
37

Ebay. (n.d). DCS-932L Wireless Home Network Camera. Retrieved 30th


October 2018 from
https://www.ebay.com/p/D-Link-DCS-932L-Web-Cam/112159544

Ebay. (n.d). Keyeys KY-019 relay module. Retrieved 30th October 2018
from
https://www.ebay.com/p/Hot-Keyes-Ky019-5v-Relay-Module-for-The-
Arduino-AVR-Pic-Better-Us53/1371316093

Ebay. (n.d). SIM900 GPRS shield. Retrieved 30th October 2018 from
https://www.ebay.com/itm/GSM-GPRS-Shield-For-Arduino-/231007843904

Ebay. (n.d). Siren. Retrieved 30th October 2018 from


https://www.ebay.com/p/6-Tone-12v-Loud-Car-Van-Truck-Security-Alarm-
Siren/1831935785

EEE Projects. (2017). Detail of Arduino Uno. Retrieved 30th October 2018
from
https://eeeproject.com/arduino-uno-board/

Epalsite Electronics. (2016). SIM900 Quad-Band GPRS shield. Retrieved


30th October 2018 from
http://wiki.epalsite.com/index.php?title=SIM900_Quad-Band_GPRS_shield

ExplainThatStuff. (2018). NO Relay. Retrieved 30th October 2018 from


https://www.explainthatstuff.com/howrelayswork.html

Farnell. (n.d). Arduino Uno Datasheet. Retrieved 30th October 2018 from
https://www.farnell.com/datasheets/1682209.pdf

First4magnets.com. (2014). What is a reed switch, and which magnets


operate them? 1st August 2014. Retrieved 30th October 2018 from
http://blog.first4magnets.com/what-is-a-reed-switch-and-which-magnets-
operate-them/

Frontpoint Security. (n.d). Frontpoint Security control panel. Retrieved 30th


October 2018 from
https://www.frontpointsecurity.com/plans/standard-control-panel

Frontpoint Security. (n.d). Frontpoint Security’s Yard Sign. Retrieved 30th


October 2018 from
https://fi.pinterest.com/pin/346777240028203902/?lp=true

Giaimo, C. (2013). Principle operation of a reed switch. Retrieved 30th


October 2018 from
https://simplisafe.com/blog/door-sensor-secrets

GRobotronics Learning. (n.d). 3x4 matrix keypad. Retrieved 30th October


2018 from
http://learning.grobotronics.com/2014/03/read-keypad-arduino-i2c/
38

Homesalarm. (2018). Home Security Facts and Statistics. Retrieved 30th


October 2018 from
https://www.homesalarm.com/home-security-facts/

IndiaMart. (n.d). Microwave sensor. Retrieved 30th October 2018 from


https://www.indiamart.com/proddetail/microwave-sensor-7207112933.html

IndiaMart. (n.d). MQ135 gas sensor. Retrieved 30th October 2018 from
https://www.indiamart.com/proddetail/mq135-gas-sensor-module-for-air-
quality-11896932155.html

Kushagra. (n.d). LCD. Retrieved 30th October 2018 from


https://www.engineersgarage.com/electronic-components/16x2-lcd-module-
datasheet

Magnasphere. (n.d). INVENTION: The Reed Switch. Retrieved 30th October


2018 from
https://magnasphere.com/invention-the-reed-switch/

PCBheaven. (2010). How a Key Matrix Work. Retrieved 30th October 2018
from
http://pcbheaven.com/wikipages/How_Key_Matrices_Works/

Romano, P. (2014). Arduino Development Kits: Advantages and Features.


28th July 2014. Retrieved 30th October 2018 from
https://www.semiconductorstore.com/blog/2014/Arduino-Development-Kits-
Advantages-and-Features/811/

SafeWise. (n.d). Safety and Home Security Statistics and Facts. Retrieved
30th October 2018 from
https://www.SafeWise.com/resources/security-stats-facts

SafeWise. (n.d). The Beginner’s Guide to Motion Sensor. Retrieved 30th


October 2018 from
https://www.SafeWise.com/resources/motion-sensor-guide

SafeWise. (n.d). What Is a Security System and How Does it Work?


Retrieved 30th October 2018 from
https://www.SafeWise.com/home-security-faq/how-do-security-systems-
work

Smith, S. (2016). The History of Security Systems. 28 th April 2016. Retrieved


30th October 2018 from
http://www.hoyles.com/blog/history-security-systems/

Sparkfun Electronics. (n.d). Reed switch. Retrieved 30th October 2018 from
https://www.sparkfun.com/products/8642

Sparkfun. (n.d). Arduino IDE Interface. Retrieved 30th October 2018 from
https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-the-arduino-
101genuino-101-board/all

Sparkfun. (n.d). Serial Communication. Retrieved 30th October 2018 from


39

https://learn.sparkfun.com/tutorials/serial-communication/uarts

Sparkfun. (n.d). SIK Experiment Guide for the Arduino 101/Genuino 101
Board. Retrieved 30th October 2018 from
https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-the-arduino-
101genuino-101-board/all

Sumeet Eshop India. (n.d). PIR sensor. Retrieved 30th October 2018 from
http://shop.sumeetinstruments.com/index.php?route=product/product&produc
t_id=306

TechnoByte. (2017). Overview of the Arduino Uno hardware. Retrieved 30th


October 2018 from
https://www.technobyte.org/2016/08/overview-arduino-uno-hardware/

ThomasNet. (n.d). How Gas Detectors Work. Retrieved 30th October 2018
from
https://www.thomasnet.com/articles/instruments-controls/How-Gas-
Detectors-Work
40

Appendix 1

ARDUINO PROJECT CODE

Main code

/* code works like this:


+ Set code by pressing * 1 time and then press code
+ specific message from specific phone = reset code
+ * = return to start of loop. delete all entered code */
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "GPRS_Shield_Arduino.h"
#include <SoftwareSerial.h>
namespace KP { //FIX CONFLICT
#include <Keypad.h>
};

#define code_Length 7 // Give enough room for six chars + NULL char
#define MESSAGE_LENGTH 10 //MESSAGE LENGTH
#define ON true
#define OFF false
LiquidCrystal_I2C lcd(0x27, 16, 2);

char Data[code_Length]; //PASSWORD INPUT FOR ACCESS


char Lock[code_Length]; //PASSWORD ALREADY SET
char Buffer[code_Length]; //CHANGE. NEW PASSWORD ENTERED TEMPORARILY
SAVED HERE
char Phone[5][20]; //PHONE NUMBERS CURRENTLY SAVED
char full_phone[20];
char phone_buffer[20];//PHONE CHANGE TEMPORARILY SAVED HERE
int phone_buffer_count;
int order = 0; //FOR CHOOSING PHONE SLOT
byte data_count = 0, lock_count = 0, buffer_count = 0,
state = 0, //STATE TO DEFINE WHAT STEP THE SYSTEM IS IN
option = 1; //OPTION OF SECURITY
bool is_lock; //TO CHECK IF A CODE IS SET OR NOT (FOR FRESH SYSTEM)

bool is_phone_match = false; //CHECK PHONE NUMBER MATCH OR NOT


unsigned long message_check_now = 0;
unsigned long message_check_last = 0;
char message[MESSAGE_LENGTH];
char datetime[24];
byte message_index = 0;
char in_number[20] = {0};
bool is_call_active;

unsigned long last_time_display = 0;


unsigned long wait_time = 6000;
41

bool is_display = true;

int addr = 0; //ADDRESS OF EEPROM

byte pir = 13;


byte reed = 15;
byte led = 16;
byte buzzer = 17;

bool detected = false;


unsigned long current_triggered_time = 0;
unsigned long last_triggered_time = 0;
bool triggered = false;
byte call_order = 0;

unsigned long blink_now = 0;


unsigned long blink_last = 0;

bool input_available = true;


bool message_checked = false;
bool call_owner = false;
bool call_cancel = false;
bool call_back_ok = false;
bool is_call_received = false;

unsigned long system_call_now = 0;


unsigned long system_call_last = 0;

unsigned long check_call_now = 0;


unsigned long check_call_last = 0;

bool is_valid_call = false;


bool make_alarm_call = true;

const int PIN_TX = 2;


const int PIN_RX = 3;
const int BAUDRATE = 9600;
GPRS gprs(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,PWR,BaudRate

const byte ROWS = 4;


const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
int testing = 0;
byte rowPins[ROWS] = {4, 5, 6, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10, 11, 12}; //connect to the column pinouts of the keypad
KP::Keypad kpd = KP::Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//initialize an instance of class NewKeypad
42

void setup()
{
gprs.checkPowerUp(); //START SIM MODULE
while (!gprs.init()) {
delay(1000);
}
lcd.begin(); //START LCD
lcd.noBacklight();
pinMode(pir, INPUT);
pinMode(led, OUTPUT);
pinMode(reed, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
for (addr = 0; addr < 6; addr++) { //ADD CODE FROM EEPROM
Lock[addr] = char(EEPROM.read(addr));
}
for (int i = 0; i < 4; i++) { //ADD PHONE NUMBERS FROM EEPROM
for (int a = 0; a < int(EEPROM.read(20 * i + 10)); a++) {
Phone[i][a] = char(EEPROM.read(20 * i + a + 11));
}
}
if (Lock[0] == NULL) { //IF NO CODE IS SET
is_lock = false;
state = 0;
}
else is_lock = true;
}

void loop()
{
bool pir_state = digitalRead(pir);
bool reed_state = digitalRead(reed);

// Serial.print("PIR IS "); Serial.println(pir_state);


// Serial.print("Detected: "); Serial.println(detected);

char key = kpd.getKey();


if (input_available) {
if (key) { //IF KEY IS PRESSED
if (key == '*') { //KEY * TO DELETE INPUT
if (state != 4 && state != 3) {
clearInput();
if (state != 1) {
lcd_clearLine(1);
}
}
else if (state == 4) phoneChange(key);
}
else if (key == '#') { //KEY # TO TURN OFF LCD
lcd.clear(); //CLEAR LCD
goBase();
is_display = true;
lcd.noBacklight();
}
else {
43

last_time_display = millis();
lcd.backlight(); //KEY PRESSED CAUSE LCD TO TURN ON LIGHT
if (state == 0) { //HOME STATE, INPUT CODE FIRST
if (is_lock == false) { //IF NO CODE IS SET, SET ONE
lcd.setCursor(lock_count, 1);
lcd.print(key);
codeSet(key);
if (is_display == true) {
lcd.setCursor(0, 0);
lcd.print("New code(op ");
lcd.print(option);
lcd.print(')');
is_display = false;
}
}
else { //IF CODE IS SET, INPUT CODE TO CONTROL SYSTEM
lcd.setCursor(data_count, 1);
lcd.print('*');
codeUnlock(key);
if (is_display == true) {
lcd.setCursor(0, 0);
lcd.print("Enter code(op ");
lcd.print(option);
lcd.print(')');
is_display == false;
}
}
}
else if (state == 1) { //PASSWORD ENTERED CORRECTLY
if (key == '1') { //TURN OFF SYSTEM

lcd.clear();
lcd.print("OFF ACTIVATED");
option = 1;
}
else if (key == '2') { //MODE HOME

lcd.clear();
lcd.print("HOME ACTIVATED");
option = 2;
}
else if (key == '3') { //MODE AWAY
lcd.clear();
lcd.print("AWAY ACTIVATED");

option = 3;
}
else if (key == '4') { //MODE MAX
lcd.clear();
lcd.print("MAX ACTIVATED");

option = 4;
}
else if (key == '5') { //CHANGE CODE
44

if (is_display == true) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter new code:");
is_display = false;
}
state = 2;
}
else if (key == '6') {
is_display = true;
state = 3;
stateDisplay();
}
}
else if (state == 2) { //CHANGE PASSWORD BY PRESSING 5
codeChange(key);
}
else if (state == 3) { //CHANGE PHONE NUMBER BY PRESSING 6
phoneSlot(key);
}
else if (state == 4) {
phoneChange(key);
}
}
//DEBOUNCE
}
}
if (millis() - last_time_display >= wait_time) { //SLEEP LCD IF NO ACTION IS DONE
last_time_display = millis();
lcd.noBacklight();
lcd.clear();
is_display = true;
state = 0;
clearInput();
}
if (lock_count == 6) { //SET THE NEW CODE
lcd.clear();
lcd.print("New code set!");
lock_count = 0;
is_lock = 1;
state = 0;
is_display = true;
for (addr = 0; addr < 6; addr++) {
EEPROM.update(addr, Lock[addr]); //ADD CODE TO EEPROM
}
}

if (data_count == 6) { //CHECK IF code INPUT RIGHT OR WRONG


if (!strcmp(Data, Lock)) { //RIGHT CODE, PROCEED TO CONTROL OPTIONS
state = 1;
lcd.setCursor(0, 0);
lcd.print("1:OFF 2:HM 3:AW ");
lcd.setCursor(0, 1);
lcd.print("4:MX 5:CH 6:PN ");
45

is_display = true;
if (detected) { //STOP ALARM
option = 1;
}
}
else { //WRONG CODE INPUT
lcd.setCursor(0, 0);
lcd.print("Wrong code! ");
lcd_clearLine(1);
}
data_count = 0;
}
if (buffer_count == 6) { //CHANGE CODE
strcpy(Lock, Buffer);
lock_count = 6;
buffer_count = 0;
is_display = true;
}
operationMode(pir_state, reed_state);
if (detected) {
alarmON();
}
else {
message_check_now = millis();
if (message_check_now - message_check_last >= 3000) {
message_check_last = millis();
message_index = gprs.isSMSunread();
}
checkIncomingMessage();
}
}

//-------------------------------------------------------------------------------------------------------------
----------------------------------------//

void codeSet(char input) {


Lock[lock_count] = input;
lock_count = lock_count + 1;
}

void codeUnlock(char input) {


Data[data_count] = input;
data_count = data_count + 1;
}
void codeChange(char input) {
lcd.setCursor(buffer_count, 1);
lcd.print(input);
Buffer[buffer_count] = input;
buffer_count = buffer_count + 1;

void clearInput() {
data_count = 0;
46

buffer_count = 0;
lock_count = 0;
phone_buffer_count = 0;
}
void goBase() {
data_count = 0;
buffer_count = 0;
lock_count = 0;
phone_buffer_count = 0;
state = 0;
}

void operationMode(bool pir_read, bool reed_read) { //OPERATION MODES

switch (option) {
case 1: //option 1: sensors do not trigger buzzer and led.
//Do nothing.
alarmOFF();
break;

case 2://option 2: option HOME if someone is at home


if (!detected) {
if (reed_read) {
detected = true;
}
}
break;

case 3://option 3: option AWAY if no one is at home


if (reed_read) {
detected = true;
}
if (!detected) { //IF SECURITY MEASURE IS ON HOLD
if (!triggered) {
if (pir_read) {
triggered = true;
last_triggered_time = millis();
digitalWrite(led, HIGH);
}
}
else {
current_triggered_time = millis();
if (current_triggered_time - last_triggered_time >= 6000) {
if (pir_read) {
detected = true;
}
else {
digitalWrite(led, LOW);
}
triggered = false;
}
}
}
break;
47

case 4: //option 4: option MAX if user wants maximum protection (0 delay for alarm)
if (!detected) {
if (pir_read == true || reed_read == true) {
detected = true;
}
}
break;
default: option = 1;
}

void stateDisplay() {
lcd.clear();
if (state == 3) {
int x = 0; //FOR DISPLAY 2 ITEMS ON 1 LINE

for (int i = 0; i < 4; i++) {


if (x + 1 == i / 2) is_display = true; //FOR DISPLAY 2 ITEMS ON 1 LINE
if (is_display == true) {//FOR DISPLAY 2 ITEMS ON 1 LINE
x = i / 2;
lcd.setCursor(0, x);
is_display = false;
}
lcd.print(i + 1); lcd.print('-');
for (int a = 4; a >= 0; a = a - 1) { //SHOWING SLOTS + LAST 5 NUMBER OF
RESPECTIVE SLOTS.
lcd.print(Phone[i][strlen(Phone[i]) - a - 1]);
}
lcd.print(" ");
}
}
else if (state == 4) {
lcd.setCursor(0, 0);
lcd.print(order); lcd.print('-');
for (int a = 4; a >= 0; a = a - 1) { //SHOWING SLOT + LAST 5 NUMBER OF THAT
SLOT
lcd.print(Phone[order - 1][strlen(Phone[order - 1]) - a - 1]);
}
}
}

void lcd_clearLine(char line_no) {


lcd.setCursor(0, line_no);
lcd.print(" ");
}

void phoneSlot(char input) {


if (input == '1' || input == '2' || input == '3' || input == '4') {
state = 4;
is_display = true;
if (is_display == true) {
order = input - '0';
48

stateDisplay();
}
is_display = false;
}
}

void phoneChange(char input) {


if (input != '*' && input != '#') {
phone_buffer[phone_buffer_count] = input;
lcd.setCursor(phone_buffer_count, 1);
phone_buffer_count++;
lcd.print(input);
}
if ((input == '*') || (phone_buffer_count == 15)) {
lcd.clear();
memset(Phone[order - 1], '\0', sizeof(Phone[order - 1]));
Phone[order - 1][phone_buffer_count] = '/0';
strcpy(Phone[order - 1], phone_buffer);
EEPROM.update(20 * order - 10, phone_buffer_count);
for (int i = 0; i < strlen(phone_buffer); i++) {
EEPROM.update(20 * order - 9 + i, phone_buffer[i]);
}
state = 3;
is_display = true;
stateDisplay();
phone_buffer_count = 0;
memset(phone_buffer, '\0', sizeof(phone_buffer));
}

void checkIncomingCall() {
if (in_number[0] == '+') {
gprs.hangup();
char incoming_number[20] = {0};
strcpy(incoming_number, in_number + 1); //INCOMING NUMBER WITHOUT "+"
for (int i = 0; i < 4; i++) {
if (strcmp(Phone[i], incoming_number) == 0) {
i = 5;
if (is_phone_match) {
option = 1;
}
is_phone_match = true;
}
}
memset(in_number, '\0', sizeof(in_number));
}

void checkIncomingMessage() {
if (message_index > 0) {
char incoming_number[20];
char inc_buffer[20];
49

gprs.readSMS(message_index, message, MESSAGE_LENGTH, inc_buffer, datetime);


strcpy(incoming_number, inc_buffer + 1); //INCOMING NUMBER WITHOUT "+"
gprs.deleteSMS(message_index);
// Serial.print("From number: ");
// Serial.println(inc_buffer);
// Serial.print("Datetime: ");
// Serial.println(datetime);
// Serial.print("Recieved Message: ");
// Serial.println(message);
for (int i = 0; i < 4; i++) {
if (strcmp(Phone[i], incoming_number) == 0) {
is_phone_match = true;
i = 5;
}
}
if (is_phone_match) {
if (!strcmp(message, "1") || !strcmp(message, "2") || !strcmp(message, "3")) { //SET
OPTIONS
option = message[0] - '0';
is_display = true;
}
else if (!strcmp(message, "5")) {
strcpy(Lock, "000000");
for (addr = 0; addr < 6; addr++) {
EEPROM.update(addr, Lock[addr]); //ADD CODE TO EEPROM
}
}
is_phone_match = false;
}
message_index = 0;
}
}

void alarmON() {
if (!is_phone_match) {
if (!call_owner) { //USED FOR CALLING HOUSE OWNERS
while (make_alarm_call == true) {
strcpy(full_phone, "+");
if (strcmp(Phone[call_order], "0") != 0) {
gprs.callUp(strcat(full_phone, Phone[call_order]));
is_valid_call = true;
call_order++;
break;
}
else call_order++;
if (call_order > 3) {
if (!is_valid_call) {
make_alarm_call = false;
}
else call_order = 0;
}
}
call_owner = true;
system_call_last = millis();
50

if (make_alarm_call == true) input_available = false;


else input_available = true;
}
else {
system_call_now = millis();
if (system_call_now - system_call_last >= 7000 && system_call_now -
system_call_last <= 20000 ) { //AFTER 7s ALLOW TO CALL BACK
digitalWrite(led, HIGH);
tone(buzzer, 1000);
if (!input_available) {
gprs.hangup();
input_available = true; //FOR HANGING UP CALL ONLY ONCE
}
if (system_call_now - check_call_now >= 200) { //FOR SLIGHT DELAY BETWEEN
READ FOR FASTER PROGRAM
check_call_now = millis();
is_call_active = gprs.isCallActive(in_number);
}
}
else if (system_call_now - system_call_last < 7000) {
blink_now = millis();
if (blink_now - blink_last >= 100) {
digitalWrite(led, !digitalRead(led));
blink_last = millis();
}
}
if (system_call_now - system_call_last >= 20000) { //AFTER 20s CALL OWNER
AGAIN
call_owner = false;
system_call_now = 0;
}
}
}
else {
check_call_now = millis();
if (check_call_now - check_call_last >= 200) { //FOR SLIGHT DELAY BETWEEN
READ FOR FASTER PROGRAM
check_call_last = millis();
is_call_active = gprs.isCallActive(in_number);
}
}

if (is_call_active) {
checkIncomingCall();
}
}

void alarmOFF() {
digitalWrite(led, LOW);
noTone(buzzer);
detected = false;
call_owner = false;
is_phone_match = false;
is_valid_call = false;
51

make_alarm_call = true;
call_order = 0;
input_available = true;
}

You might also like