Arduino Push Button and Control Led Pin 13

Created At: 2024-07-06 16:02:35 Updated At: 2024-07-06 16:47:21

Here we will program arduino with a push button to on and off led pin 13. Led pin 13 is built in led light and could be controlled using a sketch.

To follow this you need to have three male to female jump wires, a push button and an arduino uno board.

Here on the very left we see three jumper wires and they are all male to female. Then we see our push button and then the arduino board.

Our push button has three pins. These three pins we must connect to arduino board using the male to female wires.

This is how you need to connect push button to the arduino board. Let's see the video how to connect them step by step.

Once the above set up is done, then connect your arduino board with arduino IDE in your pc. Then upload the below sketch to arduino.

Then you click on the push button you will see that led 13 light up and when you release led 13 gets off.

const int buttonPin = 2; // the number of the pushbutton pin

const int ledPin = 13; // the number of the built-in LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
void loop() {
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // turn LED on
} else {
digitalWrite(ledPin, LOW); // turn LED off


Add Reviews

Latest Posts

Subscribe our newsletter