Usage Limited RFID Access System With RYRR20I_DE and Mifare Ultralight Cards

by taste_the_code in Circuits > Gadgets

291 Views, 3 Favorites, 0 Comments

Usage Limited RFID Access System With RYRR20I_DE and Mifare Ultralight Cards

RFID with Memory! Prepaid based access control with RYRR20I_DE and Mifare Ultralight

In this Instructable, I'll share a very enjoyable little project I've been working on. This DIY venture dives into the world of RFID technology, and more specifically into working with systems based on the 13.56MHz RFID.

The essence of this project is to create a basic system that writes specific data to RFID (Mifare Ultralight) tags, enabling us to control and limit their usage. For instance, envision a tag that allows entry to a facility or activates a device only a certain number of times—similar to a pre-paid bus pass or a multi-visit gym card.

A big shout-out to Reyax for generously providing the RFID module that's the centerpiece of our build, the RYRR20I_DE.

Supplies

MVI_1270.MP4.00_00_01_04.Still001.jpg
MVI_1270.MP4.00_01_06_24.Still002.jpg

Exploring the RFID Module

MVI_1271.MP4.00_01_13_09.Still001.jpg
MVI_1276.MP4.00_00_25_16.Still002.jpg
2024-04-04 08-06-25.mp4.00_00_00_00.Still001.jpg

So, let's take a closer look at the heart of our project—the RFID module we're working with. It's a sleek piece of technology referred to as the RYRR20I_DE, a multi-protocol, fully integrated 13.56 MHz RFID antenna module. This powerhouse is designed to be versatile, supporting various protocols, but the one we're particularly interested in is the ISO 14443A, which operates right at the 13.56 MHz frequency.

What makes this module truly exciting is its capability to interact with the memory blocks of specific RFID tags—those branded as "Ultralight." Here on my workbench, I've got two distinct types of tags laid out. First, we have the "MIFARE Classic" tags, which come with 1K memory. Though the module can read their unique ID or UID, manipulating their memory isn't within its scope. On the other hand, we've got these nifty small, self-adhesive tags that play nicely with the module, allowing both reading and writing operations.

Right off the bat, if I try to scan any of these tags without prior setup, the module's red LED lights up and the card ID is transmitted via serial. Since there is no data on them yet, the access is denied but this is just the starting point. We'll dive into how to write data onto these tags soon, setting them up to grant access for a prescribed number of uses.

Working With Different Types of Tags

MVI_1269.MP4.00_01_51_11.Still002.jpg
MVI_1272.MP4.00_00_13_11.Still001.jpg
MVI_1272.MP4.00_01_31_17.Still002.jpg

Even though they use a different technology, each tag is a chip with a pickup coil attached that gets excited once in the vicinity of a reader with a matching coil.

This induces enough current to the card circuit so it can then transmit its ID and in this case memory content.

At this stage, these tags are blank slates. When I try swiping one past the module, the expected data is not found so the ESP32 reacts by flashing the red LED, indicating denied access.

In the next step, we will look at how we write data to the tags so they can be allowed for usage.

Writing Data to RFID Tags

MVI_1269.MP4.00_02_10_16.Still003.jpg
2024-04-04 08-12-17.mp4.00_02_44_20.Still003.jpg

The goal is to write data to the cards that dictate the number of times they can be used. Consider the analogy of a prepaid bus ticket or a multi-entry gym pass; this is what we aim to replicate.

In the Arduino code I created for the project, I wrote a section that expects input on the ESP32 serial port. This input is then analyzed and if it matches a certain format, we can trigger actions with the module.

One such command is the "write" command that I can issue through the serial monitor. For example, inputting 'write 5' instructs the module to prepare itself to write to a tag with a limit of five uses and it flashes the red LED, indicating it's in writing mode. When I bring a tag into the module's field, the tag is written to, the module confirms the action with multiple blinks of the green LED.

When I scan the updated tag, the green LED lights up, replacing the earlier red. The serial console echoes this change by displaying 'Allowed 5.' Each scan reduces the count by one while updating and saving the new value back into the tag's memory. This decrementing continues until there are no more 'allowed' uses on the tag. Should the count hit zero, as expected, the module denies further access, signaled by the red LED once more.

But that's not the end of the story. If a user pays for additional 'rides,' I can easily write a new allowance onto the tag. For instance, 'write 3' followed by presenting the tag to the module will restore three more uses. It’s a user-friendly system allowing flexible management of access based on predetermined usage rights.

Programming the RFID System

