Go Down

Topic: HELP ME IN FIXING THIS I NEED TO ACCESS MY RFID CARD ONLY 2 TIMES (Read 375 times) previous topic - next topic

tarun1999

HI EVERYONE
I NEED A CODE THAT HELPS ME OUT IN FIXING MY PROBLEM THAT I NEED TO ACCESS MY RFID CARD ONLY A SPECIFIED TIMES FOR EXAMPLE I NEED TO USE THE RFID CARD ONLY 2 TIMES IF I TRY TO USE THE RFID CARD 3 TIMES I NEED TO GET THE ACCESS IS DENIED PRESENTLY I M USING THIS CODE





#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);   
void setup()
{
  Serial.begin(9600);   
  SPI.begin();     
  mfrc522.PCD_Init();   
  Serial.println("Approximate your card to the reader...");
  Serial.println();
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);
digitalWrite(7,LOW);
digitalWrite(6, LOW);
}
void loop()
{
  String content= "";
 
 
  // Scan for cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Selects a card
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  //show UID on serial monitor
  Serial.print("UID tag :");

  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
     Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte, HEX);
     content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte, HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();

  if (((content.substring(1) == "") || (content.substring(1) == "") ) || (content.substring(1) == "E2 E2 4B 2E") )//change the codes with the cards codes found after scanning in serial monitor
  {
 
   
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite (7,HIGH);
    delay(1000);
    digitalWrite (7,LOW);
    delay(1000);
  }
   else   {
    Serial.println(" Access denied");
    digitalWrite (6,HIGH);
    delay(4000);
    digitalWrite (6, LOW);
        delay(3000);
  }
}

gfvalvo

IT LOOKS LIKE YOUR CAPS LOCK KEY IS STUCK. ----- Fix that first.

Then, go to: https://forum.arduino.cc/index.php?topic=97455.0 Read this before posting a programming question ... and see Item #6 which will tell you how to properly post your code using Code Tags.

PaulS

If you want to do something the first time an event occurs, and the same thing the second time an event occurs, but you want to do something different the third (and subsequent?) time(s) an event occurs, doesn't it seem obvious that you must count the number of times the event occurs?
The art of getting good answers lies in asking good questions.

Slumpert

So if the card has already been scanned 2x, do something else.

Do you plan to reset the counter?

Does your project need to remember which cards have already been used 2 times even if it's unplugged and then turned back on?

Basically your going to need to define a couple of arrays, store the scanned card ID,  and maybe learn how to write to eeprom


tarun1999

yes my project need to remember which cards have been read 2 times even its is unplugged if the card reads 3rd time the card should  be unaccessiable



thanks

Slumpert

I would install a SD reader
Each time a RFID card was read,
Check SD card to see if your data file exists, if not create it.
Then loop through file looking for the captured RFID, count each time it's found
If count equals two close file, goto reject loop
Once at EOF, write RFID, close file

It doesn't need to be more complicated than that except decide what to do if the SD fails.


PaulS

Quote
yes my project need to remember which cards have been read 2 times even its is unplugged
Then you need to define some sort of scheme to store data in EEPROM, when a card is scanned, and read that data in setup().

Quote
if the card reads 3rd time the card should  be unaccessiable
Piece of cake.

What HAVE you tried?

Why the hell can't you use some punctuation and proper capital letters? I am tired of trying to decipher the mess that you type.
The art of getting good answers lies in asking good questions.

tarun1999

Thank you for your reply sir.
sorry sir i cant get you as if i new to coding.
 sorry for my improper punctuation and in order  capital letters.

PaulS

You must have some code for reading the RFID cards. Post that code.

In order to make ANY progress, you must have some code for deciding which known card you have just scanned. How do you do that?
The art of getting good answers lies in asking good questions.

tarun1999

Sir this is the code which i m  using.
In this is code i had configured the rfid card numbers . If the scanned card numbers are same as the numbers which i have been configured it turn on  an led  which i have set it for  1 sec and if not for 3 seconds.
Now my issue was that the configured cards  should be read only 1 time or  specified times. when the ARDUINO is on.when i turn it on again ARDUINO should be able to read only one time.
I think i m clear to explain my problem or issue
sorry for spell check and grammatical errors


Code: [Select]

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);   
void setup()
{
  Serial.begin(9600);   
  SPI.begin();     
  mfrc522.PCD_Init();   
  Serial.println("Approximate your card to the reader...");
  Serial.println();
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);
digitalWrite(7,LOW);
digitalWrite(6, LOW);
}
void loop()
{
  String content= "";
 
 
  // Scan for cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Selects a card
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  //show UID on serial monitor
  Serial.print("UID tag :");

  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
     Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte, HEX);
     content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte, HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();

  if (((content.substring(1) == "") || (content.substring(1) == "") ) || (content.substring(1) == "E2 E2 4B 2E") )//change the codes with the cards codes found after scanning in serial monitor
  {
 
   
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite (7,HIGH);
    delay(1000);
    digitalWrite (7,LOW);
    delay(1000);
  }
   else   {
    Serial.println(" Access denied");
    digitalWrite (6,HIGH);
    delay(4000);
    digitalWrite (6, LOW);
        delay(3000);
  }

PaulS

Code: [Select]
  if (((content.substring(1) == "") || (content.substring(1) == "") ) || (content.substring(1) == "E2 E2 4B 2E") )//change the codes with the cards codes found after scanning in serial monitor
STOP putting long, useless f**king comments after long statements. The compiler doesn't cvar about white space, but people do. That code would be MUCH more readable as
Code: [Select]
  if (((content.substring(1) == "") || (content.substring(1) == "") )
     || (content.substring(1) == "E2 E2 4B 2E") )


Now, you can see that the first condition (involving the substring starting at position 1) says "if the string is empty or the string is empty". Now, why on earth do you need to test that twice?

You will never achieve your goal, so you might as well quit now, unless you are willing to expend the effort needed.

Your code knows about ONE hardcoded tag, in the poorest possible way (as a stupid String).

You never count the number of times that one card is scanned.

You do not make the behavior of the program change based on the number of times any card is scanned.

You started from the absolutely poorest example code ever written.

Trash that code, and start again.

Create an array to hold the scanned tag data. That will be a 2D array of bytes.

Do something if any function involved returns true, rather than giving up if any function returns false.

When a tag that you haven't recorded is scanned, record that tag, and set the count of times you've seen that tag to 1.

Post the code that does that, AFTER using Tools + Auto Format, since you are too lazy to properly indent the code as you go.

Then, we can help you understand what else you need to do.
The art of getting good answers lies in asking good questions.

Go Up