Multiple Push buttons to one input So I am trying to use one input to control an LCD display. The goal being that once one of the buttons is pressed it delivers a message. I have watched quite a few tutorials and can get the program to work sometimes. Yet, it is still pretty buggy and I am wondering why that is. To get this make this project work somewhat used this code.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonPin = A0;     //Button and LED pin numbers
    void setup() 
{
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  //lcd.print(&quot;hello, world!&quot;);
  Serial.begin(9600);           //Serial monitor used to determine limit values
  
  
 }

void loop() 
{
  int temp = analogRead(buttonPin);   //Read the analogue input
  Serial.println(temp);               //Display the read value in the Serial monitor
  if (temp = 340)                     //Lower limit for first button - if below this limit then no button is pushed and LEDs are turned off
  {
  lcd.print(&quot;No Button Pushed \n&quot;);
  }
  else if (temp = 867)                //First button limit - if below this limit but above previous limit then the first button is pressed
  {
    lcd.print(&quot;Button 1 Pushed&quot;);
  }
  else if (temp = 156 )                //Second button limit
  {
    lcd.print(&quot;Button 2 Pushed&quot;);
  }
  
  else                                //If none of the previous buttons are pressed, then the third button must be pressed
  {
    lcd.print(&quot;Button 3 Pushed&quot;);
  }
  delay(100);                         //Delay for stability
}

The output sometimes is correct other times it is off. I think it has something to do with the circuit. Yet, I am scratching my head to find out what.
Michel Keijzers pointed out the issues you have in your code. But then
there is also an issue with your circuit: if you press any of the push
buttons, the analog input pin gets connected to one of the nodes of the
resistor ladder, and you get a well defined voltage reading. Good.
However, if none of the buttons is pressed, the input is not connected
to anything: it is floating. In this case the reading you get is
unpredictable, as it depends on parasitic influences of stray
capacitances, environmental noise, etc. You should modify your circuit
to make sure that the input voltage is well defined even when no button
is pressed.
Then, regarding the program, I recommend you remove everything after
Serial.println(temp);. Just make it work like this, and take note of
the readings you get in each case. Make sure they are consistent. Once
you know the values you expect, you can decide on the threshold to
apply, which should be about halfway between the typical readings. E.g.
if the two lowest values you get are 0 and 240, you would set a
threshold at 120.