Shane Engelman
Published © GPL3+

Start Your [ANYTHING] with NFC

Got a spare NFC tag? I'll show you how to use it to trip a relay to do cool stuff like start a motorcycle or turn on a PS4

AdvancedFull instructions provided9,479
Start Your [ANYTHING] with NFC

Things used in this project

Hardware components

Latching Relay
The brand or type doesn't matter. You want a latching relay just in case your hardware fails while riding. With a latching relay, separate pins must be tripped in order to trigger an open or closed condition, which means if your Arduino has a loose connection, your bike won't lose power in the middle of a ride.
×1
Adafruit PN532 NFC Shield
×1
Adafruit Arduino Pro Mini 5V 16MHz
×1
Power Regulator
Buy a few. You'll probably fry at least one before you realize the correct pins to apply power to.
×2

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Use your solder of choice. I use a butane-powered iron http://www.amazon.com/Weller-P2C-Butane-Soldering-Iron/dp/B000B61L0G
Multimeter
Wire
Use thin wire for the through-hole pins
Wire Cutters

Story

Read more

Schematics

Mock Schematic

Head to https://learn.adafruit.com/adafruit-pn532-rfid-nfc/shield-wiring
for updated proper wiring of PN532 shield to Arduino pins.
Pins for Uno (which can be used instead) will be equivalent on Pro Mini.

Pins 11 and 12 on Arduino will be used to Engage and disengage the relay.

I made this to help you see how everything is wired up.
This is the general appearance of the components as they will be wired together. Add an optional on and off switch if you don't ride the motorcycle daily, to conserve power on the motorcycle battery.

Placement of Reader

I had to make a custom cover for my battery. Harleys are all metal and block the NFC signal. Note: So does carbon fiber.

My Setup

Here is what my components looked like inside the battery cover. Note: Ignore my engage/disengage pins. Follow the code / pin instructions included in the software section coupled with Adafruit's. This is mainly illustrative and has since been iterated.

Code

NFC BikeCode

C/C++
This is Arduino code, tested for an Uno and a Pro Mini 5V 16MHz
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
#define IRQ   (2)
#define RESET (3)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

void setup(void) {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT); // When HIGH, will close relay connection
  pinMode(11, OUTPUT); // When HIGH, will open relay connection
  nfc.begin();
  nfc.SAMConfig();
}
boolean bikeOn = false;

void loop(void) {
  //Authorized UIDs
  uint8_t auth_uids[][7] = {
    // Scan your tag with a phone and place appropriate bytes below
    // prefxing each one with "0x" and delimiting with a comma ","
    {0x12, 0xFE, 0x12, 0x4E, 0x00, 0x00, 0x00}  // Description of Particluar Tag
    // ,{0xFE, 0xE2, 0x70, 0x5A, 0x00, 0x00, 0x00} // Add a second one like so
  };
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
  uint8_t uidLength;

  if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength)) {
    Serial.print("Entry Request for UID: ");
    nfc.PrintHex(uid, uidLength);
    uint32_t i;
    uint32_t b;
    int num_uids = sizeof(auth_uids) / sizeof(auth_uids[0]);
    Serial.println(num_uids);
    for (i = 0; i < num_uids; i++) {
      Serial.print("Comparing UID to: ");
      nfc.PrintHex(auth_uids[i], 7);
      for (b = 0; b < 7; b++) {
        if (uid[b] == auth_uids[i][b]) {
          if (b == 6) {
            Serial.println("Read and matched!");
            if (!bikeOn) {
              if (bikeOn) {
                Serial.println("bikeOn = True");
              }
              if (!bikeOn) {
                Serial.println("bikeOn = False");
              }
              bikeOn = true;
              if (bikeOn) {
                Serial.println("bikeOn = True");
              }
              if (!bikeOn) {
                Serial.println("bikeOn = False");
              }
              digitalWrite(12, HIGH);
              digitalWrite(13, HIGH);
              Serial.println("Relay On (Closed/Tripped)");
              delay(2000);
              digitalWrite(12, LOW);
              Serial.println("Delay Done");
            } else {
              if (bikeOn) {
                Serial.println("bikeOn = True");
              }
              if (!bikeOn) {
                Serial.println("bikeOn = False");
              }
              bikeOn = false;
              if (bikeOn) {
                Serial.println("bikeOn = True");
              }
              if (!bikeOn) {
                Serial.println("bikeOn = False");
              }
              digitalWrite(11, HIGH);
              digitalWrite(13, LOW);
              Serial.println("Relay Off (Open/Untripped)");
              delay(2000);
              digitalWrite(11, LOW);
              Serial.println("Delay Done");
            }
            i = num_uids;
          }
        } else {
          Serial.println("Failed!");
          b = 7;
        }
      }
    }
  }
}

Additional Instructions

snippets
You'll need the NFC library from Adafruit, found at https://learn.adafruit.com/adafruit-pn532-rfid-nfc/arduino-library
Instructions for adding a library can be found on Ardunio's website (arduino.cc)

Motorcycles have batteries that output ~12V. We need a regulator to ensure that
the Arduino gets a constant stream of "clean" power so it doesn't shut off
unexpectedly while riding or engaging the starter (in the use case of a
motorcycle). These types of regulators are adjustable. They'll take any voltage
within a certain range and spit out whatever you'd like very reliably. I use a
5V Arduino, but you can use whatever voltage microcontroller you want! This is
where the multimeter comes in. 

Latching relays all have slightly different pinouts, but behave generally the same way.
You have power, ground, and two pins to trip the relay to either closed or open.
There are rails to attach the load wire leads.
They should be attached in such a way that if the wires were directly connected
instead of being attached as portrayed in the blue diagram, the device would be
powered on / tripped.
Any relay is usable. Be sure to check the respective data sheet to make sure you don't fry anything.

The following code will accept a specific NFC chip's UUID (sort of like a
computer's MAC address) as a secure means of engaging the relay, in this case
acting like a motorcycle key.

The wiring shown in the diagram is that of a 2005 Harley Davidson and is not
considered a typical ignition circuit. Look up your particular brand and year
to ensure that you rewire it correctly. Don't be afraid. You have fuses, just
in case! Most models should be able to be wired up so that only one relay is
required. I am more than happy to help walk you through any problems you may
have. Just send an email to me@5h4n3.com
Motorcycles often have two different settings for starting. There is an
equivalent to "radio mode" like a car has, where the headlights aren't on, but
you can check the odometer, etc. and there is a full start mode, where you can
hit the starter button and start the bike up.
In this example, there are three pins for the ignition wires (which you should
use thick wires to interface with. The current going through them can be quite
high and will burn through thin wires). If A connects only with B, you get the
radio mode. If both of those are connected and you connect them both to C, the
bike will then think that the key has been turned to the on position and you
will be able to start the bike up.

Credits

Shane Engelman

Shane Engelman

2 projects • 4 followers
Don't call me a programmer. I just hack things together, even if I don't know what I'm doing (which is always the case)
Thanks to Lance Vick and David Sikes.

Comments