Thursday, March 26, 2015

RFID Garage Door Opener with Arduino

This week I took a leap to add RFID access to my garage door. This was largely spurred by how flaky my manufacturer's wireless keypad is for my opener in the cold weather. I wanted something hard wired, and I knew RFID was fairly cheap to add to Arduino. And it's freaking awesome!

This setup isn't network aware, so you cannot monitor the status of the garage door or add/remove keyfobs remotely. You're getting short on digital pins on a standard UNO/Leonardo, so you'd probably want a Mega if that was something you wanted. I will probably add that in the future. I've never done WiFi with the Arduino, so this would be a good opportunity. I'll probably also look at adding a real time clock module so I can permit access only within certain windows (such as giving spare fobs/cards to family but only allowing entry during the day).

First you'll need an Arduino. I've used both UNOs and Leonardos with this build and they both work great. You'll also need an RC-522 reader, available on Amazon and eBay. This is easy to integrate with Arduino. Extra cards/fobs are also nice, and you'll want to get ones that work with "Mifare" in the 13.56Mhz band. These are also available for cheap in bulk from the 'Bay.

You'll also want to use some sort of relay or transistor as your output. In this case I used a regular Arduino-compatable relay module. I liked that it gives me an audible click for testing purposes, but a solid state relay or transistor would do just as well to trigger a garage door opener (which just momentarily touches two wires together). 

RC-522, with right angle pins (included) soldered on
I took my code and inspiration from miguelbalboa's GitHub. His code uses a single RGB led for feedback, which I found works the best. I tried paring this down to two leds, but you really want all three.

Hook the pins up as follows:

* 3.3V on Arduino to the 3.3V on the RFID reader.
* Pin 9 on Arduino to RST on RFID.
* Pin 10 on Arduino to SDA on RFID.
* Pin 11 on Arduino to MOSI on RFID.
* Pin 12 on Arduino to MISO on RFID.
* Pin 13 on Arduino to SCK on RFID.
* Red LED to Arduino Pin 7
* Green LED to Arduino Pin 6
* Blue LED to Arduino Pin 5
* Finally, your output relay on Arduino Pin 4
* There's an option for a reset button to be used on Pin 3. This reset button will wipe the memory of all cards, so you can start fresh. This is nice when you're first playing with things. 

The code from Miguel is annotated to allow for both common anode or common cathode RGB LEDs.

First time you boot it up, watch your serial console in the Arduino IDE to make sure you know what's going on. The first card you scan becomes the "master" card that puts the system into program mode (where you can add or remove cards).

Once you scan a master card, put the system into program mode. All three colors will flash in sequence. Now begin scanning additional cards. A successful "add" will be followed by two green flashes. If the card is already part of the system, then scanning it again removes it. Successful removal is indicated by two blue flashes. You'll see this written verbosely in the serial console. The LED feedback is needed once you install it in the field.

Cards are stored in the ATmega's EEPROM and so will survive a loss of power. This EEPROM has a limited number of writes (about 100k), but can be read unlimitedly. Realistically you could add and remove cards in normal usage for years before you hit the write limit.

I breadboarded mine, with an LED hooked up to the output to see how well it operated.


 Then it went into a case I had lying around.


In the right photo you can see the two relay module at the bottom. 

I used a Rugged Circuits Aussie Shield to connect everything up in the finished product. This was just easier than soldering a prototype shield, which would have been much cheaper. This is a great product to use, and in the future will be much easier to repurpose than a soldered up protoshield.

The wires coming into the case include the five control wires for the RFID reader and the four wires for the RGB feedback LEDs. There's also two wires that tie into the garage door opener's button circuit. I made the wiring harness myself, which is why the level of craftsmanship is so unbelievably high.

I have intentionally left the reset button off the physical build (but in the software). This means that to reset (erase all the memorized cards, including the master) the system, you need to manually jumper pin 3 to ground. To me, this works, since I don't want someone who is clicking buttons to accidentally reset everything.

You'll also notice that I used a separate box for the "brains" of the system, the Arduino and relay. My initial inclination was to shove this all into a single gang box with only a power wire and the garage door triggers coming in/out. My wife insisted that it be "hack proof", so I put the smarts (and the garage hook ups) on the inside. If you take off the wall plate outside, in order to hack into the system you'd still need to simulate the RFID board (protocol and the correct key codes).

I hotglued the RFID board directly to a plastic faceplate. This doesn't seem to interfere too much with the signal, but you do have only a couple of millimeters range to begin with. You basically need to touch the fob to the plate to get a read. This is a little more awkward with the credit card style than it is with a keyfob. 


Here's the finished outdoor portion, with my wiring harness fed through a hole into the garage. The box (initially surface mounted) has been recessed into the garage trim.

The blue is intentionally dim. I put an extra resistor on that part of the circuit when I put the recessed box together so that it wasn't a bright blue beacon for the neighborhood. The green and red are of "normal" brightness to give a clear indication of a read. 

Overall this was a simple build, since it doesn't involve network access or a RTC. However, since it doesn't use those you get a rather "dumb" appliance. This can be good, since it seems like the more functionality you add, the more points of failure you encounter.  I'm also only using one output. I've got an extra relay that might find some usage in the future.

