DIY GSM-enabled Gate Access Control System

I built this system about a year ago, and I get so many people asking me how it was done I figured it would be a good post to help reboot my blog…

DIY Gate Access Control System

Background

Both during the week and on weekends I entertain quite a few guests. We watch TV (sports/movies) in a room separate from the main house (the Playroom* – also home to my workshop) which does not have an intercom extension, and on the summer weekends I host braais in the outside entertainment area (also no intercom extension). Access to the property is through a motorised gate. Often guests ringing the doorbell will be doing so in vain, as the ringing can only be heard from inside the main house. Usually I get a message or a missed-call on my mobile informing me that someone is outside the gate and that no one is answering the doorbell!

Doorbell, gate, driveway...

Doorbell, gate, driveway...

One solution to this problem is to add extra intercom extensions to the Playroom and the braai area. ZZZzzzz BORING! I figured why not let my guests let themselves in, using their mobile phones! And so the idea of GSM-enabled gate access control was born.

I had recently been exposed to the world of Arduino by my friend and collaborator Tegan Bristow and thought this would be a great problem to solve using the Arduino platform, learning as I went along. At the time I was busy finishing off my Master’s degree in electrical engineering, where I focussed on wireless communications, designing custom PCBs for a platform using Microchip PIC18F microcontrollers. And some of you seasoned electronics engineers will think WHAT! WHY USE ARDUINO WHEN YOU CAN BE 11.8x MORE EFFICIENT USING A CUSTOM MICROCONTROLLER-BASED DESIGN! Which is true. I could sit and design an elegant solution featuring only the necessary electronic components, using power-saving design techniques and choosing just the right microcontroller for the job based on number of used IO pins and peripheral features. Perhaps one day I will. But my research was already consuming much of my time, and I took the path of choosing the Arduino platform, for its plug ‘n play attitude, minimal setup and well documented pre-written libraries. Coming from a background working with PICs and AVRs from scratch, it was actually quite nice to spend more time tweaking a mostly working design, as opposed to tweaking a design to be mostly working.

*the Playroom was given its name when my parents built the room for my sister and I to play in when we were children. It has its own bathroom, some comfy couches and used to feature cupboards full of toys and games and even an old piano. Now it has a fridge and a Samsung LED HDTV, and the piano has been replaced with my workbench.

Design

Once I had decided that I would be using the Arduino platform as a base, I then searched for a suitable GSM shield. I browsed around the web and read over a couple of forums where others had discussed similar GSM-telemetry Arduino projects, and settled on Sparkfun’s Cellular Shield, based on the SM5100B GSM/GPRS module. The next problem would be how to open the gate remotely. I first thought that I would tap into the intercom receiver’s gate “open” button, maybe close the connection with a relay. But as I spend most of my time in the Playroom I wanted to be notified visually or audibly of guests arriving, and dreaded the thought of running cable from inside the house to the Playroom. Of course I could add some XBees or other wireless point to point link, but I didn’t feel the extra expense and complexity would be worth it. Then one day I stumbled across an unused remote control for the gate – its plastic buttons had broken off and it was just lying in the kitchen drawer. A-HA! I could tap into the button on this remote control and have my system sit in the Playroom (or anywhere in range of the gate control receiver)!

ArduinoCellularShieldGateRemote

Arduino + Cellular shield + Gate remote = :)

After figuring out the required hardware I moved on to thinking about how I would control access. My first working solution used SMS messages, where the gate was opened on reception of a text featuring a four letter password. I also added the ability for me to enable/disable the whole system using an SMS and my own master code, as well as a feature where I could change the regular access code at any time. The cellular shield communicates with the microcontroller using UART serial comms, sending cryptic text strings to show what is happening in the GSM cellular receiver. It was easy enough to look through the text string to find the relevant password and act accordingly.

It worked! But many of my friends complained that by sending an SMS they were in effect spending money to visit my house. Most of them jokingly complained, but it still got me thinking: How could I reduce the expense of opening my gate? First thoughts were to use the GPRS capabilities of the Cellular Shield to access a web server or app accessible from mobile phones. WOW that seemed over-complicated, and would take up way too much of my time, and would probably be quite tedious for the visitors to accomplish (as opposed to sending a text). Then I thought back to how I usually knew someone was at the gate – a missed-call on my mobile! So I then redesigned everything to work as follows:

  1. Guest self-registers by sending an SMS with the letters REG to the gate access number.
  2. GSM module sends SMS data to Arduino.
  3. Arduino passes along SMS data to Python script running on a PC.
  4. Python script checks the SMS text to see if contains REG string.
  5. If it contains the REG string, number is added to whitelist text file on the PC. If not, message is discarded.
  6. When guest wishes to open gate, guest calls the gate access number.
  7. GSM module sends call data to Arduino.
  8. Arduino sends call data to Python script on PC, and ends the call (resulting in a unsuccessful call for the caller).
  9. Python script checks incoming number against whitelist.
  10. If number exists in whitelist, script tells Arduino to open the gate using the remote control button connections. If doesn’t exist, does nothing.

You will notice that I have included a PC to manage the whitelist. I did this because at the time I didn’t have the time to figure out the best way to store a list of numbers in some form of memory using the Arduino, and also the string-handling operations were a bit more complicated than simply reading text messages. It just seemed easier to do in Python. I am now in the process of working out a PC-less version of the whole system, using an SD card interfaced to the Arduino for whitelist storage.

Hardware

Features:

  • On-board 5V and 3.3V linear regulators
  • Interface for external 5V and GND inputs
  • Transistor driven DC audio buzzer
  • RS-232 serial interface
  • Arduino reset button
  • 3x LEDs
  • Header connections for cellular shield (only necessary pins are electrically connected, others just for structural support)
  • Header connections for remote control
Gate access control motherboard

Gate access control motherboard

Underside of motherboard

Underside of motherboard

NB: In the picture there is a red wire connecting a pin from the MAX232 IC to the 5V regulator – I forgot to label an electrical connection in Eagle as 5V! It has been fixed in the schematic and PCB layout.

Gate remote control

Gate remote control

Gate remote showing cable interface

Gate remote showing cable interface

The remote control requires a power supply and a connection to the Arduino to close the switch. The remote was originally powered by a 3V coin cell battery. I’ve replaced this with a 3.3V supply (fed from the 5V regulator/external input). The switch is closed by pulling one side of the physical switch to ground – setting the Arduino pin LOW momentarily does the trick just fine.

The DC buzzer is activated on a 5V signal. I used a transistor to switch in the 5V from the supply to make sure I can draw the required current for the buzzer.

One LED is connected across the 5V supply; the other two are used by the Arduino as visual outputs. The LED connections are shown as header pin connections in the schematic; this is to show that the LEDs may be situated on an enclosure surface, and not necessarily on the PCB.

I made the PCB at home using my homemade UV exposure unit, some pre-sensitised copper and the required chemicals.

Eagle files: dcon.sch, dcon.brd; Schematic in PDF: dcon.pdf – Apologies the schematic is not very neat!

Software

I chose Python as it’s a really nice scripting language, and also because I had used a Python script to monitor a serial port in my academic research, so I kind of already knew what to do. I modified Chris Liechti’s miniterm.py example script to scan incoming text from the serial port, and to run custom functions based on the input. My modifications do the following:

  • Scan the PC to see which port the USB-Serial adapter is connected.
  • Run startup functions: delete any existing SMS messages that may have been sent to the number in the off-time, set the message mode to text mode (much easier to decode and read, see SM5100B documentation), and turn on auto-reporting (so that we don’t need to check for new SMS messages, the data is pushed immediately to the serial interface).
  • Scans incoming SMS messages for “REG” phrase. If it is a REG message then the script checks if the number already exists in the whitelist, if not it will append it to the file.
  • Extracts originating number from incoming calls, checking to see if number exists on whitelist. If on whitelist the script will instruct the Arduino to open the gate by sending a particular ASCII character.
  • The script also tells the Arduino to switch on/off an LED depending on if the module is connected to the GSM network. I do need to work on this a bit more, because I have noticed that I could be on the network, but unable to make or receive calls other than send emergency calls. I think I need to check for a different status update from the GSM module to make sure I am 100% on the network and able to receive text messages and calls.
  • Modified some of the miniterm.py default values so parameters are hardcoded (no need to supply any in the command line).

I use a USB<->Serial cable to connect to my custom Arduino board to the PC. This cable uses a Prolific PL2303 IC for interfacing between the two protocols. I specificly look for the Prolific hardware information when I scan the serial ports to see on which port the cable is connected. So if I had to use a cable using an FTDI chip for example, my automated scanning would not work. I will try “generalise” the scanning later.

Originally I developed the script to run on my laptop running Ubuntu, and I used the native Linux tool “hwinfo” to scan the USB ports and find on which one the Prolific USB<->serial cable was connected, then run the modified miniterm.py script (dcon.py) with the relevant parameters (this was before I hardcoded these parameters):

#!/bin/bash
hwinfo_string=$(hwinfo --short --usb | grep PL2303)
usb_port=${hwinfo_string:0:14}
python dcon.py -b 9600 $usb_port --cr -e

BUT I have since moved the system to my sister’s Windows desktop PC that sits in the Playroom. The script now searches the Windows registry to see if the Prolific serial interface cable is connected, and continues the script by connecting to the serial port.

I haven’t really made many comments in the Python code, but it’s here if you’d like to have a look: dcon.py

Firmware

The firmware passes the serial data from the GSM module to the Python script, and passes AT commands from the Python script to the GSM module. Specific characters sent from the Python script which are not AT commands are intercepted in the Arduino code and either turn the GSM network LED on/off or open the gate by pulling the Arduino pin connected to the remote control switch LOW.

