Add the RFID Reader to Your Keypad Entry System

Both the keypad entry system and the RFID reader are connected to a relay that closes the circuit to whatever is attached. For example, it might be attached to an electronic door strike. But what if you wanted to integrate both systems so that you could unlock your door with either a secret code or RFID tag? It’s surprisingly easy to do!

The diagram shows how you connect the two projects. You can see that the RFID reader is connected to the same power 5V power supply rail as the keypad and display components. The indicator LED and the relay from the breadboard for the RFID reader project have been removed.

Change your wiring

The only wiring you need to change is to connect the RFID reader’s reset pin to Arduino Digital Pin 12. You can't connect it to Pin 13, because that pin is used by the LED Display IC of the keypad entry system. When you add your RFID reader to the keypad entry system, connect the ID Solutions RFID reader’s reset pin to Arduino Pin 12.

image0.jpg

Change your code

In your code, you need to merge the two sketches together. It’s pretty easy to do because your code is modular. Start with your Keypad Entry System sketch, which contains most of the code you’ll need and save it as a new sketch. Then open your RFID reader sketch. You need to copy key lines from it to your new sketch:

  1. Copy the variable declaration for your RFID reader’s reset pin to the variable declaration section at the top of your new sketch, changing the pin number from 13 to 12:

    const int RFIDResetPin = 12;
  2. Copy the ID values from your RFID tags to the variables section of the new sketch. If you want to use more tags you will need to scan them to obtain their unique numbers and add them to this section of the code:

    char tag1[13] = "4B00DDBF9FB6";// Your scanned tag ID goes here
    char tag2[13] = "010203AABBCC";// these are example Tag IDs only
    char tag3[13] = "010203AABBDD";// these are example Tag IDs only
  3. Copy the RFID reader pin setup instructions into the setup() section of the new sketch:

    pinMode(RFIDResetPin, OUTPUT);// Tells the reader to start again
    digitalWrite(RFIDResetPin, HIGH); // Make it ready to read
    Serial.println("Ready");
  4. Add the code that operates your RFID reader to the end of the loop() section of your new sketch, after the code for reading the keypad:

    Serial.println("Looking for a tag");
    char tagString[13];
    int index = 0;
    boolean reading = false;
    while(Serial.available()){  
    int readByte = Serial.read();
    if(readByte == 2) reading = true
    if(readByte == 3) reading = false; 
    if(reading && readByte != 2 && readByte != 10 && readByte != 13){
          tagString[index] = readByte;  
          index ++;
        }
    }
    checkTag(tagString); // Check if it is a match  clearTag(tagString); //
               Clear the char array of all values  resetReader();       //
               Reset the RFID reader
  5. Don’t forget to make sure the closing curly bracket is at the bottom of the loop() section.

  6. Copy the checkTag(), compareTag(), and resetReader() functions from the RFID reader code to the end of your new sketch.

  7. Don’t copy the lightLED() triggerRelay() functions, because they aren’t needed in the new code.

  8. Change the code in the compareTag() function so that it triggers the unlock() function instead:

  if(compareTag(tag, tag1)){   
    unlock();
  }
  else if(compareTag(tag, tag2)){ 
    unlock();
  }
  else if(compareTag(tag, tag3)){ 
    unlock();
} else {
    Serial.println("New tag found: "); 
    Serial.println(tag 
    delay(5000
  }

Remember to create if. . .then. . .else tests for each of the RFID cards you want to use and to create variable for the tag ID number in the variable declaration section.

You don’t need the last lines that print a tag number to the serial port, once you disconnect the project from your computer and install it into the enclosure, but it is handy while you are testing.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.