Tuesday, February 3, 2015

Today I remembered why I don't like Windows

Over the last five years or so I've really grown to love Linux as my day to day operating system of choice. I switched to Ubuntu back at the 9.04 release and haven't really looked back. As the other computers in the house started to experience issues, I replaced the bloated, slow, virus infested Windows installs with linux. I've come to like the Linux Mint variety and use my desktop of choice, Mate. After playing the the bleeding edge versions I now stick with the long term support (LTS) releases.

I even replaced Windows on my wife's laptop some years back, initially just on a live USB stick, to see if she liked it and it did everything for her. Since it did, it brought life back to an old, slow laptop. She's since gotten a Acer C720 Chromebook, which is awesome for her needs (internet consumption) and paying bills and writing up a resume.

There's only one computer left in the house running Windows, the home theater PC in my theater room. It remains on Windows mostly out of laziness and because I tend to believe if it's working, not to fix it. It has been running Windows 7 for about five years and has been running well and without major issues. It runs my Plex desktop app which is really all I use, plus the occasional look at a trailer or video on Youtube.

I was this latter use that led me to discover that my antivirus protected Windows computer, protected by a well respected antivirus brand I might add, was infected with some form of virus. The virus made it terribly difficult to use the internet, as it opened extra browser windows, redirected links, and conducted all sorts of other hyjinks with my system.

So I checked that my antivirus was operating, it was, and the definitions were up to date, supposedly there were no updates, but the date was more than a year old. I came to find out that my antivirus now required a subscription to get new definitions. This is ridiculous to me, to pay through perpetuity for basic security. Aside from being connected to the internet, this computer is really used for nothing by watching movies. If Windows hadn't been so full of holes, I don't see how it could have become infected. 

Anywho, I loaded the free AVG antivirus which discovered the viruses, removed the offending files, and after a couple of reboots, I was virus free. I then went into the installed programs to find that whatever virus I'd become infected with had installed about four programs that I didn't want, need, or even know what they do. So I got rid of those in short order. 

What this taught me was that I need to keep a better watch on this system, I hardly ever do any maintenance on it, so I'm partially to blame here. But it also reminded me how I haven't had to deal with any of these virus related issues on any of my Linux-based systems. I also, while sitting watching a progress bar cross very slowly on the only source of entertainment in the room, remembered how great and easy the remote administration options are in Linux. I set up all my systems to allow secure shell (SSH) access, so I can access them all remotely from my main desktop. I update them all multiple times a week and use this access to do all my troubleshooting from the comfort of my office chair. 

In spite of how little I like dealing with typical Windows issues, today's problem was relatively easy to fix, and I was up and running again in about an hour, virus free. I was really tempted to just blow the Windows installation off the drive and fully convert to Linux. However, I didn't, partly out of my aforementioned laziness, but mostly because I think I like still having one bare metal Windows (i.e. not a virtual machine) computer in the house. If for no other reason than to keep my Windows troubleshooting and repair skills in shape. Because there's no end to the complaints and issues people bring up with their Windows computers. :-) 

Seagate ST2000DM001 are really crap

As a followup to my earlier article about tearing apart one of the Seagate ST3000DM001 3TB hard drives, I can now say they are one of the worst drives I've ever used.

A couple years back, when the 3TB drives were first hitting the streets in reasonable prices, I decided to upgrade my file server. I'd collected a large number of 1TB drives over time that I wanted to consolidate to a single 4x3TB drive stack.

The price on the Seagate drives was the best at the time, though I'd had better luck in the past with Western Digital drives, I decided to save a few bucks. Not only that, Seagate is a Minnesota company. I like to support local businesses.

While I was in money-saving mode, I opted to go with external drives as my donors, since they were cheaper than the bare drives (why is that? it's absurd). I tore four external drives apart to get my donors for my server expansion/consolidation.


Fast forward some time, one of the Seagate's failed. Not unusual for hard drives to fail. In the past, I'd simply submit it to the manufacturer for a replacement and operate off a backup in the meantime. However, apparently since these were originally external drives (Seagate branded mind you) they were considered OEM and not covered by Seagate. I'd late find out all four drives were similarly denied replacement.

I replaced that first failed drive with a WD 3TB and got things back up and running. About 9 months later I had another of the Seagates fail. I was able to replace it (with a WD) and get my data back, since I'd fully prepared for a single drive failure. What I could not recover from was the back-to-back failure of the remaining two Seagates in my server. In the span of a week, three of these drives failed, with the loss of all data on them.

Now, I've discovered some similar stories of pre-mature failure of these drives. There's a firmware update that I was hopeful would help, but the software failed to recognize the drives after their failure.

I noticed that the drives were very hot (in their well ventilated case with "automatic" fans), much hotter than the WD drives above and below them. Now, I can't say whether they were hot as part of the failure or if the heat hastened their demise. What I can say is that four of four drives failed (three in a span of days). I've had drives, from a variety of manufacturers, fail over the years. What I have not had was every drive from one place fail (and at once!).

I cannot in good conscience recommend these drives for anything you hold dear (and copying 3TB of anything takes a good bit of time, so....).

On a side note, I bought WD Green drives (having used them for years and found them to be solid performers), but after reading this, think I will choose Reds in the future.

Search This Blog