How to make an alarm system with Arduino

With Arduino is really possible to make complex projects, particularly through the use of the Internet, you can use it through the various Shield available for the micro-controller. In this article, we will see how to make a professional alarm system with Arduino.

This system will be able to record every movement that is detected in the house and will be saved in a database, which can be accessed remotely from any device, using a simple browser, or dedicated applications.

Requirements for the


· 1x Arduino Mega

· 1 x Ethernet Shield

· n x Arduino Uno

· n x Wireless 433 MHz kit

· n + 1 x PIR sensor

· PC/Raspberry Pi


· MySQL Connector for Arduino

· Wireless 433 MHz VirtualWire Library

· Wireless data send library

· Webduino library

· My code for my from my gitub repo

Step 1: ?How does the system work ?

How to make an alarm system with Arduino

The alarm system is based on using a sort of central station, they are connected to n clients . Each device is equipped with a PIR sensor , which is able to detect the passage of a person, through the variation of heat detected. The various clients have a wireless TX , which will send a signal to the central station, to warn the detection of a person. The main server is nothing more than an Arduino Mega connected to the Internet via the Ethernet card official , which contains over a PIR sensor , a wireless RX , which is able to receive signals that clients send . To figure out which client sent the signal, it will be equipped with some sort of identifier , set by the user when registering the client. As for the recording / saving of readings , you will use a database, which can be installed on a PC or even on the Raspberry Pi . The upload will be done directly from the central station , which is the only one to be connected to the Internet. The retrieval of information relating to the surveys , you can make it through a web page, or through an application built in Java. In addition, the central station is equipped with a web server , with which you can disable / enable the alarm system . We'll see how it is possible , with an Android phone , automate the activation / disabling the alarm system.

Step 2: ?Install the MySQL DB

How to make an alarm system with Arduino
How to make an alarm system with Arduino
How to make an alarm system with Arduino

The first step to do in order to use the alarm system , is to install a MySQL server on your PC. It should be specified that the computer must remain Arduino access so that you can complete the proper storage of detections. For this reason , the board to install the DB on Raspberry Pi , so as to drastically reduce the power consumption . Windows / Mac / Linux, you can install the server , downloading the package from the official website of MySQL . In order to complete the next steps of the project , such as creating login credentials and much more, you must install the Workbench. The latter is a program that allows you to easily interface with the MySQL server . The Workbench, you can download it from this web page

Raspberry PI

To install the MySQL server on the Raspberry Pi , you must type in a terminal:

sudo apt- get install mysql-server

To install the client Workbench instead :

sudo apt- get install mysql-workbench

During server installation , you are prompted to enter a user name and a password , which are used to gain access through the Workbench to DB server .

By default, the server is set up to access connections are made on the machine, ie localhost mode . To be able to perform , instead of the insert , or the Select remotely , please also create a new account, with the possibility to turn on even outside of the device. To do so, open the Workbench menu Raspberry Pi . Select the " New Server Instance " and the next page, select localhost and type the login credentials , I've created when you installed the MySQL server. Now that you have created a connection to the DB , we can create a user that can even remotely be able to access the Raspberry Pi .

To do this we double-click on the connection you created and it will open a new page, where we'll see a little 'statistics regarding use of the server. We select with a click the "Users and Privileges" and create a new account. Care must be taken that in the "From host" will be a% in order to allow all types of incoming connections.

Step 3: MySQL Schema

How to make an alarm system with Arduino

Now that we have the MySQL server installed, set the access credentials for access from any device to the DB, we can create our "scheme" for the alarm system. The scheme is nothing more than the set of relationships that make up our project. Each report contains the attributes. In our case the pattern will be the following:

Schema Sistema_allarme

Relazione1 Dispositivi(idDispositivi,Luogo,Citta)

Relazione2 Rilevamenti(ID,DATA,ORA)

In the first " tables" have gathered all the devices that are present in our alarm system. For example, we can install an Arduino Uno with PIR Sensor in Living Room, while we can put another Arduino Uno in the bedroom .

