RFID DOOR LOCK with DATA LOGGING

Hi guys,

Im trying to develop a code for a RFID DOOR LOCK with data logging.
Hope you can help me out.
This is one of my undergrad projects and I'm totally new to arduino.
I'll close my old topic since I decided to start the code from scratch..

This is the flow chart:

Btw, the RFID reader sends data in format like this
0x41 0x7d 0xff 0xdc 0xe8 0xe7 0x1b 0x87 0xfb 0x42

Thanks for those who will help. I'll owe you guys a lot if I am able to finish this project.

Why you don't log also if access is granted or denied ?

Because now You can't know with the log if the door opened or not :wink:

Thanks nice idea..
forgot that one :smiley:

I tried to read the data the RFID tag sends,
and got a reading like this

I received: 255
I received: 145
I received: 218
I received: 185
I received: 252
I received: 23
I received: 248
I received: 66

can anyone teach me how to compare this string to valid ones..

I'm having a hard time comparing array of strings

int incomingByte = 0;
char code[12];
char tag[12] = {'41', '84', 'FF', '91', 'D5', 'C0', 'D', 'E7', 'F8','42'};
#define PowPin 11
#define NoPin 12
#define YesPin 13

void setup()
{
Serial.begin(9600);
pinMode(PowPin,OUTPUT);
digitalWrite(PowPin,HIGH);
pinMode(NoPin,OUTPUT);
pinMode(YesPin,OUTPUT);
}

void loop()
{

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

code[12] = (incomingByte, HEX);
if (strcmp(code,tag)==0)
{
Serial.println("GOOD");
}
else
{

Serial.println("BAD");
}
}
}

I tried this code i made and it doesn't recognize the valid tag..

Thanks in advance for your help.

bump

code[12] = (incomingByte, HEX);

What are you trying to do here?
(apart from writing off the end of the 12 byte buffer "code")

Before you use "strcmp", you need to form the bytes you have read into a properly null-terminnated string.
Have a look at the tutorials or here on the forum on how to do that.

first :
char tag[12] = {0x41, 0x84, 0xFF, 0x91, 0xD5, 0xC0, 0x0D, 0xE7, 0xF8 , 0X42};

that said:

You have made such a good flowchart. Why is your code not following it? You need to define quite some functions but this chops the problem in small parts which are much easier to solve.

...

void loop()
{
   showLED(GREEN);  // new function to be defined
   
   code = readRFID();  
   log(time, code);

   if ( compare(code, password) == true) 
  { 
     showLED(RED); 
     Serial.println("Acces Denied");
  } else {
     showLED(YELLOW);
     Serial.println("TAG Accepted");
     unlockServo(SERVO);
  }
}

Thanks Guys..

I did some reading and ended up with this code..

I used some of the codes used in the old forums..

unfortunately it won't work

the PowerLED won't even light up..

here's the code:

the logging mechanism was not yet included.

int val = 0;
char code[12];
int bytesread = 0;
char tagArray[12]; // the array for the tags
char Valid1[12] = {
'0x41', '0x84', '0xFF', '0x91', '0xDA', '0xB9', '0xFC', '0x17', '0xF8', '0x42'};
char Valid2[12] = {
'0x41', '0x84', '0xFF', '0x91', '0xD5', '0xC0', '0xD', '0xE7', '0xF8', '0x42'};
#define PowPin 11
#define NoPin 12
#define YesPin 13

void setup() {

Serial.begin(9600); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
digitalWrite(PowPin,HIGH);
}

void loop() {

if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}

if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
{
if(strcmp(code,Valid1) == 0) {
Serial.println("Gwapo, you're in");
digitalWrite(YesPin,HIGH);
}
if(strcmp(code,Valid2) == 0) {
Serial.println("Pogi, you're in.");
digitalWrite(YesPin,HIGH);
}

if((strcmp(code,Valid1) !=0) && (strcmp(code,Valid2) != 0)) {
Serial.println("Invalid Tag");
digitalWrite(NoPin,HIGH);
Serial.println(code);
{

}
}
}
}

bytesread = 0;
delay(1000); // wait for a second
}
}
}

char Valid1[12] = {
  '0x41', '0x84', '0xFF', '0x91', '0xDA', '0xB9', '0xFC', '0x17', '0xF8', '0x42'};
char Valid2[12] = {
  '0x41', '0x84', '0xFF', '0x91', '0xD5', '0xC0', '0xD', '0xE7', '0xF8', '0x42'};

That's already been pointed out to be incorrect.

the PowerLED won't even light up..

I'd solve that one first.

The code you posted doesn't explicitly terminate the incoming string - that needs to be done before you call strcmp.

I was able to Light it up now, just minor problems the ground not properly connected to the breadboard..

whats wrong with that one sir?
thanks sorry for being such a newb.

Have a close look at the start of reply #7.

sorry wasn't able to read that properly

can i just add a '/0' to the array?
i read it was the null ascii char

The string termination is done for you as a by-product of having the array over-sized, but it is a good idea to get into the habit of doing yourself.
But fix those hex values.

T_T

i am really having a problem with those hex values

I used this code to know what data the RFID reader is reading from the tag..

int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, HEX);
}
}

I know it was a Ascii coded Hex code shown in the serial monitor..
I am wondering why other RFID tags in the forum s do have 10 digit codes only

i am really having a problem with those hex values

Sorry. Madame Trussant and her crystal ball have left the forum. If you still, need help, you have to explain what the problem is.

I used this code to know what data the RFID reader is reading from the tag..

I guess the results are a secret.

Please stop posting code using the Quote button. Post is using the Code button (the one with the # on it).

hi sir Paul

thanks, Ive read some of your replies in the old forum
in similar topics

Sorry I wasn't able to see the code button.

Anyway..

I have this reading
using this code

int incomingByte = 0;	// for incoming serial data

void setup() {
	Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps
}

void loop() {

	// send data only when you receive data:
	if (Serial.available() > 0) {
		// read the incoming byte:
		incomingByte = Serial.read();

		// say what you got:
		Serial.print("I received: ");
		Serial.println(incomingByte, HEX);
	}
}

I received:41
I received:84
I received:FF
I received:91
I received:DA
I received:B9
I received:FC
I received:17
I received:F8
I received:42

As I said I was wondering why the RFID tag codes in the similar topics are using digits like '0DF1244278'

Thanks

You have a serial port that can have one device on each end. You have an Arduino on one and and the PC on the other.

Are you using the serial port on the Arduino to talk to the RFID reader or to talk to the PC? The correct answer is NOT yes.

T_T

Unfortunately I did that..

I used the tx rx of arduino

but by using the program above I was able to get bytes from the RFID reader..

I just had to remove the tx rx connection when uploading sketches..

was the Ascii coded hex the correct tag data?
if not how will I know the correct data?

Thanks sir paul

char tag[12] = {0x41, 0x84, 0xFF, 0x91, 0xD5, 0xC0, 0x0D, 0xE7, 0xF8 , 0X42};

I received:41
I received:84
I received:FF
I received:91
I received:DA
I received:B9
I received:FC
I received:17
I received:F8
I received:42

So, you're receiving the code correctly, what seems to be the problem?