Looking for RFID sensore help

Still racking my brain trying to figure this out and could use some help. I have a wheel of fortune game that I am building. I am using RFID tags on the back of the wheel inside each segment (picture a big pie each piece is a segment). I am using a PN532 shield with I2C and it works great. I am able to read the cards and the ultimate goal is to trigger a video when the wheel lands on a segment (each RFID card had a unique ID which will trigger different videos. I am using Keyboard.H library to trigger a laptop with the video play list.

My problem is each time the wheel spins the reader reads the cards and triggers the media player. I need some way to not false trigger when the wheel is turning and only read the cards when it has stopped. I just cannot figure out the best solution. Any thoughts?

#include <Keyboard.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>



// If using the breakout or shield with I2C, define just the pins connected
// to the IRQ and reset lines.  Use the values below (2, 3) for the shield!
#define PN532_IRQ   (6)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield

// Uncomment just _one_ line below depending on how your breakout or shield
// is connected to the Arduino:


// Or use this line for a breakout or shield with an I2C connection:
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);


void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10); // for Leonardo/Micro/Zero

  Serial.println("Hello!");

  nfc.begin();
   
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
  
  Serial.println("Waiting for an ISO14443A Card ...");
}


void loop(void) {
  Keyboard.begin();
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
    
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  
  if (success) {
    
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    
    if (uidLength == 4)
    {
      // We probably have a Mifare Classic card ... 
      uint32_t cardid = uid[0];
      cardid <<= 8;
      cardid |= uid[1];
      cardid <<= 8;
      cardid |= uid[2];  
      cardid <<= 8;
      cardid |= uid[3]; 
      Serial.print("Seems to be a Mifare Classic card #");
      Serial.println(cardid); 
           
     if (cardid == 1839898475){
      Keyboard.write('A');
       delay(100);
     } 
     if (cardid == 3335073343){
      Keyboard.write('B');
       delay(100);
     }  
    if (cardid == 2260681791){
      Keyboard.write('C'); 
       delay(100); 
    }  
    if (cardid == 3329626431){  
      Keyboard.write('D');
       delay(100);
    }   
    if (cardid == 1186344511){
      Keyboard.write('E');
       delay(100); 
    }       
    Keyboard.end();      
     Serial.println("");
  }
}
}

You just described the problem is when the wheel is moving, so you need to design a sensor that you can monitor for movement of the wheel. Stop all RFID reading while the wheel is moving.
To do that you need a tachometer of some type To just tell you moving or not moving. When not moving begins, you still need to pause a bit before reading a card.
On a different part of your problem, how do you ensure a card is in position to be read? How ever you have determined that may also be your tachometer of movement sensor.
Paul

Paul, that's a good idea. I have never used a tachometer sensor before, but I understand the principle. I will search for one and see how to implement.

The cards are placed on the backside of the wheel near the bottom of each segment. My code only has ID's and if statements for 5 just as a test, but you can see from the drawing below there will be 10 segments.

Wheel

Again, how do you ensure a card is stopped in the correct position?

The RFID reader and cards are on the backside of the wheel. See the diagram below. This is a simple drawing, but the reader picks up the cards just fine. The reader is located on the vertical mounting pedestal and the cards are on the inside radius of each segment.

2021-10-30_15-33-39jpg

Fine, but how to avoid reading two adjacent cards if the wheel stops midway between them?

There are more stand-offs on the physical wheel than what is shown in this drawing and they are pretty thick. I believe a 1/4" in diameter. Currently there is enough space between the cards in each segment even if the wheel lands close. It will never land directly between segments because a standoff will be placed in between each segment.

Explain?

This ISO drawing shows the standoffs between segments. There will be two more within each segment. they are just not shown on this version.

Your "bracket" at the top is the perfect place to add an Ir source/detector to reflect off the standoffs as they go by. No reflection for some small amount of time means the wheel is not turning. A reflection every so often, say 1/4 second or more often means the wheel is turning.
Paul

I like your idea and the standoffs are steel, so they would reflect nicely with an IR sensor. My only concern is if the wheel stops next to one of those standoffs the IR sensor will read a reflection. I suppose one idea would be to build a small shroud around the IR detectors so they have a narrow field of view.

Yes, but if you count the number of reflections per second and it doesn't change from second to second, then not moving. You need to count the changes from reflection to no-reflection, not how many seconds it is ON!
Paul

Ok, I see what you are saying. This is a state change function with timing. I will experiment and see how it goes. Thank you

You got it!

OK, I am still a hack at coding, so I may need some help, but i'm going to give it a go.

Let us know what IR sensor/emitter you are going to use.
Paul

The link below is from Amazon and these sensors really don't look that accurate. I didn't see other sensors from Adafruit or Sparkfun. any other suggestions?

https://www.amazon.com/dp/B07ZYZRQ2F/ref=sspa_dk_detail_0?psc=1&pd_rd_w=3A4rc&pf_rd_p=887084a2-5c34-4113-a4f8-b7947847c308&pd_rd_wg=5ghwr&pf_rd_r=W6SBQ3RE310R3SKZ30NG&pd_rd_r=43242608-d855-47ec-aa3e-d9e82e5e7afc&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUExQzNJUDVYQ1ZVR0lKJmVuY3J5cHRlZElkPUEwMTE4MDE5M0FDOUJNSVZNSktSMyZlbmNyeXB0ZWRBZElkPUEwMzU2MjQzMlozSDA0QzRJMFM3VSZ3aWRnZXROYW1lPXNwX2RldGFpbCZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU=#customerReviews

But just one will do fine! Notice the spec: Output format: digital switching output (0 and 1). Which is what you want.
Paul

It occurred to me last night that perhaps i could use the card reader itself to determine when the wheel has stopped moving. For example- when the wheel turns each segment passes the reader and it will read a cards ID in sequence...Card A, B, C, D..etc. Once the wheel goes back around the cycle repeats. i cannot tell how many times the cycle would repeat because each spin would be random. That said, once the wheel stops the reader will keep reading the same card over and over (that's a problem too, but lets solve one at a time), but what if I set a timer and say 'if card A has been read continuously for 3 seconds (wheel has stopped), play a video. any thoughts?

It's ALL thought until you actually test it.