makerstorage gsm gate opener

This weekend I got upset with my garage door remote control. I do not know the main reason, but the coverage range is getting worse day by day. I replace the battery which is another reason of becoming angry, but this did not solve my problem. I did not calm myself and decided to make something better as residential access control.

I started to think about a gate access control and my requirements as well as the constraints. The device that I am using to open the garage door must be with me every time. Of course, it is my cellular. There are some solutions that you can install as phone apps and use Wi-Fi to control your garage door, but I want something better. The reason is the Wi-Fi signal is not very strong at my garage, and another requirement that I settled is the security gate system must work with any kind of phone, not only with the smartphones. This requirement forced me to use a GSM module that I have one somewhere around my workshop. I found it and saw that it had simcom SIM900R module on it. I googled it and found lots of informative solutions, but none of them exactly fit for me because of the third requirement. It was security. This system must take action from only the authorized users. This part as usual is a must have but the challenging part is defining a user that will have access must be done via web interface. Wow, will it hurt me to implement? No, not really. After a few minutes of research, I saw that the sim900R module has the ability to make TCP connection with its GPRS feature. Very nice!!!

So let me summarize you the requirements of the gsm gate opener system. If it also fits your needs, you may want to DIY or to have one of the boards that I have built.

  • The coverage must be long enough, and I could open my garage door at the last turn to my house. I do not want to lose time while waiting for it open. Using GSM also lets me open the garage door from anywhere in the world. I may want to let someone that I know in when I am far away.
  • No app installation and the system should work even with my grand mom's phone.
  • It won't need any Wi-Fi signal. Most of the garages are out of home Wi-Fi coverage.
  • It won't need any battery replacement. I have my cellular with me always charged.
  • Must work with only authorized phones. And authorization can be done with a web interface.
  • Will not cost to my phone bill for every access to my garage. (There will be a sim card on the system of course, and this may have a small monthly cost)

If you like my solution for residential access control specially for gate and garage doors, continue reading. I will tell you how to make it with every single detail including source code.

First thing first. The scenario:

You are approaching home, and you take your phone and call your garage security system by pressing a button (speed dial can be a solution). You hear the call ring once, then disconnected to acknowledge the call and to allow the system to get the number calling (Caller ID). This may make you feel bad, but with this feature, there will be no cost that will be billed. :) Supposing you do not want to talk to the caller and you press the RED button on your phone, these systems work exactly the same. But this time, you are the rejected one. Hahaha! Now the system got the caller’s phone number, and it is time to take a look at the authorization. It will make a TCP connection to a server to discover if this phone number has the authority to open the garage door. If the server's answer is yes, the on board relay will be triggered, and this will open the door. If the system understands that this call is not coming from an authorized person, it will not take any action. Easy. Here is the process picture:


Picture will be here



The board design:

GSM Module: The main part is of course the simcom Sim900R. This module will handle all the GSM related activities as well as TCP connection over GPRS.



simcom sim900 module

Microcontroller: I love Atmega328P very much because of the Arduino's popularity. There are lots of ready to use libraries and I am developing the firmware with Arduino IDE. This will be our micro controller which will communicate over a serial bus with the GSM module.

Relay: I only need one relay on board which will be triggered when an authorized call occurs. It is a simple relay with one transistor that drives it.

Expansion pins: I put some pins on the board for future expansion. These pins are related to I2C bus. I have future plans about storing authorized phone numbers inside an I2C Eeprom.


gsm_gate_opener_eagle_schematic

Link to Github board source files

Software:

There are two software running on this system. One is the firmware that will run on our Atmega328P microcontroller. The other is the web interface app that will run on a server.

Firmware:

As you can see from the schematics, Atmega328P have a serial connection with the Sim900 Module. In the main loop, the code waits for the "RING" indication. If it gets it, the code parses the caller id and hangs up. The system then tries to make a TCP connection to the server to check if the caller’s phone number is in our database. If so, the code sends a signal to the on-board relay.

You can download the source code of GSM Gate Opener from our github repo

Web App

In order not to make things complicated, I decided to keep this part as simple as possible. What we have is a MySQL table which holds the phone numbers. And a simple PHP file response to our SIM900 TCP request. You can easily test your system with Digital Oceans. Just set up a one-click LAMP stack. Set your MySQL Table with running an SQL statement like this

CREATE TABLE IF NOT EXISTS `phone` (
 `id` int(11) NOT NULL,
 `devid` int(11) NOT NULL,
 `name` varchar(15) NOT NULL,
 `surname` varchar(15) NOT NULL,
 `phone` varchar(15) NOT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `devid` (`devid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;  

The request coming from the board will be in this format

http://m2m.makerstorage.com/index.php?phone=7072325888

The index.php shown below will get the phone number (in this example it is 7072325888) and will try to fetch it from the database. If it finds the phone number, it will return True otherwise False

<?php 

 // Connect to MySQL
include("dbconnect.php");

$sql = "SELECT * FROM phone WHERE phone=".$_GET["phone"];

//echo $sql;

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "true";
    }
} else {
    echo "false";
}
$conn->close();


?>

Please find the simple web app source code in our github repo

Conclusion:

I do not want to go too deep into the code and technical details here. Please comment below about the problems you are facing or the details you like to talk about. I can update the required part, or I can write a Part 2 for GSM gate opener series. For a quick solution without any headache, you can just buy one GSM gate opener from makerstorage.com. You will also get the support. MakerStorage product page will have the connection diagrams.

I have some plans in my mind to develop other firmware for the system. This version is the one which authorizes the incoming caller ID over TCP connection with a server. The other solutions for the firmware can use Eeprom in order to store the authorized phone numbers. I will update the blog post when I complete the other firmware. For the web app, I also have a better authorization web app that I developed with Laravel. I will talk about it later. Be sure that all these will be open source as always.