Basic Button

Written By
Deedar

Button
Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button.

Equipments

1. Arduino Uno
2. Button
3. Registor 10K
4. Breadboard

Schematic

Final

Code

int buttonPin = 2;
int ledPin = 8;

int buttonState = 0;

void setup() {

pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}

void loop(){

buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
// turn LED on
digitalWrite(ledPin, HIGH);
}
else {
// turn LED Off
digitalWrite(ledPin, LOW);
}
}

Advertisements
%d bloggers like this: