Tying data to variables so as to not write lots of if statements

Hi! I recently purchased the SparkFun Simultaneous RFID reader and antenna for timing distance races using RFID. I have the RFID system up and running, and am now writing the code for the timer. In the code, I want to have the program print the person's name, time, and place. I have the time and place parts figured out and working properly, but I don't have the name part. I want to only have the Serial commands be something like Serial.print(personName) and PersonName be identified by an RFID tag being read. Long story short, I want to only write one command to identify who the tag belongs to using its serial number, and only write one command to print that name to the Serial Monitor. Any help is greatly appreciated!

What code?

The timing software (in Arduino IDE)

No idea what that is.

The code running on the Arduino (I.E. a sketch).

Oh, you mean the code that we cannot see

Oh! I'm sorry for being unclear. I haven't written that part of the code yet. I am adapting the code from a sketch I wrote a while back to time sprinting races using a laser gate. For this project I am using an RFID system to identify runners specifically. I'll print data in the serial monitor and I want to print the place, then the person's name, then the person's time (something like 1. John Smith, 15:34.23). I don't want to have to write an if statement for every tag (like if the serial number is XYZ, print this person's name). To be clear, I have not written this portion of the sketch yet. My apologies for not being very clear!

Which we can't see either.

Look at an array of structs containing names and corresponding tags.

1 Like

//Sensor Variables
const int sensorPin = A5;
int sensorValue = 0;

//Place variables - data placement
int place = 1;
float seconds;
float personTime;
unsigned long currentMillis = 0;
unsigned long prevMillis = millis;
unsigned long minutes = 0;
int heat = 1;

int greenPin = 10;
int redPin = 11;
int note = 1246;

//button things
const int  buttonPin = 2;      
int buttonPushCounter = 1;   
int buttonState = 0;         
int lastButtonState = 0; 

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  digitalWrite(greenPin, LOW);
  digitalWrite(redPin, HIGH);

//beep when things are crossed
void flash(){
  digitalWrite(greenPin, HIGH);
  digitalWrite(redPin, HIGH);
  tone(6, note);
  digitalWrite(greenPin, HIGH);
  digitalWrite(redPin, LOW);
//play the note we want
void playNote(){
  tone(6, note);

//start the race
void startRace(){
  Serial.print("Race ");
    Serial.println(" started");

//stop the race
void stopRace(){
  Serial.println("Race ended");
 // flash();

//where the magic happens
void runTimer(){
  currentMillis = millis();
  seconds = currentMillis - prevMillis;
  float personTime = seconds/1000;
  sensorValue = analogRead(sensorPin);
  digitalWrite(greenPin, HIGH);
  digitalWrite(redPin, LOW);
  //for callibration ------------------------------------------- CALLIBRATION HERE
 // Serial.println(sensorValue);

  if(seconds < 100){
 //print the time!!!
 if(sensorValue < 750){
  Serial.print("Place ");
    Serial.print(" Time: ");
    unsigned minutes = (personTime + .0005) / 60;
  personTime -= minutes * 60;
  if ((personTime + 0.0005) < 10)
  Serial.println(personTime, 3);

//and stop the timer
void stopTimer(){
  digitalWrite(redPin, HIGH);
  digitalWrite(greenPin, LOW);
  seconds = 0;
  place = 1;
  minutes = 0;
  prevMillis = millis();

//where we actually do stuff
void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
    } else {
  lastButtonState = buttonState;
  if (buttonPushCounter % 2 == 0) {
  } else {

You do know that an RFID tag reader has a range in centimeters? The runner is going to stop and hold a tag up to a reader?

There are readers that can do a longer distance than that. Warehousing folks at a company I worked at were testing an expensive reader (supply your own smartphone too!) that could do up to 50m.

It's also common to have marathon runners use tags that they tie to their shoes. I've always assumed that the tech was RFID and therefore readable at 20m or more I would expect.

I am using the SparkFun Simultaneous UHF RFID reader and antenna. I can get 15+ feet read distance, which is plenty for my application.

Very interesting. The only long-distance RFID readers I've seen are in the thousands of dollars each- hardly hobby electronics.

Please keep up updated on the project because we see people asking about long range RFID frequently.

You will miss the second runner, if their timing is less than 100 ms apart,
which happens quite often.

I see further problems identifying the tags that correspond to measurements
if more than one tag is in reach.

Good luck with using delay while trying to get precise measurements of events. :woozy_face:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.