I bought a RC522 rfid reader to integrate it into my smarthome IoT.
Most of the stuff you can find for those, both software and things, follows the idea of access control.
- the thing with the reader waits in front of a door and controls a lock. User comes, holds a keycard at the reader, is denied or allowed, puts the keycard back in their pocket and enters...
My use case is different, more like what you may find in a hotel:
- the thing with the reader waits behind the door and the user is supposed to insert the key card into the reader and leave it there. The reader identifies the key card and informs the smarthome controler that the owner of that key card is at home so it's time to turn on the lights and enable all the features that will be turned off again when the key card is taken out of the reader, later.
For this to work the key card (those blue drop shaped ones with a key chain ring you get with the reader) has to be in close range of the reader in a stable position, in other words, some sort of pocket is needed.
Searching around I couldn't find a thing like that so I had to create my own. The only difference to the source desktop rfid reader is the pocket, based on a circle cut at the top so the key chain chip can be inserted. And I skipped the sujeccon_arduino which i part of the source since it took too much space which I need for the longish dupont connectors.
The design has a noteable drawback: it gets printed with lots of support and you need to be patient and careful to get that off and not destroy the pocket on the way.
On the software side there are plenty of example sketches where the reader idles until you put a key card in its range, then the card is analysed, the result is given and the thing idles on. There is no event when the card is taken away.
So I had to write my own sketch for that, too. Again it is a remix.
It runs on an arduino clone - Nodemcu V2 - and it creates an event when a known key card is entered, and another event when that card is taken out.
Since my smarthome is controlled by openHab2 which has a very usable rest api there is some code to report those events to this, you will have to adapt this.