Introduction: EAL-Embedded Security System

About: nick6379 & marc1706

This is an educational project, aiming to get familiar with Arduino and the C language.

Step 1: Overview

In this Instructable we will show how to make a door security system. The idea is to use a Hall magnetic sensor to detect whether a door is open or closed. The Arduino program is then setting the colour of an RGB LED. If the door is closed the LED is green, if the door is open the LED is blue and if the door has been opened for too long the LED is red (indicating a security risk).

Furthermore we will show how to use an Android application, to log on to the security system, by sending a password over bluetooth and either arm or disarm the security system. When the security system is armed opening the door will result in an alarm going off, in form of the LED blinking red.

Step 2: Video

A short video of the functionality.

Step 3: Parts List

  • Arduino MEGA 2560 R3 with USB-cable
  • Arduino KY-003 Hall magnetic sensor module
  • HC-05 Integrated Bluetooth Module Wireless Serial Port Module 6 pin New for Arduino
  • Breadboard 830 point solderless PCB breadboard mb-102
  • 3 Color RGB LED KY-016 FZ0455

Step 4: Wiring

Step 5: Arduino Program

To time the duration the door has remained open we use the millis() function provided by Arduino. This function returns the amount of time passed since the program started running. When the door opens we store the value of millis() in the integer "start" and then we compare the value of start to the current value of millis(). In the event that millis() becomes 5000 greater than start (5 seconds have passed) and the door is still open, the LED is set to red. By using millis() this way, instead of delay() for example, the program can keep running its other functions and not hang until delay() is finished.

//Start counter, when the door changes from being closed to open.<br>	if(digitalRead(hall)!=last) {
	//Red true, when the door has been opened for 5 sekonds, else false.
	if(millis()>start+5000 && !digitalRead(green)) {
		digitalWrite(red, true);
	else {
		digitalWrite(red, false);
//Helping variable to detect when the door changes from being closed to open.<br>last=digitalRead(hall);

We also wrote 3 void functions of our own to interact with the bluetooth module: login(), readlock() and logoff().

In the event that the bluetooth module is receiving and noone is already logged in with the correct password login() will read the received data and match it against a predefined password. If the password is correct the "in" flag will be set true and the program is opened to be armed or disarmed.

void login() {<br>	//Reads code parsed from a phone.
	if(Serial.available() && code=="") { // Checks whether data is comming from the serial port
 		code = Serial.readString(); // Reads the data from the serial port
	//Checks the code from the phone against the password.
	if(code==pass) {
		digitalWrite(13, true);
	else {
		digitalWrite(13, false);

When someone is logged in and the bluetooth module is receiving, readLock() will read the received data and store it in the variable "lock". Lock determines whether the system is armed (lock = 1) or disarmed (lock = 0).

void readlock() {<br>	//Helping variable for logging off.
	//Reading lock, unlock and logoff from the phone.
	if(Serial.available() && in) {
  	lock =; // Reads the data from the serial port

In the event lock gets set to 2, logoff() will reset the password, stored in code, to empty and the in flag to false, prohibiting anyone from arming or disarming the system, until someone logs in with the correct password again.

void logoff() {<br>	//If logoff recieved reverts lock to its last state, resets the code and sets login to false.
	if(lock=='2') {

Step 6: Android Application

The Android application is developed using MIT's App Inventor 2, which is a free Android application builder found at

To connect to the Bluetooth module via the app there had to be made a list picker with a Bluetooth client in it. In the list picker we programmed Bluetooth client addresses and names, so you can choose the Bluetooth module you want to connect to.

The log in button sends the text that has been entered in the password textbox to the Bluetooth module. The log off button sends byte number 50 to the Bluetooth module which is read as the integer 2 in the Arduino program.

The arm and disarm buttons can only be activated when the correct code is entered, and you are logged in. Each button sends a byte number to the Bluetooth module, arm sends byte number 49, which is read as the integer 1 in the Arduino program, and disarm sends 48, which is read as the integer 0 in the Arduino program.

The application and MIT APP Inventor 2 project can be downloaded below.

Step 7: I/O List

  • Bluetooth HC-05
  • RXD
  • TXD

Digital inputs

Hall magnetic sensor

  • Hall = 8

Digital outputs


  • Blue = 10
  • Red = 11
  • Green = 12

Step 8: Evaluation


The system is still pretty barebones and the parts have to be individually placed on a door. Was this to be a final product in daily use, we would have liked to build an easily mountable and battery-powered box for the Arduino, the Hall sensor and the bluetooth module, with an output where the user could choose to connect an alarm response of their choice, as well as an easily mountable magnet.

Further development

Given that we continue working on this project we would want to add functionality for the alarm to send a notification to your phone over the internet. This would require either a WIFI or a GSM module and probably a server to bounce the signal off of. Having the system connected to the internet would also open up for more function possibilites for the Android application. We could for example add functionality to arm and disarm the system while away from home.