2024-04-04 08-12-17.mp4.00_00_36_00.Still001.jpg
2024-04-04 08-31-39.mp4.00_02_07_00.Still001.jpg

Diving into the coding aspect, I created the demo with an ESP32 microcontroller to handle the operations and used the hardware serial library for smooth communication with the RFID module. To start off, I've created a few variables – one for the reset pin of the module, two for managing the LEDs' functions, and one for setting the delay between issuing commands.

In the setup function, I first initiate the serial communication with the RFID module, which is a distinct process from the serial communication with the Arduino IDE’s serial monitor. This setup phase includes sending a few specific commands to prime the module for our particular application. If all you need is to read the IDs of cards, this preparation step isn't necessary, and the module will seamlessly relay any scanned ID.

As we enter the loop function, I've crafted the code to be straightforward for this demonstration. The loop is constantly on the lookout, asking for an ID. Once an ID is detected, indicating the presence of a card, I call on the module to read the data. Any data received is then checked at a specific address – in this case, block 7. Here I've devised a simple Auth marker, 'AA BB CC,' which signifies our own data is present on the tag. Following this marker, I read the next byte, which represents the number of allowed accesses left on the card.

Should the 'allowed' count be greater than zero, the code updates the tag by decrementing that value by one and activating the green LED, signaling a successful access. Conversely, if our 'allowed' count is zero, indicating no more permitted entries, the red LED flashes in denial.

I've included a few supportive functions to handle the interactions with the module—functions to send commands, read responses, and then process those responses. There's also a reset function triggered by pulling the module's reset pin low and functions to visually indicate approval, denial, or success in updating the card.

To facilitate the writing of allowances to the cards, I've got a segment that detects a 'write' command sent through the serial monitor. When such a command is detected, the code is designed to extract the number of writes desired and to draft a command to inscribe that onto the card. Using a do-while loop, the system patiently waits for a tag to present itself, sends out the write command, and validates the action by confirming the write. With a successful update, it celebrates the occasion with a blink from the green LED before returning to its watchful state, ready for new tags and new instructions.

This code, as you see, becomes the puppet master, deftly controlling the RFID system according to our design, catering to both simplicity and function.

The full version of it can be found on my website.

Conclusion

MVI_1269.MP4.00_00_00_11.Still001.jpg
MVI_1274.MP4.00_00_13_10.Still001.jpg

This RFID system opens up a world of practical applications, from simple domestic uses to complex access control in public facilities. Let's imagine for a moment the versatility this offers. Say we're running a gym; members could be issued RFID tags as entry passes, with the module programmed to grant access for the number of sessions purchased. Every time they come in and scan their tag, the system automatically deducts one session.

Additionally, think of amusement parks or fairs where visitors could preload their cards with a certain number of rides. Each attraction would have a scanner, and with each scan, one ride would be deducted, much like the wristbands often used today, but with the convenience of a reloadable tag.

But it’s not just about leisure and transportation. Such a system could be incredibly handy around the house. If you have a pool table, you could regulate the number of games your kids play each day using these tags to release the balls. The implications for parental control are both intriguing and practical.

It's vital to note, however, that in this example, we've sidestepped the more advanced security measures that would typically accompany the use of RFID in a professional setting. We're focusing on the basics of writing and reading plain data to and from the tags. It’s a starting point for countless personalized projects, from managing personal items to creating interactive learning tools.

Now, imagine we encounter a new, never-scanned-before tag. Our system would naturally decline it since it hasn't been set up with the permissions in the specific memory block. This illustrates a significant aspect: the process of validation. A tag must be granted access in order to be recognized and functional within our system.

Using this technology responsibly and creatively, we can design countless systems, whether for fun, for education, or for streamlining certain aspects of our daily lives. Let’s move forward and take a look under the hood at the code that makes it all tick!

And there we have it—a journey through the creation and implementation of a smart, usage-limited RFID tag system! From the intricate workings of the RFID module and the varying tags to the nuances of programming and allowing specific access, this project is truly a gateway into the potential of RFID technology.

I hope you've found this foray into RFID as enriching and enlightening as I have. Whether you're exploring potential applications for your business, considering a tech-savvy upgrade to your home, or simply looking to tinker with something new, the possibilities with RFID are vast and varied.

If you have ideas, suggestions, or specific projects that could benefit from an RFID system, please drop a comment below. I'd love to hear about your creative concepts and explore how this technology can bring them to life.

If you liked this project, you can check out some of my other ones, and also feel free to check out my YouTube channel where you will find video versions of all of my projects.