RFID messing with LCD output

Hey guys, I'm new to the forums and have been messing with an arduino for a little over a month. I'm currently tasked with a project at work. I've worked with a Pi in the past but arduinos are new to me. I work in a metal stamping factory and I've been asked to create a device that tracks machine activity. Myself and a co-worker have come up with a prototype that is able to track machine cycles by use of a reed switch. Every time the switch is closed it adds +1 to the count. The count is displayed on an LCD. 3 buttons are attached that allow the user to Reset, Add One, and Subtract One from the count. Currently all of this is working just fine. All of this data is then forwarded to a Pi, which routes all that data to a database where we will use it to track machine productivity.

The RFID comes into play because we want to track the current state of the machine. Each employee will have an RFID card that they can scan against the device. The idea is that if a machine operator scans his/her card a green LED will turn on, signalling the machine is currently in an operational status and forward this data to the Pi and then database/. When the count is at 0 a red led is displayed, showing the machine is either being set up, or is not running at the time, which is also sent to the database. If maintenance is being done on the machine, the maintenance worker scans a card, turning on a yellow led, and notifies the database. The same for IT workers messing with the PI/Arduino, except a blue led comes on.

I've just started implementing an RFID code that simply reads the contents of a card, which I was going to modify for the previously stated needs. I currently just have 2 RFID devices, a card and a tag, (waiting on the actual cards that will be given to employees until the prototype is done). For some reason when I scan the tag the count on the LCD suddenly jumps to 247. When I scan the card this count goes to 107. This literally changes the entire count. As far as I can tell I dont even have the RFID scanner sending any data to the LCD.

Any thoughts or help would be greatly appreciated. I've attached my sketch.

Update
So I'm on to something. The tags last decimal value is 247, and the cards is 010. If I scan the card first the LCD displays 10, the tag displays 247. If I scan the card after the tag 107 is displayed because the LCD never clears the third character on the screen. I'm just not sure why this last value is being display on the LCD because the RFID shouldn't be putting anything out to that screen.

Pi_Test2.ino (7.73 KB)

#include <AddicoreRFID.h>

// this constant won't change:
const int  buttonPin = 2;   // pin for the main switch connected to the machine
const int resetPin = 4;     // pin for the reset button
const int addOnePin = 6;    // pin for the +1 button
const int subOnePin = 13;   // pin for the -1 button
const int ledRedPin = 22;   // LED pin for Reset Button
const int ledGreenPin = 23; // LED pin for +1 button
const int ledYellowPin = 24; // LED pin for -1 button
const int ledRunPin = 25; //LED pin for running green LED
const int ledOffPin = 26; //LED pin for off red LED
const int ledMaintPin = 27; //LED pin for maintenance yellow LED
const int ledITPin = 28; //LED pin for IT blue LED

// include the library code:
#include <LiquidCrystal.h>
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN   5     // Configurable, see typical pin layout above
#define SS_PIN    53   // Configurable, see typical pin layout above

//RFID setup 
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key; 
// Init array that will store new NUID 
byte nuidPICC[3];

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
int resetState = 0;          // default reset state
int addOneState = 0;         // default add one state
int subOneState = 0;         // default subtract one state
String machineState = "off";       // default machine state

// LCD setup: initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // initialize the button pins as an input and LEDs as an output
  pinMode(buttonPin, INPUT);
  pinMode(resetPin, INPUT);
  pinMode(addOnePin, INPUT);
  pinMode(subOnePin, INPUT);
  pinMode (ledRedPin, OUTPUT);
  pinMode (ledGreenPin, OUTPUT);
  pinMode (ledYellowPin, OUTPUT);
  pinMode (ledRunPin, OUTPUT);
  pinMode (ledOffPin, OUTPUT);
  pinMode (ledMaintPin, OUTPUT);
  pinMode (ledITPin, OUTPUT);
  
  // turn on button leds
  digitalWrite(ledRedPin, HIGH);
  digitalWrite(ledGreenPin, HIGH);
  digitalWrite(ledYellowPin, HIGH);
  digitalWrite(ledRunPin, LOW);
  digitalWrite(ledOffPin, LOW);
  digitalWrite(ledMaintPin, LOW);
  digitalWrite(ledITPin, LOW);
   
  // initialize serial communication:
  Serial.begin(9600);
  
  // configure the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Cycle Count");

  //RFID void setup
  Serial.begin(9600);
  SPI.begin(); // Init SPI bus
  rfid.PCD_Init(); // Init MFRC522 

  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }

  Serial.println(F("This code scan the MIFARE Classic NUID."));
  Serial.print(F("Using the following key:"));
  printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
}


void loop() {
  // read the pushbutton input pins:
  buttonState = digitalRead(buttonPin);
  resetState = digitalRead(resetPin);
  addOneState = digitalRead(addOnePin);
  subOneState = digitalRead(subOnePin);
  
  // compare the buttonState to its previous state 
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      
      Serial.println(buttonPushCounter);
      machineState = "run";
    } else {
      // if the current state is LOW then the button went from on to off:
     
    }     
  }
  //reset button is pushed
  if (resetState == HIGH)  {
    digitalWrite(ledRedPin, LOW);
    buttonPushCounter = 0;
    lcd.clear();
    lcd.begin(16, 2);
    lcd.print("Cycle Count");
    lcd.setCursor(0, 1);
    lcd.print(buttonPushCounter);
    delay(250);
    digitalWrite(ledRedPin, HIGH);
    machineState = "off";    
  } 
 
  //add one button is pushed
  if (addOneState == HIGH)  {
    digitalWrite(ledGreenPin, LOW);
    buttonPushCounter++;
    lcd.clear();
    lcd.begin(16, 2);
    lcd.print("Cycle Count");
    lcd.setCursor(0, 1);
    lcd.print(buttonPushCounter);
    Serial.println(buttonPushCounter);
    delay(250);
    digitalWrite(ledGreenPin, HIGH);  
  }

  //subtract one button is pushed
  if (subOneState == HIGH)  {
    digitalWrite(ledYellowPin, LOW);  
    buttonPushCounter--;
    lcd.clear();
    lcd.begin(16, 2);
    lcd.print("Cycle Count");
    lcd.setCursor(0, 1);
    lcd.print(buttonPushCounter);
    Serial.println(buttonPushCounter);
    delay(250);
    digitalWrite(ledYellowPin, HIGH);  
  }
  
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;

  // set LEDs to togglen on/off depending on the state of the machine
  
  if (machineState == "run") {
    digitalWrite(ledRunPin, HIGH);
    digitalWrite(ledOffPin, LOW);
    digitalWrite(ledMaintPin, LOW);
    digitalWrite(ledITPin, LOW);
  }
  if (machineState == "off") {
    digitalWrite(ledRunPin, LOW);
    digitalWrite(ledOffPin, HIGH);
    digitalWrite(ledMaintPin, LOW);
    digitalWrite(ledITPin, LOW);
  }
  if (machineState == "maint") {
    digitalWrite(ledRunPin, LOW);
    digitalWrite(ledOffPin, LOW);
    digitalWrite(ledMaintPin, HIGH);
    digitalWrite(ledITPin, LOW);
  }
  if (machineState == "IT") {
    digitalWrite(ledRunPin, LOW);
    digitalWrite(ledOffPin, LOW);
    digitalWrite(ledMaintPin, LOW);
    digitalWrite(ledITPin, HIGH);
  }
  
  // LCD screen: set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(buttonPushCounter);
  // Delay a little bit to avoid bouncing (this number will depend on the speed of the machine)
    delay(300);

  //RFID loop
  // Look for new cards
  if ( ! rfid.PICC_IsNewCardPresent())
    return;

  // Verify if the NUID has been read
  if ( ! rfid.PICC_ReadCardSerial())
    return;

  Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  Serial.println(rfid.PICC_GetTypeName(piccType));

  // Check is the PICC of Classic MIFARE type
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&  
    piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
    piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }

  if (rfid.uid.uidByte[0] != nuidPICC[0] || 
    rfid.uid.uidByte[1] != nuidPICC[1] || 
    rfid.uid.uidByte[2] != nuidPICC[2] || 
    rfid.uid.uidByte[3] != nuidPICC[3] ) {
    Serial.println(F("A new card has been detected."));

    // Store NUID into nuidPICC array
    for (byte i = 0; i < 4; i++) {
      nuidPICC[i] = rfid.uid.uidByte[i];
    }
   
    Serial.println(F("The NUID tag is:"));
    Serial.print(F("In hex: "));
    printHex(rfid.uid.uidByte, rfid.uid.size);
    Serial.println();
    Serial.print(F("In dec: "));
    printDec(rfid.uid.uidByte, rfid.uid.size);
    Serial.println();
  }
  else Serial.println(F("Card read previously."));

  // Halt PICC
  rfid.PICC_HaltA();

  // Stop encryption on PCD
  rfid.PCD_StopCrypto1();
}


/**
 * Helper routine to dump a byte array as hex values to Serial. 
 */
void printHex(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }
}

/**
 * Helper routine to dump a byte array as dec values to Serial.
 */
void printDec(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], DEC);
  }
}

Not sure what the problem is but you are overflowing nuidPICC by putting 4 bytes in it, only 3 are allocated.

You only need to call lcd.begin() once, so leave the call in setup() and remove it elsewhere.

Consider using constant bytes for the machine states instead of Strings, 0=on, 1=off, for example.