miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.75k stars 1.43k forks source link

if statements are not working second time rfids are not read #509

Closed ghost closed 4 years ago

ghost commented 4 years ago

Step 1: Describe your environment

Step 2: Describe the problem

Affected file(s) or example(s):

Steps to reproduce:




Observed Results:

Expected Results:

Relevant Code:

  // TODO(you): code here to reproduce the problem
ghost commented 4 years ago

Can anyone tell me whats wrong in it. The rfid codes inside if conditions are not working. Other code is right.

include

include

define SS_PIN 10

define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);
String studentArray[]={"B1 3C CB 20","81 1B 00 1B"}; String bookArray[]={"09 6E 99 6E","86 12 C3 F7"};

void setup() { Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Approximate your card to the reader..."); Serial.println(); }

void loop() { if ( ! mfrc522.PICC_IsNewCardPresent()) {return;} if ( ! mfrc522.PICC_ReadCardSerial()) {return;} Serial.print("UID tag :"); String content0=""; byte letter0; for (byte e= 0; e < mfrc522.uid.size; e++) {Serial.print(mfrc522.uid.uidByte[e] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[e], HEX); content0.concat(String(mfrc522.uid.uidByte[e] < 0x10 ? " 0" : " ")); content0.concat(String(mfrc522.uid.uidByte[e], HEX));} Serial.println(); content0.toUpperCase(); int j=0; for(j=0;2>j;j++) {if(studentArray[j]==content0.substring(1)) {Serial.println("Authorized access"); Serial.println("Give 1 to issue book"); Serial.println("Give 2 to return book"); Serial.println("Give 3 to check availability of book"); delay(1000);} int q; q =Serial.read(); if(q==51) {int a =0; for (a=0;2>a;a++) {if (bookArray[a]==content0.substring(1)) {Serial.println("Book Avaialable!!!");} else{Serial.println("Soory,book not available");}}}

if(q==50)
{Serial.print("scan tag of book you want to return"); if ( ! mfrc522.PICC_IsNewCardPresent()) {return;} if ( ! mfrc522.PICC_ReadCardSerial()) {return;} Serial.print("UID tag :"); String content1=""; byte letter1; for (byte z = 0; z < mfrc522.uid.size; z++) {Serial.print(mfrc522.uid.uidByte[z] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[z], HEX); content1.concat(String(mfrc522.uid.uidByte[z] < 0x10 ? " 0" : " ")); content1.concat(String(mfrc522.uid.uidByte[z], HEX));} Serial.println(); content1.toUpperCase(); if(content1.substring(1) == "09 6E 99 6E" ) {bookArray[0]="09 6E 99 6E"; Serial.println("Book Returned!!!");} if(content1.substring(1) == "86 12 C3 F7" ) {bookArray[0]="86 12 C3 F7"; Serial.println("Book Returned!!!");}}

if(q==49) {Serial.print("scan tag of book you want to issue"); if ( ! mfrc522.PICC_IsNewCardPresent()) {return;} Serial.println("_ll"); if ( ! mfrc522.PICC_ReadCardSerial()) {return;} Serial.println("fu"); Serial.print("UID tag :"); String contentu=""; byte letteru; for (byte p= 0; p < mfrc522.uid.size; p++) {Serial.print(mfrc522.uid.uidByte[p] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[p], HEX); content0.concat(String(mfrc522.uid.uidByte[p] < 0x10 ? " 0" : " ")); contentu.concat(String(mfrc522.uid.uidByte[p], HEX));} Serial.println(); contentu.toUpperCase(); Serial.print("hi"); if ((contentu.substring(1)) == ("09 6E 99 6E")) {Serial.println("Book1 issued!!!"); delay(3000);} else if ((contentu.substring(1)) == ("86 12 C3 F7")) {Serial.println("Book2 issued!!!"); delay(3000);} else {Serial.println("zyxv");} } else {Serial.println("Access Denied!!!"); delay(3000);}} }