whats wrong in my code ( RFID READING)

i just want to make simple locking system
where it reads the rfid data and then uses the switch case but i getting some errors like diferent characters

i just want it to make soo simple that it just reads the cards and checks in the switch case

#include <SoftwareSerial.h>
SoftwareSerial id20(2,3); // virtual serial port
char i;
char a;
void setup() 
{
 Serial.begin(9600);
 id20.begin(9600);
}
void loop () 
{
 if(id20.available()>0) {
for (int j =0 ;j<13 ;j++){

 i = id20.read(); // receive character from ID20
 a += i;
}
 Serial.print(a); // send character to serial monitor
 
switch(a){
  case '0800692B5D17' :
   Serial.println("good");
  break;
  case '0800695E605F' :
   Serial.println("bad");
  break;
  case '08006940F9D8' :
   Serial.println("good");
  break;
  case '080068DF853A' :
   Serial.println("bad");
  break;
  case '080069625F5C' :
  Serial.println("good");
  break;
 
 default :
 Serial.println(" acess denied ");
 break;
 
}
 }
}

any help for updating the code

 if(id20.available()>0) {
for (int j =0 ;j<13 ;j++){

 i = id20.read(); // receive character from ID20
 a += i;
}

If there is at least one byte available to read, read all 13 of them. Fail!

  case '0800692B5D17' :

Can you tell me which ONE key you pressed to get the character in the single quotes?

If not, perhaps you need to think about using strcmp() to compare something other than ONE character (or the == operator in the String class).

iam running out my mind now ,cannot concentrate on programming just searching for a best code to directly implement it in my project =(

 a += i;

Is this meant to concatenate the character from id20.read(); onto the existing char variable a ? Try printing a on the next line to see whether it works or not.

saiganesh_panchu:
iam running out my mind now ,cannot concentrate on programming just searching for a best code to directly implement it in my project =(

So you don't want to actually write the code, you just want to load code and have it work? Perhaps the Gigs and Collaboration section would be a better fit for your post.

If that's not the case, then I would start simple and print out the HEX of any received character to determine what, exactly, is being sent:

if (Serial.available() > 0)
{
  Serial.print(Serial.read(), HEX);
  Serial.print(' ');
}

That way, you can look for any start/stop bytes that will help you better parse the incoming data.

finally updated my code but still there is a problem

it reading and comparing my rfid card , but reads only one cards , and stops reading again until if i reset the board

but the led works fine stays on 2000ms and turns off

#include <SoftwareSerial.h>
#define CODE_LENGTH (12)
SoftwareSerial rfid(2, 3);
char command[CODE_LENGTH];
char panchu[] = "6B0037E8398D";
int ledpin = 13;

void setup()  
{
  Serial.begin(9600);
  Serial.println("rfid read begin");

  // set the data rate for the SoftwareSerial port
  rfid.begin(9600);
  pinMode(ledpin,OUTPUT);
  
}

void loop() // run over and over
{
  if (rfid.available() > 0)   
  { 
     delay(035);
    for (int i=0; i < CODE_LENGTH; i++) 
    { 
     command[i] = rfid.read(); 
         
    } 
   command[CODE_LENGTH]=0;
     Serial.print("Information Read: ");
    Serial.println(command);
    if (strcmp(command, panchu)  == 0)  // test to see if the two strings are equal
    { 
        
       
       Serial.print("sucessfull read and comparssion ");
       digitalWrite(ledpin,HIGH);
       delay(2000);
    } 
    
   
  }
 digitalWrite(ledpin,LOW);
 
}
  if (rfid.available() > 0)   
  { 
     delay(035);
    for (int i=0; i < CODE_LENGTH; i++) 
    { 
     command[i] = rfid.read(); 
         
    }

The delay() is the wrong solution. It makes it more likely that the required data will have arrived before you try to read it, but it does not ASSURE that it has. If you know that the tag consists of 12 characters, wait for 12 before reading.

Where did you come up with 29 as the delay time?

   command[CODE_LENGTH]=0;

You just wrote beyond the end of the array. Any future execution of code is at risk.

PaulS:

   command[CODE_LENGTH]=0;

You just wrote beyond the end of the array. Any future execution of code is at risk.

any suggestions about what can be done to make the reader read continuously
i even removed the delay

i still find it troubling even tried many arduino codes for implementing my door lock

any suggestions about what can be done to make the reader read continuously

Assuming this is actually a clone of the ID series, then did you try moving the tag away from the reader and then moving it closer? Those devices only send it once when it moves into range. There is usually a reset pin on these devices that you can drive if you want it to keep sending while it is in range at a specific interval.

i still find it troubling even tried many arduino codes for implementing my door lock

It's hard to help when you spend more time talking about how you've tried many "codes" and don't follow directions or answer questions from people trying to help.

Arrch:
Assuming this is actually a clone of the ID series, then did you try moving the tag away from the reader and then moving it closer? Those devices only send it once when it moves into range. There is usually a reset pin on these devices that you can drive if you want it to keep sending while it is in range at a specific interval.

oh I am really sorry ...

The rfid reader actually works fine ie it sends the data only once when the rfid tag is in proximity to the reader , and re-sends the same data when again brought into proximity

the only thing with the reader is that i don't whether it sends the start bite 0x02 and stop byte 0x03 while reading the card , it doesn't have any data sheet

the only thing with the reader is that i don't whether it sends the start bite 0x02 and stop byte 0x03 while reading the card , it doesn't have any data sheet

You need a datasheet to ALLOW you to write code that prints EVERY character received in HEX mode? I don't!

(deleted)