Pages: [1]   Go Down
Author Topic: Wireless RFID reader  (Read 674 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

I've been wanting to create a wireless RFID reader but I'm at a loss when it comes to modifying the code to make it work. I have set up a Uno with a ID-20 RFID reader and it works great. What I want to do is transmit the RFID tag reader info to another Arduino using series 1 XBee radios so it can perform identical functions (control the two output pins) when tags are read. I've used XBee radios before and I have them set up properly to transmit/receive- there's no problem there. Is this possible? I'm sure it's just something really simple I'm missing... Any help would be greatly appreciated- thanks!

Here's the RIFD tag reader code-
Code:
/**
* RFID Access Control
*Transmit
*
* Some of this code was inspired by Tom Igoe's excellent RFID tutorial
* which is detailed on his blog at:
* http://www.tigoe.net/pcomp/code/category/PHP/347
* And also from the ID-12 example code on the Arduino Playground at:
* http://www.arduino.cc/playground/Code/ID12
*
* Code modified from code by Jonathan Oxer <jon@oxer.com.au>
* http://www.practicalarduino.com/projects/medium/rfid-access-control
*/

// Set up the serial connection to the RFID reader module. In order to
// keep the Arduino TX and RX pins free for communication with a host,
// the sketch uses the SoftwareSerial library to implement serial
// communications on other pins.
#include <SoftwareSerial.h>

// The RFID module's TX pin needs to be connected to the Arduino. Module
// RX doesn't need to be connected to anything since we won't send
// commands to it, but SoftwareSerial requires us to define a pin for
// TX anyway so you can either connect module RX to Arduino TX or just
// leave them disconnected.


// Use pins D6 / D7 for rx/tx:
#define rxPin 6
#define txPin 7


// Create a software serial object for the connection to the RFID module
SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );

// Set up outputs for the control pin and status LEDs.
// use pins D8 and D9:
#define controlPinA 8
#define ledPin 9


// Specify how long the control pin should be turned on.
#define activateSeconds 2

// The tag database consists of two parts. The first part is an array of
// tag values with each tag taking up 5 bytes. The second is a list of
// names with one name for each tag (ie: group of 5 bytes).
char* allowedTags[] = {
  "440085E774", // Tag 1
  "440085FC33", // Tag 2
  "440085F978", // Tag 3
  "4400863914", // Tag 4
};

// List of names to associate with the matching tag IDs
char* tagName[] = {
  "T1", // Tag 1
  "T2", // Tag 2
  "T3", // Tag 3
  "T4", // Tag 4
};

// Check the number of tags defined
int numberOfTags = sizeof(allowedTags)/sizeof(allowedTags[0]);

int incomingByte = 0; // To store incoming serial data

/**
* Setup
*/
void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(controlPinA, OUTPUT);
  digitalWrite(controlPinA, LOW);

  Serial.begin(9600); // Serial port for connection to host
  rfid.begin(9600); // Serial port for connection to RFID module

  Serial.println("RFID reader starting up");
}

/**
* Loop
*/
void loop() {
  byte i = 0;
  byte val = 0;
  byte checksum = 0;
  byte bytesRead = 0;
  byte tempByte = 0;
  byte tagBytes[6]; // "Unique" tags are only 5 bytes but we need an extra byte for the checksum
  char tagValue[10];

  // Read from the RFID module. Because this connection uses SoftwareSerial
  // there is no equivalent to the Serial.available() function, so at this
  // point the program blocks while waiting for a value from the module
  if((val = rfid.read()) == 2) { // Check for header
    bytesRead = 0;
    while (bytesRead < 12) { // Read 10 digit code + 2 digit checksum
      val = rfid.read();

      // Append the first 10 bytes (0 to 9) to the raw tag value
      if (bytesRead < 10)
      {
        tagValue[bytesRead] = val;
      }

      // Check if this is a header or stop byte before the 10 digit reading is complete
      if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) {
        break; // Stop reading
      }

      // Ascii/Hex conversion:
      if ((val >= '0') && (val <= '9')) {
        val = val - '0';
      }
      else if ((val >= 'A') && (val <= 'F')) {
        val = 10 + val - 'A';
      }

      // Every two hex-digits, add a byte to the code:
      if (bytesRead & 1 == 1) {
        // Make space for this hex-digit by shifting the previous digit 4 bits to the left
        tagBytes[bytesRead >> 1] = (val | (tempByte << 4));

        if (bytesRead >> 1 != 5) { // If we're at the checksum byte,
          checksum ^= tagBytes[bytesRead >> 1]; // Calculate the checksum... (XOR)
        };
      } else {
        tempByte = val; // Store the first hex digit first
      };

      bytesRead++; // Ready to read next digit
    }

    // Send the result to the host connected via USB
    if (bytesRead == 12) { // 12 digit read is complete
      tagValue[10] = '\0'; // Null-terminate the string

      Serial.print("Tag read: ");
      for (i=0; i<5; i++) {
        // Add a leading 0 to pad out values below 16
        if (tagBytes[i] < 16) {
          Serial.print("0");
        }
        Serial.print(tagBytes[i], HEX);
      }
      Serial.println();

      Serial.print("Checksum: ");
      Serial.print(tagBytes[5], HEX);
      Serial.println(tagBytes[5] == checksum ? " -- passed." : " -- error.");

      // Show the raw tag value
      //Serial.print("VALUE: ");
      //Serial.println(tagValue);

      // Search the tag database for this particular tag
      int tagId = findTag( tagValue );

      // Only activate controlPinA if this tag was found in the database
      if( tagId > 0 )
      {
        Serial.print("Authorized tag ID ");
        Serial.print(tagId);
        Serial.print(": activating for ");
        Serial.println(tagName[tagId - 1]); // Get the name for this tag from the database
        activate(); // activate controlPinA
      } else {
        Serial.println("Tag not authorized");
      }
      Serial.println(); // Blank separator line in output
    }

    bytesRead = 0;
  }
}

/**
* Activate the control pin for the configured
* number of seconds.
*/
void activate() {
  digitalWrite(ledPin, HIGH);
  digitalWrite(controlPinA, HIGH);
  delay(activateSeconds * 1000);
  digitalWrite(controlPinA, LOW);
  digitalWrite(ledPin, LOW);
}

/**
* Search for a specific tag in the database
*/
int findTag( char tagValue[10] ) {
  for (int thisCard = 0; thisCard < numberOfTags; thisCard++) {
    // Check if the tag value matches this row in the tag database
    if(strcmp(tagValue, allowedTags[thisCard]) == 0)
    {
      // The row in the database starts at 0, so add 1 to the result so
      // that the card ID starts from 1 instead (0 represents "no match")
      return(thisCard + 1);
    }
  }
  // If we don't find the tag return a tag ID of 0 to show there was no match
  return(0);
}

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is this possible?
Of course it is.

Quote
I'm sure it's just something really simple I'm missing
Yes, it is. You missed telling us what the problem is.

That code does something. You expect it to do something. Clearly, those two somethings are not the same thing. What either of them is is a mystery, though. As is the code running on the other Arduino and how you have stuff connected to the Arduino(s).
Logged

Dallas, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Check out my blog on your smartphone!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It doesnt look as if there is any code that sends information out using the Xbee.... That is what im guessing is wrong.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nevermind- I figured it out. Must have had my brain turned off...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nevermind- I figured it out. Must have had my brain turned off...

hi

can you share the full source code and how is the connection being made, anyway I've Pm'ed you

thanks!
Logged

Pages: [1]   Go Up
Jump to: