How to

Hi everyone :slight_smile:
I am new to Arduino, and have a question about the RC522 RFID readers.
First of all, I want to tell you that you are currently reading the message from a person who is very poor in electronics and computers. You might as well say that if you decide to help me, you will have to be patient :stuck_out_tongue: Ah, and also, I am French. To tell you that it will be very complicated.
I own a Mega 2560.
Here is my problem:

I want to do a single tag RFID reader activation sequence. For example, the tag must pass first on reader 1, then 2, then 3, then 4, before activating a relay.
Currently, I have managed to connect multiple RFID readers and have them read tags correctly using the example “readuidmultireader” provided with the library. I just changed the pins as I’m on Mega, as well as the tag ID, of course.

I don’t know how to program a sequence with a precise order of activating RFID readers by a single tag.
If you have some food for thought, that would be really great: D
Thank you all and love from France <3

I am French

If you would be more comfortable in your own language there is a French section of this forum

Is there one tag and one sequence?

@UKHeliBob: Sorry, I didn't know there was a french question! :slight_smile: Do you want me to delete this topic?
@wildbill: Yes, that's it! There's just one tag and one sequence. I still don't know what is the sequence, I just don't know how to make readers recognize one by one to make a sequence, and go through the steps of this sequence by passing a tag on each reader :slight_smile: Is it understandable? :confused:

Do you want me to delete this topic?

You can't, but I can or I (or another mod) could copy it to the French section and you can change the title of the topic to explain what you want to do (in French, of course)

If you want it copied or deleted then please use the Report to moderator link and explain what you want done. Obviously you can continue here if that suits you, but it is against forum etiquette to post the same question in two sections

Good luck with your project

I want to do a single tag RFID reader activation sequence. For example, the tag must pass first on reader 1, then 2, then 3, then 4, before activating a relay.

That describes a state machine.

The simple solution is to set a boolean flag for each reader. When reader1 reads the right tag, set flag1 = true. When all four flags are true, activate the relay.

A more complex solution would be to use the bitSet function. Start with an integer value of zero then set a bit for each reader. Then the value of the integer shows the sequence of the card reads. Reader1 sets bit 0, giving the integer a value of 1. Reader2 sets bit 1 which adds a binary 2 to the integer value. Reader3 sets bit 2 and reader4 sets bit 3. When the integer value == 15, then activate the relay.

Using bitSet(), you can detect an out of sequence read. The value of the integer for readers 1-4 in sequence would be 1,3,7,15. If you do a reader1 then reader3, the value would be 5, indicating a sequence error.

A similar possibility is to use a byte to keep track of where you are. Set it zero to start. If the byte is zero and reader one sees the tag, set the byte to one. If byte is one and reader two sees the tag, set it to two etc. when the byte is four, trigger the relay.

If the wrong reader sees the tag, you can ignore it or zero the variable to force a restart.

@UkHeliBob: Thank you for your explanations! :slight_smile:
@SteveMann: Thanks a lot for your answer! It helps me a lot, I hadn't seen it that way. Like I told you, I am a total novice, and explanations as clear as this help me a lot :slight_smile: I have to take a little more interest in it, I will dig these tracks!
Do you think that with just the boolean flags I can make sure that it is only the right sequence that can activate the relay? For example, activate readers 1, 2, 3, 2, 1 and 4 (and therefore in reality the flags which are associated with each of the readers, if I understood correctly?) To activate the relay? I guess I'll have to work on my "ifs".