Arduino sketch here: dcon.pde

Usage and Example

To get everything working you need to:

  1. Plug the USB<->Serial cable into the computer.
  2. Run the Python script by double clicking on dcon.py
  3. Switch the power on the Arduino board.

Then you’ll see a whole bunch of stuff happen in the Python window on the PC. Here’s what you’ll see when you switch everything on, register a mobile number and then make a call to open the gate…

dcon.py - DIY Gate Access Control System - Dino Fizzotti, 2010 - 2011
using miniterm.py by Chris Liechti: http://pyserial.sourceforge.net

USBSerial cable found on COM7

--- Miniterm on COM7: 9600,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
CELLMISSCALL
Starting SM5100B Communication...
áá
+SIND: 1

+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1

+STIN:0

+SIND: 11

REGISTERED TO NETWORK
GSM ON

+SIND: 3

+SIND: 4
DEVICE READY
DELETING ALL MESSAGES

OK
DELETE MSGs OK
SETTING TEXT MODE

OK
TEXT MODE OK
SETTING AUTO REPORT

OK
AUTO REPORT OK

OK

+CREG: 1

+CREG: 1

+CREG: 1

+CREG: 1
+CMT: "+2782xxxxxx2","+2782xxxxxx","11/08/17,18:00:43+08",3
SMS MESSAGE RECEIVED
+2782xxxxxx2
REG MESSAGE RECEIVED FROM +2782xxxxxx2
REGISTERING NUMBER

+CREG: 1

RING

+CLIP: "+2782xxxxxx2",145
INCOMING NUMBER
+2782xxxxxx2
MATCH
OPENING GATE

Conclusion

So there it all is. The DIY Gate Access Control System, or “dcon” as I refer to it myself. So nowadays when my good friends come over to hang out I don’t need to listen for the doorbell, or run to the gate intercom to open for them. They simply let themselves in.

One of the other popular uses for my access system is when friends and I go out in large groups: everyone can park their own cars in my driveway, and we can all leave in a few designated cars, or leave with a taxi or two. Using the gate system I do not need to be home for others to fetch their cars, they can simply come home when they want (say by catching their own taxi) and let themselves in to fetch their car and let themselves out again to leave. Again, I really only allow people who I really trust to use the system.

Files


9 responses to “DIY GSM-enabled Gate Access Control System

  1. Pingback: DIY GSM-enabled Gate Access Control System | dinofizz

  2. Dude, that is awesome. I wish I had time to play around with this kind of stuff…

    • Thanks JC! If you are at all interested you should take a look at the Arduino platform. It’s so easy to get stuff working, really not at all like the micros we battled with at uni ;)

  3. Done something similar with the output from works phone system, looks for missed calls from list of mobiles onto my extension and activates relay to trigger gate, but my code uses a XML configuration file so not as ambitious as using gsm.
    Comments on yours would be can anyone who knows the number register and be put on the Whitelist ?, I would adapt it to accept only SMS reg messages from you and removals from you.

    I did mine before I had Arduino’s and our phone system is about to be VoIP so I guess v2 will be gsm’d

    • Yep right now anyone who knows the number can register. I wanted to make it as autonomous as possible. For example, I’m hosting a party in the coming weeks with around 100 guests. They will be registering for access using this system, saving me the trouble of vetting 100 text messages. What I’m thinking of doing is making people register with their names. I can then periodically check the whitelist and query any names I don’t recognise.

      FYI as an update, I have since re-engineered this system to work without a PC, using an Arduino with an SD card for whitelist storage. I’ll be posting these details soon.

  4. Hey Dinofizz,
    Very cool project. Working on something similar (who’s details I hope to post soon). Two thoughts:

    1) For a limited set of people, you could use the SIM’s built-in address book to store whitelisted numbers. I believe there’s 255 slots available.
    2) Did you ever post the arduino-only whitelist checking code? I’m about to delve in to parsing a command set, and wanted to see what someone else had done ahead of time.

    Again, cool project.

    Thanks,
    Chris

  5. Hi Dino
    Did you manage the updated version without a PC..very interested!
    Cheers
    Schalk

    • Hi Schalk. The updated version worked pretty well, with the Arduino reading and writing from text file on an SD card. Unfortunately not long after I finished that work I moved to a new country, and the move kinda took up all my time, and then I just never got back into maintaing this propject or this blog :|

      But if you have any questions or would like to see the Arduino code (which I’m sure I have saved somewhere) send me an email at fizzotti at gmail.com

  6. Hi,
    I have no recollection of whether my source code is currently working, but I went through several iterations of a similar project:
    https://bitbucket.org/clearf/arduino-public/src

    Some notes:
    If you don’t need cellular, consider wifi or bluetooth on a raspberry pi — I found that much easier to work with in the end, as I could write higher level code.

    Enjoy,
    Chris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s