Maker Pro
Arduino

LED blinking with button using Arduino

December 27, 2020 by Parmar Nilesh
Share
banner

Arduino blinking with button

Software

1 ARDUINO

INTRODUCTION OF THE PROJECT 

Neat Robo.png
const int buttonPin = 6;     // the number of the pushbutton pin
const int ledPin =  12;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Author

Avatar
Parmar Nilesh

N.tech is a technical platform for those people or students who desire to learn about electronics, IoT, and electrical engineering.

Related Content

Categories

Comments


You May Also Like