MacGuyver Episode 1: NFC Doorbell

Posted by Guy Dupont on Jul 29, 2016 4:13:48 PM

I don’t have all that much in common with Angus MacGyver; he's the legendary secret agent who duct-taped and hot-wired his way through 139 action-packed TV episodes. I’m Guy, an Android developer who sits on a purple yoga ball for eight hours every day. What we do share is a knack for building useful things from limited resources.

When my dad decided I was old enough to use a soldering iron, I built a headphone splitter out of a Philadelphia Cream Cheese box. In college, I ripped the volume knob out of an old guitar, poked it through the end of a Solo cup, and created a remote control for my roommates' stereo system.

None of these “hacks” required any knowledge beyond high school physics, but in each case I was able to throw together a semi-permanent solution in less than 20 minutes— all without leaving home. This is probably as far as I can stretch the MacGyver comparison; his best ideas were fueled by real science and the need to survive. Mine are mostly products of impatience.


Now I write code for a living, and though I don’t think it’s fair to refer to my MacBook Pro as “limited resources,” I still find myself throwing together these baby hacks fairly frequently. The process usually looks something like this:

  1. “Oh man, my life would be so much better/easier/sillier if I could do x” - 1 minute
  2. Search Google, inevitably land somewhere on Stack Overflow - 5 to 10 minutes
  3. Piece together "functional" code - 15 minutes
  4. Tear apart desk and/or closet for spare hardware - 5 minutes, if necessary
  5. Show your friends! - 5 minutes of people looking at you funny
  6. Make code pretty - 10 to 20 minutes (optional, depending on who you ask)

I’ll be sharing some of my more useful projects here. The code will always be short and simple. Any third-party resources I reference will be free to use (or very close to it), and the hardware should be reasonably easy to come by.


Episode 01 - The Doorbell

The Problem:

Intrepid opened a new office space down the street. Many people need to move back and forth; few have key cards.

The Solution:

NFC doorbell!

I built an app to run on an old Android phone, which I mounted by the door. When an Intrepid employee (or anyone who knows why the phone is taped to the wall, honestly) taps an NFC-enabled device or card to this phone, it sends a message to the office’s Slack channel letting everyone know that someone needs to get in. Once the Slack message has been successfully posted, the phone’s camera flash lights up for a few seconds to let the employee (or enlightened stranger) know that the office has been alerted. Why did I choose NFC? Two reasons:

  • It allowed me to mount the phone inside the office. The NFC magic still works through our thin glass wall, so I was able to greatly reduce the chances of somebody walking off with our device.
  • A large majority of people in our office are carrying some kind of NFC do-dad, whether they realize it or not. We successfully tested with Android phones, metro passes, old hotel room keys, credit cards… you name it. The app doesn’t actually read any data via NFC; it just needs to know something is nearby.

Here is the source code:


There are a few things worth noting as you make your way through the code base. First, you’ll see that I have provided two implementations of the camera-flasher module. I wanted to build this using the most up-to-date camera APIs, but these were only made available as of API level 23. I did end up using these to build the NewLedFlasher class, but I provided an OldLedFlasher to run on devices that have not received an update to Marshmallow. The app decides which module to use in MainActivity, at line 29

Also, you’ll notice that the most important method in the app is mostly empty: MainActivity.onNfcScanned(). This is the method that is called when the app actually makes an NFC discovery. You should do something cool here! Intrepid’s in-house build makes a post to one of our Slack channels, but there are plenty of other options, including:

While you’re at it, consider adding some of these other awesome features we thought of:

  • Allow your administrator to register a set of pre-approved keys, so that NFC-enabled strangers can’t ring in
  • Let your visitors chose from a list of people to notify
  • Add a hardware integration, so you can actually unlock the door remotely

If you have any questions, issues, or suggestions, feel free to leave a comment or fork the repo. 

Stay lazy thrifty!



Topics: Hacks, NFC, Hardware