Serial.println() ruins my code

I’m working on a project where I have a progress bar displayed on an LCD which is incremented or decremented when an RFID tag is read. There is also a reset button that will reset the progress bar to it’s original state as well as enter a “Programming Mode” if it is held. In Programming mode, the screen simply displays the UID of the RFID tag that was most recently scanned, making it easier to record.
Here are the parts I’m using:

  • Arduino Uno
  • LCD: Hitachi HD44780
  • RFID reader: MFRC522
  • and I’m also using a small push button that came with my kit.

The code I have currently works perfectly. Until I add a Serial.println() command. I need this println because I need to be able to read data that’s coming from the Serial port for another part of this project.
Here is my code:

#include <LiquidCrystal.h>
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          
#define SS_PIN          10

MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal lcd(7,6,5,4,3,2);
const int resetButton = 1; // Reset button pin

//Initialize variables
byte readCard[4]; //Used to read in the ID from the card

//Define stored IDs
const int changeLength = 4; //Number of IDs stored
byte storedIDs[changeLength][4] = {{6, 49, 224, 160}, {163, 210, 168, 154}, {19, 9, 41, 124}, {4, 45, 113, 10}}; //Stored IDs
int storedIDchange[] = {-10, -7, -22, -40}; //The changes each ID makes
int originalChange[changeLength]; //Duplicate of storedIDchange for reset

int counter = 80; //Define where the Bar starts, 80 is full
int hold = 0; //Used for checking if the button is held

//Define custom characters for bar action
byte zero[8] = {B00000,B00000,B00000,B00000,B00000,B00000,B00000,B00000};
byte one[8] = {B10000,B10000,B10000,B10000,B10000,B10000,B10000,B10000};
byte two[8] = {B11000,B11000,B11000,B11000,B11000,B11000,B11000,B11000};
byte three[8] = {B11100,B11100,B11100,B11100,B11100,B11100,B11100,B11100};
byte four[8] = {B11110,B11110,B11110,B11110,B11110,B11110,B11110,B11110};
byte five[8] = {B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111};

void setup() {
  Serial.begin(9600);    // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522
  Serial.print("MFRC522 Initialized, ");
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details

  //Populate the originalChange array with values from storedIDchange
  for(int i = 0; i < changeLength; i++){
    originalChange[i] = storedIDchange[i];
  }
  
  //Set pintype for reset button
  pinMode(resetButton, INPUT);
  
  //Initialize LCD
  lcd.begin(16,2);
  lcd.createChar(0, zero);
  lcd.createChar(1, one);
  lcd.createChar(2, two);
  lcd.createChar(3, three);
  lcd.createChar(4, four);
  lcd.createChar(5, five);
  lcd.clear();
  Serial.println("LCD Initialized");
}

void loop() {
  //Check if the reset button has been pressed
  if(digitalRead(resetButton) == LOW){
    ounter = 80;
    for(int i = 0; i < changeLength; i++){ //Reset any values that may have been negated
      storedIDchange[i] = originalChange[i];
    }
    hold++;//Used to check if the button is held
  }else if(digitalRead(resetButton) == HIGH){
    hold = 0; //If the button is released, reset hold
  }
  
  if(hold >= 10){//If  the button is held long enough, enter programming mode
    lcd.clear();
    lcd.print("PROGRAMMING MODE"); //Notify the user they're entering programming mode
    Serial.print("Entering programming mode...");
    //delay(1000);
    hold = 0;
    while(true){
      if(digitalRead(resetButton) == LOW){//Check if the button is held
        //hold++;
      }else if(digitalRead(resetButton) == HIGH){
        hold = 0;
      }
      if(hold >= 100){//If the button is held exit programming mode
        lcd.clear();
        lcd.print("EXHIBIT MODE");
        Serial.print("Entering exhibit mode...");
        delay(1000);
        hold = 0;
        break;
      }
      printID(); //Prints IDs to LCD screen in order to easily add them to the array
    }
  }else{
    counter += checkID();
    LCDBar(counter);
    delay(250);
    Serial.println("counter");
  }
  //delay(250);
}

int checkID(){
  //Checks if an ID has been read, if so, check it against stored IDs and add/sub the
  //given amount
  int c = 0, barChange = 0, output[4] = {0, 0, 0, 0};
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
    return 0;
  }
  //Read data into an array
  for ( uint8_t i = 0; i < 4; i++) {
    readCard[i] = mfrc522.uid.uidByte[i];
  }

  //Compare readCard array to storedIDs
  for(int x = 0; x < 4; x++){
    for(int y = 0; y < 4; y++){
      if(readCard[y] == storedIDs[x][y]){
        c++; //Used to check if four values in a row have matched
        output[y] = readCard[y];
      }else{
        c = 0;
      }
    }
    if(c == 4){ //If all four values match, set position to x and break the loop
      barChange = storedIDchange[x];
      Serial.println("Match found, barChange = ");
      Serial.println(barChange);
      for(int i = 0; i < 4; i++){
        Serial.print(output[i]);
        Serial.print(' ');
      }
      Serial.println();
      storedIDchange[x] = -storedIDchange[x]; //Negate stored ID so it will reverse if the item is scanned again
      Serial.print("Negating stored ID, New water value = ");
      Serial.println(storedIDchange[x]);
      break;
    }
  }
  mfrc522.PICC_HaltA(); // Stop reading
  return barChange;
}

void LCDBar(int counter){
  //Clear the LCD
  lcd.clear();

  //Set the cursor to the top row, first character
  lcd.setCursor(0,0);
  int full = counter/5; //Calculate the number of characters that should be full
  for(int i = 0; i < full; i++){
    lcd.write(byte(5)); //Write the full characters
  }
  lcd.write(byte(counter%5)); //Write the final character of the correct size

  //Repeat for the second row
  lcd.setCursor(0,1);
  for(int i = 0; i < full; i++){
    lcd.write(byte(5));
  }
  lcd.write(byte(counter%5));
}

void printID(){
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
    return;
  }
  
  //Print data out to LCD screen
  lcd.clear();
  Serial.print("New ID found, ");
  for ( uint8_t i = 0; i < 4; i++) {
    readCard[i] = mfrc522.uid.uidByte[i];
    lcd.print(readCard[i]);
    Serial.print(readCard[i]);
    Serial.print(' ');
    lcd.print(' ');
  }
  
  Serial.println();
  mfrc522.PICC_HaltA(); //Stop reading from card
  
}

The “Serial.println(“counter”);” at the bottom of the loop function is what causes problems. Without it the code runs smoothly and exactly as intended. Once I add it, however, it would seem that the Arduino mistakes it for a button press. I thought at first that it might be that the Serial.println() was drawing power from the Arduino, therefor drawing power from the button, which would cause it to be read as a lower voltage, but I also tried plugging a friend’s 5V and GND ports into my breadboard to give it some extra power and still had the same problem. Any idea what could be causing this and how I could fix it?

Thanks

Edit: Posted the full code. Sorry, I’m used to stack overflow where you get shouted out if you post more than a few lines.

Needs more F()

(We can't see your code)

(deleted)

At a guess you have used pins 0 or 1 for the digital input, but let's see your code.

Sorry about not posting the full code. It's all there now

Thanks for the help! I was using digital pin 1 for the button. I switched it to one of my analog pins and now it works exactly as intended.