I can not get a button to pause my program, any help would be appreciated.

hello i am new to arduino, and i have a program that i need to pause part way through and wait for the button to be pressed. my problem is that the arduino/program won't read the sensor, and will just endlessly repeat the do loop even when i press the button.
I was unable to attach the circuit diagram, but the button is attached to pin 12 on an arduino infaduino and on the other leg it is attached to a 10k resistor through to 5v, i have also tried having the resistor on the other leg connecting to pin 12.

  Serial.print("do"); // print "do" so i know what loop it is in
  while( digitalRead(buttonpin == HIGH/* I have also tried with the it set to LOW,*/)); //while the button is pressed 
// goes on to the rest of the program.

thanks in advance

Sounds like the button is connected wrong. Throw the resistor away, connect one leg to gnd, the other to pin 12 and use pinMode(12, INPUT_PULLUP). Then pressed will be LOW, unpressed HIGH.

But a do loop isn’t really the best way to pause anything.


thanks Steve
i will try that :slight_smile: