How to blinking led with button

In this tutorial, we will learn how to control blinking led with push button.

The buttons are one of the objects frequently used in arduino projects. You can control leds and many objects using buttons. In this project, we use button to turn on the LED. We use four legs pushbutton for this tutorial.

 

How to connect pushbutton on arduino board

Firstly, you need to prepare this circuit sheme for this example.

How-to-blinking-led-with-pushbutton

We need to use a breadboard. Pushbutton has 4 legs, but we use only two legs to connect arduino board.

Arduino code for blinking led with button

arduino-led-blinkling

Click to go Arduino Led Blinking Tutorial

 

Step 1: First step define three variables as int(integer).

Step 2: Configure ledPin OUTPUT mode and buttonPin INPUT mode.

Step 3: You need to detect button state. We use digitalRead function for this step. If you press the button, digitalRead(buttonPin) code variable is HIGH. If you don’t press the button, digitalRead(buttonPin) code variable LOW. we will transfer buttonPin value to buttonState varriable.

Step 4:

Button led control complete arduino codes

 

Leave a Reply

Your email address will not be published. Required fields are marked *