In the second " tables" are the various surveys that have been recorded , with the date and time. The ID is used to identify the various devices in your home. For the creation of the various " tables" just open a connection to the MySQL Workbench , through the " MySQL Connections" . The data included are those that have been created in the previous step , such as user name and password. The IP can also leave the localhost ( Then it will open a page where we could control our DB . The thing to do is to select the " Create new schema " on the top and give the name of Sistema_allarme . Once you have created the schema, we can create the " tables" that is our relationship. To do this, select the bottom right corner " Sistema_allarme " and the right button , select the " Create table " . The next steps are used to enter the data that have been reported previously . The only item to be added in this regard, is to insert idDispositivi as the primary key of the relation / tables Devices . In this way there will be no two devices with the same identifier .

Step 4: ?How to connect the various devices

How to make an alarm system with Arduino

As previously mentioned, at the base of the project, there are two types of devices, the server / central station which is composed of Arduino Mega, which allows you to upload your data to DB using an Internet connection, while the client is made up of an Arduino Uno and is able to send the detected motion to the server, using the PIR sensor and wireless components.

Server / Central Station


VCC -> 5V

OUT -> PIN 4


RX Wireless 433 MHz


DATA -> PIN 11

DATA-> None V

CC -> 5V



VCC -> 5V

OUT -> PIN 3


Wireless 433 MHz TX

ATAD -> PIN 11

VCC -> 5-12 V (increases the signal port, increasing the voltage)


Step 5: ?Installing Software components for Arduino

As previously reported, in order to successfully compile the codes that I realized you need to download the libraries that are not present by default in the IDE Arduino. The installation is really simple, you can just download the file in. Zip, unzip and move them into the Arduino / libraries on your computer.

Here are the codes of the programs of the alarm system version 1.0


You can find the Arduino code for the server here



This code should be installed in every client, who want to detected a motion via sensor PIR.

If the PIR detect a motion, the client will send via wireless a message to the Master,

who will make an insert to the MySQL DB

Version 1.0

Author Giacomo Bellazzi

Copyright (C) 2014 Giacomo Bellazzi (


* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.


* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of


* GNU General Public License for more details.




const int baudRate = 800;

int pinPIR = 3;

int led = 13;

int timeLed = 800;

int pinTX = 12;

int ID = 2; // The ID of the client

void setup()


Serial.begin(9600); // Debugging only


SetupRFDataTxnLink(pinTX, baudRate);


void loop()



float outArray[1]; // this array keep the data to send

outArray[0] = ID; // send the ID of the client

union RFData outDataSeq;

EncodeRFData(outArray, outDataSeq);




// remain in this status, not to send motion twice




//This method detects the presence of people

boolean motionDetected(){


return true;


return false;



// This method light a led, for time

void ledOnOff(int led,int timeLed){





The code is quite understandable from the point of view of the mechanism of the motion detection. If a client detects a transition, it sends a value that identifies the server and the server will know to send an insert in the database, with the time and place given that there has been movement.

Step 6: ?How to enable / disable the alarm

How to make an alarm system with Arduino
How to make an alarm system with Arduino
How to make an alarm system with Arduino
How to make an alarm system with Arduino
How to make an alarm system with Arduino

As for the traditional alarm systems , this is also able to be deactivated , for example we are in the house and it is normal that there is movement ! To do this , it was made a webserver inside the train station, from which you can manage the system. Typing the IP address of the server, it will open a web page protected by a user name and password. In the case of this code , the credentials are:

user = admin

password = admin

The encoding used is the base 64 and has been implemented using the excellent library Webduino , with which it is possible to simplify the process of creating web pages with Arduino. To change the credentials for access to the protected page of the alarm system , you can modify the code to replace the string = YWRtaW46YWRtaW4 , with the desired one. To create its string , which represents the encoding base 64 of its credentials is possible to use online tools , such as . For example if you want to create the following credentials ;

user = nomeutente

password = password

Insert in "encode" nomeutente:password e and the result will be bm9tZXV0ZW50ZTpwYXNzd29yZA==.

In the protected page of the web server , you can enable and disable the alarm system by pressing the center button , which will change color depending on the state .
It should be noted that by default , when you start Arduino , the system is active, even if it was previously disabled. This is due to the fact that the memory in which the Arduino is volatile static variables and then reboot the device , you lose the data. However, it is available in the repo , a program that solves this problem, that holds the state chosen even after you restart Arduino . However there is a small problem , the memory where the data is saved , and yet you call EPROM has a "life" at the bottom of the Arduino RAM . Therefore overuse of writing , it can damage it. Therefore I recommend using the standard program . Alternatively , you could disable the system through a switch, however , it would ensure a lower level of security , since anyone could turn it off. However, in a future version , I will introduced the ability to enable the manual system , through the secure web page .

Step 7: ?How to retrieve the checks?

How to make an alarm system with Arduino

The easiest method to retrieve the data is to perform a query to the DB that we have installed. The query is nothing more than a query that returns tuples, which are nothing more than our observations. To do this, we type this query in the Workbench:


FROM Sistema_allarme.Rilevamenti as RI join Sistema_allarme.Dispositivi as DI on (RI.ID = DI.idDispositivi)

In order to access from smartphones to this list of detections, you can install a kind of workbench to your device and enter the previous query.

How to activate / deactivate the automatic system ?

The system offers the ability to automate the procedure for activating / deactivating the alarm system, thanks to a program available for Android Llam be downloaded from this link . kebab.Llama . This need is due to the fact that the alarm system is lose functionality when we are in the house, which is detected in the room , if the system were active , there would be many records of measurements unnecessary . In order to automate the system , we can decide to turn it on when the GPS position is away from home, or to turn it off when we get in the house . To set up what has been said , you need to open the application LLama , go to the Events you add one , the features to be activated are:

Within in the area - short run app - preferred ( http://ipwebserver.private.hmtl/?off )

I leave the area - short run app - preferred ( http://ipwebserver.private.hmtl/?on )

Java application for PC

In addition to using the Workbench to be able to record / see the various surveys , you can use the Java application that I have made . The first procedure to do is to enter the username and password of the MySQL server . Through the menu, you can select the two operations permitted to register a client in an area and to view the surveys , filtering by ID , Date and Time .

Step 8: Download the application to switch on/off the Alarm from Android

How to make an alarm system with Arduino
How to make an alarm system with Arduino

If you want to switch on/off the alarm with Android, you can download the application from the Play store, by typing AlarmON or by this link

Remember that once you have downloaded it, you have to set up the username, password and the Arduino's IP from the preferences.


Tag cloud

make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel