Anth's Computer Cave

AAIMI RFID Alarm

18th April 2017

Today I'll show you how to build a cheap and simple but highly-effective RFID-based home or car alarm system.

The components for the alarm system. Picture: Anthony Hartup
The components for the alarm system.

I already have a comprehensive security system in AAIMI Home Automation, but not everybody wants a full blown home-automation system, so I have built a much simpler stand-alone program that just does security. The first of these systems I'm installing in my son's work vehicle to protect his expensive carpentry tools. I wanted this system to be simple. No passwords to forget, and no settings that can cause issues. The last thing you want is the car's horn blasting away because you've pressed the wrong button.

The result is a system so simple that you can't do anything wrong. You swipe your card or key ring when you leave the car, and you swipe it again when you get back in. There are no buttons, no keypads or any other interfaces. It's certainly not my thing - if it was my car it would be running a full version of AAIMI Home Automation with BIG screens - but it's perfect to do the basics.

Let's get into it. First we'll cover the components and connections, then we'll get onto the code.

Components

The brain is an Arduino micro-controller. I'm using a Uno, but you should be able to use any of the other boards. A Mega would be a good choice if you plan to add more sensors and relays.

The RFID reader is an RC552 available from ebay for about $10 each.

An RC552 RFID reader. Picture: Anthony Hartup
An RC552 RFID reader.

They come with one card and one keyring. The units I bought didn't have the pins soldered, so you may need to solder them yourself.

The movement sensor is a cheap - $2 - PIR sensor off Ebay.

A PIR movement sensor. Picture: Anthony Hartup
An RC552 RFID reader.

The relay to activate a screamer or horn is a $2 5v unit off ebay,

An 5v relay. Picture: Anthony Hartup

In our car project we're using the relay to activate the car's horn in the event of a break in.

You'll also need three LEDs and resistors for visual feedback from the system. The cardOk LED flashes when a valid card is detected. The Entry/Exit LED flashes while you are exiting after arming the alarm and again to remind you to swipe the card again when you return. It stays on solid while the system is armed. The Alarm LED flashes in time with the screamer in an alarm event. You can leave your screamer disconnected and use the Alarm LED instead for testing the system without hurting your ears.

Connections

Now we'll put it all together. The diagram below shows the exact connections to match the AAIMI RFID Alarm code.

The components for the alarm system. Picture: Anthony Hartup

The resistor for the LEDs should be around 330 OHMs.

Th RC552 takes 3.3V, not 5V like most gadgets. Don't hook it to 5V out of habit like I nearly did.

Arduino code

You can download the AAIMI RFID Alarm program here.

There are a couple of variables you may wish to change before you upload the sketch to your Arduino.

The entryExitLimit on line 35 is the time allowed to cleanly exit the area, and the time you have to swipe your access card after entering. Because I built the first system for a car I used a fairly short default time of 15 seconds. If you have a longer distance to cover to reach the RFID reader you may want to increase the time.

The alarmCountLimit variable on line 38 controls how long the screamer or horn stay on after an alarm event. Out of respect for your neighbours you should keep this time fairly short, in case the event happens when you're not around. In some places there are EPA rules governing this time-out. The default for this program is 30 seconds. The alarm LED will remain on after the time out to tell you an event has occured.

That's all there is to change for now. You can now save and upload the sketch to your Arduino

Now we need to get the unique ID(UID) from your card and keyring. Open a serial monitor to your Arduino and swipe your card across the RFID reader. You'll see an invalid card message, along with the UID for that card. Swipe any other cards you wish to use and note their UIDs as well.

Now open the sketch again, and go to line 74. Replace the 1000000 placeholders with the UIDs for your cards. If you have more than two cards, add another ' || uid == 1000000' after the others, substituting the extra card number for 1000000.

Save and re-upload the sketch to the arduino.

This time when you swipe your card you should see the cardOK LED flash briefly and a success message printed to the serial monitor. The Entry/Exit LED will flash for the entryTimeLimit duration, then turn on solid. The system is now armed.

If the PIR sensor detects movement, the system will begin enter-mode and the Entry/Exit light will start flashing again. Swipe your card, and the cardOK light will flash, then switch off. The system is disarmed.

If you don't disarm the system before the timeout it will activate the alarm. Swipe your card to clear the alarm and disarm the system.

That's it, your AAIMI RFID Alarm is on duty.

Car system

Below is an example of an installation in a vehicle.

The components for the alarm system. Picture: Anthony Hartup

It uses a double relay to take control of the vehicle's horn if it needs to sound the alarm. The Arduino is hidden under the dash, away from the RFID reader and PIR movement sensors. This means that even if an intruder smashes the PIR and reader, the Arduino can still activate the horn.

Cheers

Anth

_____________________________________________


Comments

Leave a comment on this article