Introduction: Security System Using Sigfox and Arduino

Today, the home automation allows us to make great things. In this tutorial, we are going to create our own security system. The goal is to create an object which is independent from your wifi and able to work a long time being powered by a battery in order to protect your home, a garage, an outbuilding and any other place. That's why we are going to use the Sigfox network which is low-energy.

Warning: The tutorial is mainly there to make us practice different technologies. So, do not consider the object as infallible.

Step 1: The Tools

We are going to program an Arduino board. I chose an Arduino Uno but you could use the one you like.

For the radio part of the project, we are going to send messages with Sigfox thanks to an Akene. The Akene is an Arduino shield which uses a modem created by Telecom Design, the TD1208 (Manual is attached). It is based on a ARM cortex M3 chip with a Sigfox radio stack. Using the Akene with Arduino requires to add a library to your project. Snootlab, which created the Akene, has developed a library which allows us to send commands to the modem very easily (GitHub link).

Here are a couple of different solutions that could allow you to use Sigfox in your project: Sigfox makers website

Plug in the Akene on the board like you would have done with any shield and don't forget to add the antenna.

Finally we are going to use a PIR sensor which analyses infrared variations of his environment and creates a voltage in case of movement. An important point is that our object will not make the difference between animals and humans.

The sensor has 3 pins (Here is a datasheet):

  • The power (+5V)
  • The ground
  • A digital output

A picture above shows you how to connect the sensor to the Arduino.

Step 2: The Embedded Code

The code is simple. We check if the PIR pin is high. If so, there is a motion so we must send a message to warn of a problem using the library.

As you can see in the datasheet, the PIR sensor requires a time to calibrate. That's the for loop in the setup() function.

Because Sigfox uses free frequency bands, we have to be careful not to send more than 140 messages per day. To prevent this, the variable "msgSent" is set when we send a message. That way, even if you walk again in front of the sensor the program will not send a second message before you reset the Arduino.

You can download the attached file which contains all the project. If you don't understand a step, please feel free to send me a email.

Step 3: The Web Notification

We are now able to detect someone and to send a message to our API provider (Sigfox backend). We want to create a web callback that will be use to display a notification in case of intrusion.

The first step is to configure the Sigfox backend to make it call our web page when it receives a message. If you have some knowledge in web development, we are going to ask Sigfox to call our page with a POST request and we will see a message with a GET request. We just send a security key (again, this is not the best way to secure our application). There are other parameters that you could send like the id of the device, the latitude and the longitude to locate the device but they are not very useful for our project.

Log in with Sigfox backend account. In the device type section, access to the device type of the object you want to track. In the sidebar, click on the Callbacks option. Click the New button. Set your callback (you can see the picture above to help you).

The second step is to create a web page which must be hosted on a web server. I use PHP with the micro framework Silex (documentation) but we could use NodeJS, Ruby...

Our page must:

  • Accept POST requests
  • Write "1" in a file in case of POST request with the good security key
  • Accept GET requests
  • Read the file in case of GET request. If we read 1, the page displays "There is someone in your house!" and a form to reset the file else the page displays "No problem."

Be sure to create a file in .../silex/web/ named as you want ("alarm" by default in the code). And be careful to give it the good permissions.

If you already have an experience with MVC frameworks you should understand this basic code. If not, don't worry there are many tutorials to begin!

The Sigfox backend is very powerful with that callback system because you can now add other devices which will use the same callback. We could create a second security system and put it in an other room of your house etc. We would be able to distinguish the one which sent the notification with the id of the device. If you want more examples, please feel free to have a look to Nicolas' Github (Maker Evangelist at Sigfox).

Step 4: After?

Have you tested our system? If you walk in front of the sensor you should see the message on the web page. If not, check:

  • The sensor's connections
  • The configuration of the callback
  • The file used by the callback must exist, have the good permissions and be in the good directory

The system is very basic and a good idea would be to add different things:

  • Using your phone (with Bluetooth) to switch on/off the alarm. This would avoid you to (re)set the Arduino when you want to use it.
  • Instead of using a web page as a notification (this is not intuitive), we could create an API which would be called by a mobile application to send "push notifications" to the user.
  • Log the messages in a database.

We have created a Sigfox device, and I encourage you to improve it.

Thanks for reading this tutorial. As you can see, when you want to create a connected object, you need a lot of skills in many areas (electronic, web development, embedded system...). In my opinion, it makes the process very interesting.