Design and Implementation of an IoT-Based Smart Home Security System
- Mohammad Asadul Hoque1, *, Chad Davidson21Department of Computing, East Tennessee State University, Johnson City, TN 37614, USA2Department of Electrical Engineering and Computer Science, University of Tennessee, Knoxville, Tennessee, USA*Corresponding author. Email: firstname.lastname@example.org
- Corresponding Author
- Mohammad Asadul Hoque
- https://doi.org/10.2991/ijndc.k.190326.004How to use a DOI?
- Smart home, security, IoT, Arduino, Raspberry Pi, NodeJS, MongoDB, RF transmission
Recent advances in smartphones and affordable open-source hardware platforms have enabled the development of low-cost architectures for Internet-of-Things (IoT)-enabled home automation and security systems. These systems usually consist of sensing and actuating layer that is made up of sensors such as passive infrared sensors, also known as motion sensors; temperature sensors; smoke sensors, and web cameras for security surveillance. These sensors, smart electrical appliances, and other IoT devices connect to the Internet through a home gateway. This paper lays out an architecture for a cost-effective smart door sensor that will inform a user through an Android application, of door open events in a house or office environment. The proposed architecture uses an Arduino-compatible Elegoo Mega 2560 microcontroller board along with the Raspberry Pi 2 board for communicating with a web server that implements a RESTful API. Several programming languages are used in the implementation and further applications of the door sensor are discussed as well as some of its shortcomings such as possible interference from other radio frequency devices.
- © 2019 The Authors. Published by Atlantis Press SARL.
- Open Access
- This is an open access article distributed under the CC BY-NC 4.0 license (http://creativecommons.org/licenses/by-nc/4.0/).
The Internet-of-Things (IoT) is a vision for an internetwork of intelligent, communicating objects such as home appliances, vehicles, factory machines, wearable devices and various types of sensors. The convergence of technologies like ubiquitous wireless communications, machine learning, real-time analytics and embedded systems has made novel IoT applications possible in a multitude of domains. A combination of commercial interests and government initiatives have made smart homes, smart healthcare, smart cities, and smart transport primary areas of focus for IoT application development.
Internet-of-things-enabled personal healthcare applications will require sensors to collect data in smart spaces, such as smart homes or healthcare environments, and from wearable or implanted RFID tags. Data from RFID devices will provide insights into people’s diurnal activities, help detect abnormal events, and possibly alert caregivers to problems. The idea of using an IoT to create smart cities may have originated with a 1990’s era nationwide coalition, Smart Growth America (SGA). SGA sought to address issues related to urban environments, including resource management, transportation, and public administration. Recent government support for information and communication technology systems may finally allow the SGA’s vision to be realized. Potential applications of IoT include the monitoring of building health, energy consumption, noise, and air quality; improved waste and traffic management; and smart lighting. The Internet-of-Vehicles (IoV) is a subfield of IoT that uses wireless technology to enable vehicles to communicate with their environment. IoV creates opportunities for developing novel applications in intelligent traffic control and management, road safety and vehicular safety such as online diagnosis, anti-theft systems and tracking [1–16]. IoV enables vehicles to communicate utilizing multiple modes of communications including vehicle-to-vehicle, vehicle-to-network-to-vehicle, and vehicle-to-infrastructure communications.
Smart home is a section of the IoT paradigm that aims to integrate home automation and security. Enabling objects in a typical household to be connected to the Internet allows home-owners to remotely monitor and control them. From lamps that are set on timers to turn off at a specific time of the day, to smart thermostats that will regulate the temperatures in a house and generate detailed reports about energy usage, smart homes have found its niche in the consumer market. The availability of affordable smartphones, micro-controllers and other open-source hardware along with the increasing use of cloud services, has made it possible to develop low-cost smart home security systems. With families having busier lives than ever, smart home automation and security systems can also cater to household members with limited mobility such as the handicapped and the old.
The purpose of this paper is to present a low-cost architecture using RF based communication in a household to create an IoT-enabled smart home security system . Smart home devices that typically consume low power such as smart bulbs and door or window sensors use RF transceivers to communicate with each other. In this paper, an inexpensive architecture is proposed for a smart door sensor that will utilize an Elegoo Mega 2560 microcontroller board, Raspberry Pi 2, a web server, and an Android application.
2. RELATED WORK
Prior work in IoT-enabled home security system has proposed architectures that focused on the use of low-cost open-source hardware components like the Arduino and Raspberry Pi MCU boards and a combination of sensors. Passive Infrared (PIR) sensors are used to detect motion and can work in sync with a webcam that captures images to alert users of trespassing.
Kodali et al.  describe a cost-effective wireless home security and automation system based on the TI-CC3200 LaunchPad: a battery-powered Microcontroller Unit (MCU) with built-in Wi-Fi connectivity. PIR motion sensors are placed at the entrances to a building and connect to a digital input–output pin of the MCU. The MCU is programmed using Energia Integrated Development Environment (IDE) and Wi-Fi enabled. Kodali et al.’s configuration allows mobile phones without Internet connectivity to receive security alerts and control IoT devices connected to the microcontroller. Tanwar et al.  describe an inexpensive home security system that implements a real-time email alert system. The system uses a PIR module and a Raspberry Pi MCU. Security cameras and PIR sensors are connected to the Raspberry Pi via USB ports and general purpose input/output pins respectively. The system assumes that homes have Internet access; it uses the Internet to send e-mails to the resident in real-time. The system’s intrusion detection logic identifies motion by comparing signal inputs from the PIR sensors with their previous values. When current and previous signals differ, the security camera captures an image that is stored temporarily on the Raspberry Pi and then automatically e-mailed to the resident.
Gupta and Chhabra  describe a cost-effective Ethernet-based smart home system for monitoring energy consumption, smoke and temperature levels and detecting trespassing. This system uses the Arduino-certified Intel Galileo 2nd generation microcontroller board. Temperature, smoke and PIR sensors are connected directly to the microcontroller, while four 220 V devices are connected via a relay module. An android based mobile app that connects to the Intel Galileo-based server over the Internet allows users to toggle switching devices by tap-to-touch or voice commands through Google API speech recognition tools.
Piyare et al.  present a Bluetooth-based home automation system where an Android cell phone running a Python script communicates with an Arduino BT board with digital and analog input/output ports to which sensors and appliances are connected. The smartphone application has a toggle on and off feature for each device. However, Bluetooth connectivity between the smartphone and the Arduino BT board required a range of 50 m or less within a concrete building and mobile platforms other than Symbian do not support the Pyhton application.
Behera et al.  designed and implemented a real-time smart home automation system using an Arduino Uno board along with an Arduino Wi-Fi Shield and a PC home server. A PIR or motion sensor, an light dependent resistor and an LM35 temperature sensor were used to collect data which was made available on the PC server that also implemented a MATLAB-GUI platform to control the temperature, lights, and fans. The PIR sensor also acted as a security component by detecting possible intrusions and setting off a buzzer to alert the residents.
Howedi et al.  proposed a low-cost smart home system built upon a similar architecture using the Arduino Uno board, PIR sensors, DHT11 temperature sensors, INA219 high side DC current sensor and servo motors that control doors and windows. The Arduino IDE is used to implement the control and monitoring module of the system while the MIT App Inventor is used to develop a simple Android application.
Panwar et al.  implemented the Eyrie smart home automation system using the Raspberry Pi 3 MCU as the central hub. Their proposed architecture connected several Arduino Nano boards located around the house to various types of sensors and NRF24L trans-receivers that eliminated the need for Ethernet or Wi-Fi connectivity. Mosquito Broker, an open-source message broker used for relaying messages to the Raspberry Pi 3, operates using the Debian OS. Eclipse SmartHome framework was used to implement a web interface and a smartphone app for end-users.
In Baraka et al. , a home automation system with smart task scheduling is developed making use of wireless ZigBee to connect appliances and wired X10 technology to connect light and switch modules to an Arduino microcontroller. An Ethernet shield mounted on the Arduino MCU allows communication between Arduino and a web-based Android application which is then used to remotely add and manage devices and view recommended scheduling.
ShariqSuhail et al.  implemented a prototype for smart home security system that uses PIR sensors for intrusion detection, MQ2 sensors for detecting smoke and gas leaks, LM35 temperature sensors as input to an Arduino Mega 2560. A buzzer, LCD, LED strip and a Global System for Mobile communication (GSM) module are outputs to this MCU board while a Raspberry Pi 2 board is used to include a webcam that captures images upon motion detection. GSM, a wireless technology interfaces with the Arduino Mega to send SMS notifications and calls to the user’s cell phone whenever potential intrusion, smoke or gas leak is detected.
In Gunputh et al. , a similar architecture utilizes an Arduino Mega 2560 board with a Wi-Fi module to implement a voice-controlled smart home system. The Elechouse V3 voice recognition module allows users to send voice commands to adjust lighting, open or close windows and control a folding bed.
Vineeth’s et al.  voice-controlled secure eHome also make use of the V3 voice recognition module but use an RF module instead of Wi-Fi for wireless communication between an Arduino UNO and Raspberry Pi MCUs. The Raspberry Pi supports sensor connectivity to the Internet so all sensory data can be logged onto a Google spreadsheet. There is no implementation of a mobile or web app thus confining the controlling of this system to the location of the mic.
Sunehra et al.  propose two schemes for a speech-based home automation system. The first scheme uses HC-05 Bluetooth module along with Arduino Bluetooth controller mobile application to control appliances when inside the house. GSM/GPRS technology is used to remotely control appliances and receive SMS alerts for possible intrusion detections. The ARM11 Raspberry Pi board acts as the central hub for receiving voice commands though the HC-05 Bluetooth module and connects to a PIR sensor, relays, a Wi-Fi router and a webcam.
3. SYSTEM ARCHITECTURE AND DESIGN
3.1. Devices and Sensors
Elegoo Mega 2560 board (or Arduino).
RF receiver–transmitter pair (433 Hz).
Magnetic reed switch.
Raspberry Pi 2.
Female-to-Female–Female-to-Male Jumper Cables.
Android phone or emulator.
Figure 1 presents a diagram of the pinout of the Raspberry Pi 2 attached to an RF Receiver. The RF Receiver has leads to ground, a 5 V power supply, and to pin 13 on the Raspberry Pi (used in OpenDoor.cpp in repository). Note that there is a second Data pin that is not to be utilized in this project and an antenna (not pictured) was formed out of rolled aluminum foil.
Figure 2 describe the schematics for wiring the Elegoo Mega boards. In Figure 2, a magnetic reed switch and RF 433Hz transmitter is attached to the Mega 2560 board. The ordering of the wires do not matter for the reed switch. One wire leads to ground and for the code located in the repository, pin 2 on the Mega 2560 board is where the other wire will lead. The RF transmitter has leads to ground, a 5 V power supply, and a lead to pin 10 on our board. The antenna used for this project is a simple rolled piece of aluminum foil.
3.3. System Architecture
Figure 3 describes the overall architecture of the smart home security system. Figure 4 shows the flow diagram of data communication. Each of the following subsections provide a detailed explanation of how the devices communicate with each other. A simple overview of the system architecture will help understand why the sections have been laid out in the order they are. Initially, the reed switch is opened which causes the Elegoo board to send an RF signal from its transmitter to the RF receiver located on the Raspberry Pi 2. The Raspberry Pi then sends an HTTP POST request to a RESTful web server that is set up in the cloud. This web server then either pushes information, or receives GET requests from an Android application to allow the end user to view the door open events by date and time. All libraries mentioned in the following sections are open source.
3.4. Communication between Elegoo and Raspberry Pi 2
The connection between the Elegoo and the Raspberry Pi is the most important part as it is where the sensor in the IoT architecture communicates with another device. Once the door is open and the reed switch is activated, an RF transmission of 433 Hz is sent from the transmitter using the RC-switch library for the Arduino. A binary code is sent to the receiver connected to the Raspberry Pi and it is incremented for every subsequent door open event. This enables the Raspberry Pi to keep track of individual door open events. The RF transmission range was tested in a 1200 sq. ft apartment. When the reed switch is activated, a constant stream of binary numbers is transmitted to the receiver attached to the Raspberry Pi. Using a simple piece of aluminum foil as antennae on the receiver and the transmitter, the entire 1200 sq. ft of the house is covered. The Raspberry Pi utilized the wiringPi library and the 433Utils library to receive the binary codes. These codes are then sent as a text file output that is read by a Python script that will perform the next step of the communication process.
3.5. Communication between Raspberry Pi 2 and NodeJS Web Server
When the binary codes have been received and sent as output to a text file, a Python script utilizing the Requests library checks the text file every second for new updates. When a new code is placed in the text file, a POST request is then sent to an HTTP web server that is set up with NodeJS and a MongoDB database. This server implements a RESTful API that stores door open events by date and time. The data located in this database are accessible via GET requests that can be performed by the Android application.
3.6. Communication between Web Server and Android Device
The final step in the communication process is between the web server and the Android application written in Java. It is possible to send push notifications whenever a new door open event is detected by the web server, however, for the purposes of this project, the Android application makes GET requests to the server. The Android application uses a variety of libraries that are available through the Android Studio but the library used to make the requests is the Volley library.
In this section, we discuss the algorithms corresponding to the different programs running in different portion of the system. The Raspberry Pi required a Python script for updating the NodeJS server (Algorithm 1) and a C++ program for receiving the code transmitted by Arduino through the 433 MHz RF antenna (Algorithm 2). The program in Arduino for sensing door opening and transmitting code to Raspberry Pi was written in C++ (Algorithm 3). The Android application was implemented using Java. Due to complexity, the algorithm for the Android application is not presented in this paper.
5. TESTING OF THE PROTOTYPE
This section describes the actual testing using the prototype of the proposed IoT-based smart home security system. Figures 5–9 sequentially depicts the successful testing and operation of the prototype. The system has been tested within a 1200 sq. ft apartment. The range can be extended if the 433 MHz antenna is extended with cheap aluminum foils.
Python program for Raspberry Pi
C++ Program for sensing and receiving code in Raspberry Pi
C++ Program for sensing and transmitting from Arduino
6. FUTURE SCOPE
This design can be used as a reference for further applications to be developed with the current sensor architecture, and it provides a framework using the Raspberry Pi through which other sensors can be added to the smart home network.
6.1. Reed Switch Applications
The door sensor provides a way of seeing whether or not a door has been opened. The most obvious way to extend this application is to record the amount of time a door is open. While this may be useful to individual end users, there lies a possible business interest in knowing how often the doors to a store are opened and closed. This information can then be used by businesses to lower their energy costs.
A second future application for this architecture could include connecting a Bluetooth module to the Mega 2560 board to identify individuals entering through the door by pairing with an end users phone. It could also be used by parents to check on a child that may try to leave home at an odd hour.
6.2. Further Raspberry Pi Applications
Since the Raspberry Pi uses an RF receiver it can not only receive the transmission from the magnetic reed switch but also be outfitted with the ability to receive transmissions from other RF-enabled devices in the household. The Raspberry Pi could be used as a hub for RF-enabled smart home devices throughout the house. The concept can be used to develop a more advanced home security system that would include PIR motion sensors placed in other areas of the house to detect intrusion while homeowners are away. Using, RF-enabled bulbs the smart home system can be extended to include energy management inside the house.
The Raspberry Pi can serve as a fog computing device which can store information locally before sending it to the cloud server. This can be useful when applications might need real time support or low latency that cannot be provided by the cloud service.
6.3. Android Application Improvements
The Android application for this project, written in Java, is a basic application. Future work may involve adding time zone support from the device so as not to depend solely on Unix timestamps. Multiple options to view and display the data located in the MongoDB database, can also be added. A calendar feature can be integrated so users can have a more robust view of the door open events in their household. The system can be enhanced to display alerts to users in the form of SMS or email in the event of trespassing.
Potential issues may arise through interference on the 433 Hz RF frequency. Many home devices use RF signals to communicate and at a given time there may be more than one RF receiver trying to send signals to the Raspberry Pi or it could be picking up signals that it was not intended to receive. An interference testing with the RF units can be done as a part of future work. In the case of multiple transmitters attempting to communicate with the Raspberry Pi, there would need to be a registration system in place on the Raspberry Pi that kept track of incoming signals and their sources. However, the architecture proposed here does not provide that support.
This paper presents an architecture that can be used as framework to build a low-cost smart home security system. Using affordable components such as microcontrollers from Elegoo and Raspberry Pi and RF signals as a communication channel between these devices, it was possible to develop an IoT system that allows users of a household to view when a particular door has been opened. Schematics for connecting the different components have been provided along with figures to demonstrate them. The data flow between each of these devices have been explained and potential issues that may arise have been discussed. Finally, future work in this area along with potential use cases for this architecture have also been discussed.
CONFLICTS OF INTEREST
There is no conflict of interest.
Cite this article
TY - JOUR AU - Mohammad Asadul Hoque AU - Chad Davidson PY - 2019 DA - 2019/04/16 TI - Design and Implementation of an IoT-Based Smart Home Security System JO - International Journal of Networked and Distributed Computing SP - 85 EP - 92 VL - 7 IS - 2 SN - 2211-7946 UR - https://doi.org/10.2991/ijndc.k.190326.004 DO - https://doi.org/10.2991/ijndc.k.190326.004 ID - Hoque2019 ER -