RFID Acces control project using Arduino uno, Sparkfun SM 130 ,Mifare antenna s

Hello,

I am Mohamed abdelbaky. I bought the spark fun components for Access control project using: Arduino UNO, SM130, RFID shield, transparent mifare tags and Electric door lock
I am trying to get it running but because I am new to the field. I am kind of struggling As for the lock I am using it is an electric door lock (https://www.specialized-security.co.uk/Datasheets/M-R1-ADJ.pdf)
Simply it opens when supplied by 12 VDC and close with 0 V.
As the arduino uno cannot supply this voltage so I will use an external power supply. The circuit will consist of External power supply, a Relay (Coil voltage needed 3 VDC) that shall be powered by Arduino signal.
Now I downloaded the code and i am monitoring the system through the arduino serial monitor. Intially it shows " start " then when I test the 1st tag it showes " B56C2B0" When I test the 2nd tag it showes “DE71B120”.

Here is the code i am using (UART com):
/*
RFID Eval 13.56MHz Shield example sketch v10
Aaron Weiss, aaron at sparkfun dot com
OSHW license: http://freedomdefined.org/OSHW
works with 13.56MHz MiFare 1k tags
Based on hardware v13:
D7 → RFID RX
D8 → RFID TX
D9 → XBee TX
D10 → XBee RX
Note: RFID Reset attached to D13 (aka status LED)
Note: be sure include the SoftwareSerial lib, NewSoftSerial | Arduiniana
Usage: Sketch prints ‘Start’ and waits for a tag. When a tag is in range, the shield reads the tag,
blinks the ‘Found’ LED and prints the serial number of the tag to the serial port
and the XBee port.
06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.
/
#include <SoftwareSerial.h>
SoftwareSerial rfid(7, 8);
SoftwareSerial xbee(10, 9);
//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);
//Global var
int flag = 0;
int Str1[11];
//INIT
void setup()
{
Serial.begin(9600);
Serial.println(“Start”);
// set the data rate for the SoftwareSerial ports
xbee.begin(9600);
rfid.begin(19200);
delay(10);
halt();
}
//MAIN
void loop()
{
read_serial();
}
void check_for_notag()
{
seek();
delay(10);
parse();
set_flag();
if(flag = 1){
seek();
delay(10);
parse();
}
}
void halt()
{
//Halt tag
rfid.write((uint8_t)255);
rfid.write((uint8_t)0);
rfid.write((uint8_t)1);
rfid.write((uint8_t)147);
rfid.write((uint8_t)148);
}
void parse()
{
while(rfid.available()){
if(rfid.read() == 255){
for(int i=1;i<11;i++){
Str1
= rfid.read();*
}
}
}
}
void print_serial()
{
if(flag == 1){
//print to serial port
Serial.print(Str1[8], HEX);
Serial.print(Str1[7], HEX);
Serial.print(Str1[6], HEX);
Serial.print(Str1[5], HEX);
Serial.println();
//print to XBee module
xbee.print(Str1[8], HEX);
xbee.print(Str1[7], HEX);
xbee.print(Str1[6], HEX);
xbee.print(Str1[5], HEX);
xbee.println();
delay(100);
//check_for_notag();
}
}
void read_serial()
{
seek();
delay(10);
parse();
set_flag();
print_serial();
delay(100);
}
void seek()
{
//search for RFID tag
rfid.write((uint8_t)255);
rfid.write((uint8_t)0);
rfid.write((uint8_t)1);
rfid.write((uint8_t)130);
rfid.write((uint8_t)131);
delay(10);
}
void set_flag()
{
if(Str1[2] == 6){
flag++;
}
if(Str1[2] == 2){
flag = 0;
}
}
Kindly provide me with,
1)The code Extension/Modification for Energizing the relay and lighting green LED when " B56C2B0" is detected While Lighting Red LED when “DE71B120” is detected.

2)Do I have the appility to show “names” on the serial monitor instead of Codes?
Thanks in advance for your cooperation

SoftwareSerial rfid(7, 8); SoftwareSerial xbee(10, 9);

Ah, yes, the infamous software serial on the smiley pin.

Only one instance of SoftwareSerial can be active at a time. When, in print_serial(), you make the xbee instance active, by calling a member of that instance, the rfid instance is no longer active (and no longer listening).

Almost always, when you need two instances of SoftwareSerial, you need a Mega. I see nothing here that makes you special.

Kindly provide me with,

1)The code Extension/Modification for Energizing the relay

digitalWrite(relayPin, relayState);

and lighting green LED

digitalWrite(greedLedPin, HIGH);

when " B56C2B0" is detected

That string is NOT what the RFID reader returns. The RFID reader returns 5 bytes. You need to have an array that contains those same 5 bytes, and use memcmp() to compare the read array to the known array.

2)Do I have the appility to show "names" on the serial monitor instead of Codes?

I doubt it. But, the Arduino does.

Thank you so much for your reply.

My main concern is when "B56C2B0" is detected I need have a digital output from arduino to open the door.

Your reply here is very useful "That string is NOT what the RFID reader returns. The RFID reader returns 5 bytes. You need to have an array that contains those same 5 bytes, and use memcmp() to compare the read array to the known array" But how can I found out what the reader return when it read that specific tag. and how can I implement that on the code. Can u provide me with the code modification. That would be really appreciated.

But how can I found out what the reader return when it read that specific tag. and how can I implement that on the code.

You already know that, because you printed the 5 bytes.

byte validTag[5] = {B5, 6, C, 2B, 0};
if(memcmp(validTag, readTag, 5) == 0)
{
    // The tags match
}

Of course, those might NOT be the correct values sinceyoudidnotprintspacesbetweenthebytes.

You'll need to print the good tag's values again with spaces between the bytes, so you can define validTag correctly.

Hi,

you may well have come across this already but I found this very helpful as I am working on something similar for my final year project.

http://www.jeremyblum.com/2011/07/08/tutorial-12-for-arduino-rfid-card-reading/