Problem with adding values from RFID Tags for Cash Register Project

Hi! Im doing a project that integrates RFID into cash registers and since I am fairly new to using Arduino, i’m having a bit of a problem with my coding when it comes to adding the values of the tags that are detected. What i’m trying to do is as soon as the card is detected, the value of that card would be added to the previous value that was read and will continue to do so as more tags are detected. The board that i’m using is an Arduino Uno. Posted below are the codes I tried to modify from the sample that comes with the RFID reader.

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define  STX 2
#define  ETX 3
#define  SERIALSTX 0
#define  SERIALETX 1
#define  SERIALRDY 2
#define I2C_ADDR    0x27
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);


// RFID read results
 String card_enrolled;   // = 0 if card is not enrolled = 1 if enrolled and valid
 String  card_addr;      // contains valid card index only if card is enrolled. 
 String  card_type;      // card type identifier
 String  card_number;    // card serial number

byte  serial_state;
String serialinput;
boolean  carddetected=false;



void setup() {
  // initialize serial:
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  serial_state=SERIALSTX;
  serialinput="";
  check_RFID();
   lcd.begin (16,2);

lcd.home (); // go homec
  
}

void loop() {


  if(check_RFID()==true){
    
    Serial.print("card number: ");
    Serial.println(card_number);
    Serial.println("");
 
     if(card_number.equals("0007707307")){

      lcd.clear();

      Serial.print("50");
      lcd.print("50"); 
    
      }


      if(card_number.equals("0006870617")){


        lcd.clear();

      Serial.print("54");
      lcd.print("54"); 
    
      }

      if(card_number.equals("0007707306")){

      lcd.clear();

      Serial.print("65");
      lcd.print("65"); 

     
    }
  }
}


/* Do not modify anything in the following codes unless
  you absolutely know what you are doing :-) */
  
boolean check_RFID(void){

  int  strindex;
  int  strindexe;
  
      // Read if card data is available
     if(serial_state==SERIALRDY){
     
      //extract card enrolled portion
      strindex=serialinput.indexOf(",");
      card_enrolled=serialinput.substring(0,strindex);
      
      //extract card addr portion
      strindex++;
      strindexe=serialinput.indexOf(",",strindex);
      card_addr=serialinput.substring(strindex,strindexe);
      
      //extract card type portion
      strindex=strindexe+1;
      strindexe=serialinput.indexOf(",",strindex);
      card_type=serialinput.substring(strindex,strindexe);
      
      //extract card number portion
      strindex=strindexe+1;
      strindexe=serialinput.indexOf(",",strindex);
      card_number=serialinput.substring(strindex,strindexe);
      
      // clear received string and ready SERIAL for new stream
     serialinput="";
     serial_state=SERIALSTX;
     return(true);
   }
   return(false);  // return false if RFID data is not available
}


/* This is a interrupt driven serial Rx routine */

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    
    // Wait for the STX character
    if(serial_state==SERIALSTX){
      if(inChar==STX){
        serial_state=SERIALETX;    // STX character detected, enable next phase
        return;
        }
    }
    
    // Store rx character to serial input until ETX is detected
    if(serial_state==SERIALETX){
      if(inChar!=ETX){
        serialinput += inChar;
        return;
        }
    }
    
      // Indicate serial data is ready after ETX is detected
      serial_state=SERIALRDY;
    }
  }

Any help or suggestions would be much appreciated as i am sort of desperate haha :slight_smile: Thanks!!!

What does the code do that is different from what you want? Hint: "it does not work" is not a good problem description.

The use of the String class can get you in trouble if you don't know what you are doing. See the Evils of Strings.

Karma for code tags on first post.

Welcome to the forum, and good job with the use of code tags on your first post.

i'm having a bit of a problem with my coding when it comes to adding the values of the tags that are detected. What i'm trying to do is as soon as the card is detected, the value of that card would be added to the previous value that was read and will continue to do so as more tags are detected.

How does the value of the card/tag relate to the card_number?

You will need to declare a variable to hold the sum of the values. I don't see that in your code.

I am fairly new to using Arduino

What is your experience? Are you familiar with another programming language other than C++?

I think I see what you are doing.
I designed a game with 100 RFID cards, and like your program, depended on the Card ID alone (instead of actually programming the card). Of the 100 cards, four of them had the same ID.

You don't say how many cards you are planning, but there are several ways to get a value from the card ID without individual if (card_number.equals("nnn")) statements.