On/Off Button

I am trying to create a program that will turn on and off a process every time a button is pressed. I am testing that part of the program by first creating this program. As it is the readout on my Serial.Print continues to display 0, even after the button is pressed. I have added an LED to make sure the button is being pressed.

int buttonPin = 10;

boolean value = false;

void setup(){

pinMode(buttonPin, INPUT);

Serial.begin (9600);


void loop(){
  if (digitalRead(buttonPin) == HIGH) {


Any help, please.

Temporarily increase the delay to 1000 and see what happens. 10 millisecs is very short.


if (digitalRead(buttonPin) == HIGH) {

When this goes HIGH, as in the button is pressed, it will be HIGH for many many iterations of loop unless you have the fastest finger that has ever been and can press a button for a few microseconds at a time.

Have a look at the state change example. You need to only react when the pin first becomes changed, not the whole time it is HIGH.