13.56Mhz RFID module Help

Is there any way to code this so I do not have to hit enter?
I need to print custom text for each card Id
if card = “cardId” then print “Chris”
else card = “cardId” then print “Brian” ect…

I know this is not how I would code it but it gives you an idea of what I am doing.

[code]#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);
char txrxbuffer[255];

char get_readID[] = { 0xAA , 0x00, 0x03, 0x25, 0x26, 0x00, 0x00, 0xBB };
void setup()
{
Serial.begin(57600);
Serial.println(“Hit Enter to read the RFID number”);
mySerial.begin(9600);
}

void loop() // run over and over
{

int counter = 0;
if (mySerial.available())
Serial.print(mySerial.read(),HEX);

if (Serial.available()){
Serial.read();
Serial.println(">");
for (counter =0 ; counter < 8 ; counter++){
mySerial.write(get_readID[counter]);
}
}
}
[/code]

Hi,
Here is my code , the customer_ID used Decimal number .

[code]#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);
unsigned long cardId;
char customer_name[][10]={“Deray”,“Tobe”,“Mike”,“Chris”};
unsigned long customer_ID[]={3727903***,166308***,7334255***,3854747***};
char get_readID[] = { 0xAA , 0x00, 0x03, 0x25, 0x26, 0x00, 0x00, 0xBB };

void readNumber(void)
{
cardId = 0;
char counter = 0;
for (counter = 0 ; counter < 8 ; counter++){
mySerial.write(get_readID[counter]);
}
delay(200);
//succeed to read a card ID , return 11 byte data.
if(mySerial.available() == 11){
for(counter = 0; counter < 5 ; counter++) mySerial.read();
cardId = cardId | mySerial.read(); //get byte 1 to cardId
cardId = cardId << 8;
cardId = cardId | mySerial.read(); //get byte 2 to cardId
cardId = cardId << 8;
cardId = cardId | mySerial.read(); //get byte 3 to cardId
cardId = cardId << 8;
cardId = cardId | mySerial.read(); //get byte 4 to cardId
}
mySerial.flush();
}

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}

void loop() // run over and over
{
readNumber();
int i;
for(i=0;i<2;i++)
{
if(cardId == customer_ID[i]){
Serial.print(“Customer name :”);
Serial.println(customer_name[i]);
Serial.print(“Card Number :”);
Serial.println(cardId);
}
}
delay(1000);
}[/code]

Regards,
Deray

Thanks deray

Looks good I’ll try it!

Just a fast question what does the “11” do
if(mySerial.available() == 11){

And do you know how many names and card id’s I could use? I have about 60!

And is there away I could organize them in the code for quick editing?
Thanks Chris

Hi ,Chris

if(mySerial.available() == 11)

When you send the read_id command(0xAA , 0x00, 0x03, 0x25, 0x26, 0x00, 0x00, 0xBB) to RFID module , and it succeed to read a card ID , it will return 11 byte data. So the mySerial cache is 11.

If you want to save 60 names and IDs , you have better to save them to a SD card or EEPROM.

Deray

Thanks for your help I think that I have got it!

Everything is working fine even with the 60 names! Thanks

I just dont understand the text string declaration [][10]

“char customer_name[][10]”

and the “cardId = cardId << 8;”

For “only” 60 names you could use PROGMEM to place strings in program memory instead of RAM. Watch out for wearout! Prog mem have a quite limited number of writes!

That’s basic C syntax…
customer_name is an array of ‘unknown’ (determined by initializer) length of 10-bytes strings (so every string can be at most 9 chars + trailing 0x00).
cardid = cardid <<8 (or, more briefly, cardid <<= 8) simply shifts left current cardid value by 8 bits, making space for next character.

BTW by using your 13.56MHz tags this way you have nearly no security, just like 125KHz read-only ones!

I do not need any security with this one but thanks.

I do have another queston I get this

error: invalid conversion from ‘char*’ to ‘char’

here is the code

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

char firstName = 0;

unsigned long cardId;
char customer_name[][10]={“Deray”,“Tobe”,“Mike”,“Chris”};
unsigned long customer_ID[]={3727903***,166308***,7334255***,3854747***};
char get_readID[] = { 0xAA , 0x00, 0x03, 0x25, 0x26, 0x00, 0x00, 0xBB };

void readNumber(void)
{
cardId = 0;
char counter = 0;
for (counter = 0 ; counter < 8 ; counter++){
mySerial.write(get_readID[counter]);
}
delay(200);
//succeed to read a card ID , return 11 byte data.
if(mySerial.available() == 11){
for(counter = 0; counter < 5 ; counter++) mySerial.read();
cardId = cardId | mySerial.read(); //get byte 1 to cardId
cardId = cardId << 8;
cardId = cardId | mySerial.read(); //get byte 2 to cardId
cardId = cardId << 8;
cardId = cardId | mySerial.read(); //get byte 3 to cardId
cardId = cardId << 8;
cardId = cardId | mySerial.read(); //get byte 4 to cardId
}
mySerial.flush();
}

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}

void loop() // run over and over
{
readNumber();
int i;
for(i=0;i<2;i++)
{
if(cardId == customer_ID[i]){
Serial.print(“Customer name :”);
Serial.println(customer_name[i]);
Serial.print(“Card Number :”);
Serial.println(cardId);
firstName = customer_name[i];
}
}
delay(1000);
}

I am trying to assign the customer_name to a variable so that I can use that variable in a if statement
also why should I use a sd card, EEPROM or ram?

Thanks for everyones help!

If only one byte lost you never will get the right 11 bytes.
Check first the startbyte of the datapackage (0xAA) and then read 10 bytes.

You should really study C a bit (or at least read a good book at least once), before shooting yourself in the foot. That’s a really basic question.

Use:
const char* customer_name[]={“Deray”,“Tobe”,“Mike”,“Chris”};
that (simplifying) means that customer_name is an array of constant strings.
But the whole array contents gets copied to RAM at startup…
Once you’ve read about C basics, look for PROGMEM directive in Arduino. This will let you avoid wasting precious RAM by placing those constant strings in program memory.

Thanks and your right!

I have read a book but its been so long since I have had to do anything in C!

I guess i should go over things again!