LCD screen supposed to print random message on button press just cycling through them

I'm making something with an arduino uno and a LCD 16 x 2 screen that will show a random message chosen from an array on the top line every time you press a button and if you don't press the button for 20 seconds it will give a randomized "goodbye" message then show no text, and I will show the temperature and humidity on the button line with a DHT11 temperature sensor. When I wired it in tinkercad it worked exactly as intended (but without the DHT11 because tinkercad doesn't have that) but when I actually wired it, the temperature worked as intended but it's just cycling through the random messages really quickly even when I don't do anything and I don't think it's showing the goodbye message, I don't think it's a software issue but here's my code anyway

#include <LiquidCrystal.h>
#include <dht.h>


// putting lots of comments
LiquidCrystal lcd(12, 11, 2, 3, 4, 5); // connect the screen to those pins

const char* messages[] =
{
  "Hello           ",
  "How are you?    ",
// there are more messages but you don't have to see those
};

const char* goodbyeMessages[] = 
{ 
  "Goodbye         ",
  "see you later   ",
  "Farewell        ",
  "powering off    "
};

const int buttonPin = 6; // connect button to pin 6
bool buttonPressed = false;
unsigned long lastMessageTime = 0; // time passed since the button was pressed
const unsigned long constTimeToLeave = 20000; // will turn timeToLeave variable into the proper amount of time after becoming 999999
unsigned long timeToLeave = 20000; // how long it will take since pressing the button to say goodbye, will turn into 999999 so that it doesnt constantly give goodbye messages
unsigned long timeToPowerOff = 1000; // how long it will take to turn off after saying goodbye

// (for temperature)
dht DHT; // make a dht (temp/humid sensor's brand) variable called DHT
#define DHT11_PIN 7 // designate the temp/humid sensor to pin 7

void setup() 
{
  lcd.begin(16, 2); //setup the screen
  randomSeed(analogRead(A0)); // number generator
  pinMode(buttonPin, INPUT_PULLUP); 
}

void loop() 
{
  // check if the button is pressed
  if (digitalRead(buttonPin) == LOW) 
  {
	  timeToLeave = constTimeToLeave; // sets timeToLeave to be the right amount of time
    buttonPressed = true;
    lastMessageTime = millis(); // update last message time
    delay(75);
  }

  //show the random message when i press the button
  if (buttonPressed)
  {
  	int randomIndex = random(0, sizeof(messages)/ sizeof(messages[0])); // randomly picks a message
  	lcd.setCursor(0, 0); // moves the cursor of the screen to be the start of the sentence
  	lcd.print(messages[randomIndex]); // writes the randomly selected message
    buttonPressed = false;
  }

  if (millis() - lastMessageTime >= timeToLeave)
  {
    int randomGoodbyeIndex = random(0, sizeof(goodbyeMessages) / sizeof(goodbyeMessages[0])); // chooses random goodbye message
    lcd.setCursor(0, 0);
    lcd.print(goodbyeMessages[randomGoodbyeIndex]); // shows the goodbye message
    timeToLeave = 999999;
    delay(timeToPowerOff);
    lcd.setCursor(0, 0);
    lcd.print ("                ");
    buttonPressed = false;
  }
  
  // read temperature
  int chk = DHT.read11(DHT11_PIN);
 
  //show temperature on screen 
  lcd.setCursor(0, 1);
  lcd.print("T:");
  lcd.print(DHT.temperature);
  lcd.print("C,");
  lcd.print ("H:");
  lcd.print(DHT.humidity);
}

and here are pictures of my wiring in tinkercad and in real life



both of the resistors are 1.8kho

Thanks.

If you want to show one new message for each new button press you need to act on the change of the button signal, not the level of the signal.

Check out the IDE’s file/examples/02.digital/StateChangeDetection example and see if you can use that to start your “buttonPressed” logic

Is this wired properly? It is hard to tell from the the pic:

image

Try configuring the File/Examples/02.Digital/Button example to work with your const int buttonPin = 6; and test that the button works as expected.

I'm pretty sure its right, I'll check it again though

I fixed the problem, it turns out the button was just sideways