How to use button to start program?

How to start Arduino program by pressing a button.? I want to run Arduino code when I press a button.
ANSWER

See and compare two below codes

void setup() { /******************* * your setup code *******************/ } void loop() { /****************** * your loop code ******************/ }

The code with start button

#include <ezButton.h> ezButton button(7); // create ezButton object that attach to pin 7; void setup() { button.setDebounceTime(50); // set debounce time to 50 milliseconds while (!button.isPressed()) button.loop(); // MUST call the loop() function first /******************* * your setup code *******************/ } void loop() { /****************** * your loop code ******************/ }

The wiring diagram for above code:

How to use button to start program

Image is developed using Fritzing. Click to enlarge image

If you want to use a button to start/stop program each time button is pressed, see how to use button to start/stop program

※ NOTE THAT:

The above code uses the ezButton library, you can see how to install the library

※ OUR MESSAGES