Professional Documents
Culture Documents
Thanh Nguyen Thesis - Low-Cost Residential Security System
Thanh Nguyen Thesis - Low-Cost Residential Security System
BACHELOR’S THESIS
Valkeakoski, date
ABSTRACT
Automation Engineering
Valkeakoski
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.
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.
CONTENTS
7 CONCLUSION ........................................................................................................ 35
4
REFERENCES ............................................................................................................... 36
APPENDICES
Appendix 1 ARDUINO PROJECT CODE
5
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
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)
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.
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
3.3 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
In home security system, reed switches, as door sensors, are usually set up as
shown in Figure 4.
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.
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
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.
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
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
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.
company. This method helps decrease the chance of being targeted. Figure 9
is a yard sign on which words glow at night.
4.1 Overview
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
All in all, Arduino is a suitable platform for making small range projects, of
which the Low-cost Security System is.
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
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
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)
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.
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.
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.
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
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.
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.
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.
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.
is in the closed position by default and will become open if there is current
flowing through the electromagnet.
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.
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.
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.
For this project, a GPRS Shield SIM900-based was used that can be stacked
upon Arduino Uno.
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.
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).
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.
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:
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.
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.
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
- 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.
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). 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
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
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). 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
EEE Projects. (2017). Detail of Arduino Uno. Retrieved 30th October 2018
from
https://eeeproject.com/arduino-uno-board/
Farnell. (n.d). Arduino Uno Datasheet. Retrieved 30th October 2018 from
https://www.farnell.com/datasheets/1682209.pdf
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
PCBheaven. (2010). How a Key Matrix Work. Retrieved 30th October 2018
from
http://pcbheaven.com/wikipages/How_Key_Matrices_Works/
SafeWise. (n.d). Safety and Home Security Statistics and Facts. Retrieved
30th October 2018 from
https://www.SafeWise.com/resources/security-stats-facts
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
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
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
Main code
#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);
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);
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
}
}
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 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;
}
switch (option) {
case 1: //option 1: sensors do not trigger buzzer and led.
//Do nothing.
alarmOFF();
break;
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
stateDisplay();
}
is_display = false;
}
}
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
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 (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;
}