Edit footer

Tactile Button Switch

About

Push-button switches are the classic momentary switch, as they only remain in their “on” state as long as they’re being actuated (pressed, held, etc). (adapted from Sparkfun)

When pressed, the tactile button switches connect two points in a circuit by allowing electricity to flow through. Tactile Button Switches have four pins, which can be a little confusing but because pins B and C are connected together as well as A and D, there are only really two electrical connections. (adapted from Adafruit)

Starter Code

/*
Adafruit Arduino - Lesson 6. Inputs

https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs?view=all
*/

int ledPin = 5;
int buttonApin = 9;
int buttonBpin = 8;

byte leds = 0;

void setup() 
{
  pinMode(ledPin, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);  
  pinMode(buttonBpin, INPUT_PULLUP);  
}

void loop() 
{
  if (digitalRead(buttonApin) == LOW)
  {
    digitalWrite(ledPin, HIGH);
  }
  if (digitalRead(buttonBpin) == LOW)
  {
    digitalWrite(ledPin, LOW);
  }
}

Resources

https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs?view=all

×

Subscribe

The latest tutorials sent straight to your inbox.