SMM2
Published © GPL3+

You've Been Using a Button Wrong this Whole Time

This tutorial will show you the easiest and best way to use a pushbutton with your Arduino board!

BeginnerFull instructions provided20,386
You've Been Using a Button Wrong this Whole Time

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
You'll need this!
×1
LED (generic)
LED (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
Since I am using a red LED I will actually be using a 220 ohm resistor (Red-Red-Brown-Gold). Though, if you are using a different color LED you may want to make sure you have the right resistor for it.
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor
You can use either one of these.

Story

Read more

Schematics

Breadboard Diagram

Make the connections as shown.

Schematic Diagram

Code

Code

Arduino
const int led = 13;
const int button = 12;

void setup() {
  // put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
if (digitalRead(button) == LOW) {
  digitalWrite(led, HIGH);
}
if (digitalRead(button) == HIGH) {
  digitalWrite(led, LOW);
}
}

Arduino Web Editor link to the code

Credits

SMM2

SMM2

2 projects • 16 followers
I'm 15 and have much interest in Robotics, and open- source electronics like the Arduino platform.

Comments