Programming for rfid and piezo speaker

My goal is that this program will whistle when it does not see a tag and stop whistling when it sees the tag and go silent until the tag is no longer near it the program below will start whistling then when it sees a tag stop but wont start whistling again once the tag is removed. i think i have watched every video out there on this so please help

_122_test_program.ino (1.76 KB)

So other people don’t have to download the code you should have posted here:

#include <SoftwareSerial.h>
SoftwareSerial rfidSerial=SoftwareSerial(10,11);
#define BUFSIZE 11
#define RFID_START 0x0A
#define RFID_STOP 0x0D
double deadtime=50;

void setup()
{pinMode(9,OUTPUT);
 pinMode(10,INPUT);
 pinMode(13,OUTPUT);
 digitalWrite(9,HIGH);
 Serial.begin(9600);
 while(!Serial);
 rfidSerial.begin(2400);
Serial.flush();
}
void loop()
{ 
  digitalWrite(9,LOW);
  char rfidData[BUFSIZE];
  //char offset = 1;
  rfidData[0] = 0;
  
  
// while(rfidSerial.available() == 0){
  
  if (rfidSerial.available() < 1)   
   {int half_period=100;
    digitalWrite(13,HIGH);
    delayMicroseconds(half_period);
    digitalWrite(13,LOW);
    delayMicroseconds(half_period);
    
    }  
     digitalWrite(9,HIGH);
  /* if (rfidSerial.available() > 1) // If there are any bytes available to read, then the RFID Reader has probably seen a valid tag
    {
      rfidData[offset] = rfidSerial.read();  // Get the byte and store it in our buffer
      if (rfidData[offset] == RFID_START)    // If we receive the start byte from the RFID Reader, then get ready to receive the tag's unique ID
      {
        offset = -1;     // Clear offset (will be incremented back to 0 at the end of the loop)
      }
      else if (rfidData[offset] == RFID_STOP)  // If we receive the stop byte from the RFID Reader, then the tag's entire unique ID has been sent
      {
        rfidData[offset] = 0; // Null terminate the string of bytes we just received
        break; 
       // Break out of the loop
      }
          
      offset++;  // Increment offset into array
      if (offset >= BUFSIZE) offset = 0; // If the incoming data string is longer than our buffer, wrap around to avoid going out-of-bounds
    }*/
  

 
  

// Serial.println(rfidData);
  
// Serial.flush();
 rfidData[0] = 0;
 
   }

The commented out code is CLEARLY not part of the problem. GET RID OF IT.

Serial.flush() blocks until outgoing serial data has been sent. Clearly that is of NO use in this program. GET RID OF IT.

I can’t see where you actually read any data from the RFID device.