How to check if a RFID card is always touching

Hi, I need to create a device which assures the card is always in place, when removed I need to cut the electricity of a room, this is like the hotel rooms.
As I see the RFID modules uses interrupts to notify arduino a new card is detected, but do these modules allow continous reading? Maybe once every 2 seconds, for example.
Probably the problem is on the card itself, it sends for some time its code in the beginning, that doesn't until it's powered off and reactivated (by proximity), so in this case I have to power off the module and activate it again, but the boot time is enough to let the process sucessful?
Reading datasheets there is a soft reset by SPI command, will it do the job? The rfid library hasn't a ready example for it unfortunately.

Thank you a lot for answering

have you checked the MFRC522 library? (if you are using compatible cards)

Hotel rooms just have a mechanical switch that is opened/closed by inserting the card - could you not do that?

That would be an active card.
The ones commonly used with door locks, hotel rooms, etc are usually passive: they only respond to queries from the reader - they don't actively transmit anything at all.

What modules, exactly? It would depend on the module.

Have you taken a look at their documentation, and/or the documentation of associated libraries?

Hi, thanks for answer, yes I'm sure they have just a switch, you're right

Are you sure the request come from the reader? I'm a newbie here but I don't beleive so, the reader keep running the oscillator to power the card and expecting to receive a transmission from the card, then it starts to communicate, request, etc. But the first step is made by the card, when the card will do it again?
When active, the card is always working? will always be ready to answer the reader? Or after sending the first communication it places itself on st-by mode, expectiong another power on?

Yes I read the MFRC522 library and I can't find soft power off in it, the processor supports it

Again, it depends on what type of card you have - you still haven't said!

By definition, a passive card cannot transmit of its own accord - it can only respond to a "read".

A passive card doesn't actually transmit at all - it effectively "loads" the reader's reading coil, and the reader detects that: Radio-frequency identification - Wikipedia

Not if it's a passive card.

As the name suggests, a passive card has no built-in power source - it is powered entirely by the energy from the reader.

https://en.wikipedia.org/wiki/Radio-frequency_identification#:~:text=Passive%20tags%20are%20powered%20by%20energy%20from%20the%20RFID%20reader's%20interrogating%20radio%20waves

Thanks, I didn't know there are different types, the card or dongles I?m going to use are the typical ones, really cheap, can cost 0,20$ each, they have no internal power source, so I suppose they are passive. Ok you teached me the reader can understand whan a nearby card loads its oscillator, then it will transmit something and the card answer. As the card is really simple, no security at all, it will transmit its code, for me this is ok.
Now how can I permanentely check if the card is near? I'm not going to use the "credit card shape" card, I?m going to use dongles, much more handly and resistent, and there isn't a box for them with an internal switch, so I need to polling them, maybe every 5 seconds, do you know if there is any way to stp oscillator and enable it with this library?
Also, interesting, maybe these cards aren't made to be active (or turned on) that much, can it affect their reliability?
Thanks for info

If you are using these common MFRC522 type readers, test this code.
Place an LED on pin 5.
With the tag in place the LED lights up, without the tag the LED turns off.

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define LED 5
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
byte nuidPICC[4];   // Init array that will store new NUID
//------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
  SPI.begin(); // Init SPI bus
  rfid.PCD_Init(); // Init MFRC522
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
  Serial.println(F("Start."));
}
//------------------------------------------------------------
void loop() {
  if ( ! rfid.PICC_IsNewCardPresent()) {
    // Serial.println(F("Card out, turn light OFF."));
    digitalWrite(LED, LOW);
    return;
  }
  if ( ! rfid.PICC_ReadCardSerial())// Verify if the NUID has been readed
    return;
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&       // Check is the PICC of Classic MIFARE type
      piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
      piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }
  if (rfid.uid.uidByte[0] != nuidPICC[0] ||
      rfid.uid.uidByte[1] != nuidPICC[1] ||
      rfid.uid.uidByte[2] != nuidPICC[2] ||
      rfid.uid.uidByte[3] != nuidPICC[3] ) {
    Serial.println(F("A new card has been detected."));
    //Serial.println(F("Card stay in, turn light ON."));
    digitalWrite(LED, HIGH);
    for (byte i = 0; i < 4; i++) {      // Store NUID into nuidPICC array
      nuidPICC[i] = rfid.uid.uidByte[i];
    }
  }
  else {
    //Serial.println(F("Card stay in, turn light ON."));
    digitalWrite(LED, HIGH);
  }
  rfid.PICC_HaltA(); // Halt PICC
  rfid.PCD_StopCrypto1();   // Stop encryption on PCD
  delay(2000);
  rfid.PCD_Init();    // Init MFRC522
}

Yes - "No internal power source" is pretty much the definition of "passive".

The message could be encrypted.

As you said, the reader will have to keep reading.

Do you need to confirm that it's the same card staying near?

Not sure what you mean by that. Please post links/pictures.

I'm sure you could make something ...

Highly unlikely - electronics don't "wear out" !

Going back to basics, does this need to be RFID at all?

are the two instructions to send a soft reset and power again on the oscillator?

Which is the command for keep reading? Yes I need to confirm the card is near, I can't find a box with switch for dongle, so I have to keep it reading. I won't bet that electronics are living forever, especially if they come from China and use not good capacitors. Anyway I asked your experience about and it looks you never had faults with them.
This is what I call dongle
images

I think I'd call it a "fob" or "pendant".

Maybe just hang it on a hook, where the weight of it activates a switch?

Again, does this really need to be RFID?

Yes it sould, it's used by guest to open several doors, when they are inside the room they "hook" it somewhere so they won't loose and forget it when they will go out, also, this wll be useful to deactivate all electricity (excluding fridge) in the room.
Hook is not the best and safe way, also it can be easly "scotched" and simulate contact, a box with switch accepting it it doesn't exist but I could find a way, if I read RFID is much more easy, and I can test if dongle keeps works and all is ok, and I can know if guest is inside.

I need to know if rfid.PICC_HaltA(); rfid.PCD_Init(); do the job or what ever instruction keep reading card every some seconds. Thank you

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.