Loading... Please wait...

Arduino Tactile Push Button Switch KY-004

Hover over image to zoom

  • Image 1
  • Image 2
$0.70
SKU:
KY-004
Weight:
1.00 Grams
Availability:
Ships within 24 hours from Cleveland, Ohio.
Shipping:
Calculated at checkout

 Product Description

The Arduino Tactile Push Button Switch KY-004 provides you with a simple all-in-one switch circuit that can be easily integrated into your project. With the KY-004 tactile switch sensor you can start experimenting with Arduino input. Arduino uses the digitalRead function to monitor the voltage on the input pin (inputPin). The Push button switch has two states HIGH (5 volts) or Low (0 volts). 

Arduino Tactile Push Button Switch Code

//
Arduino Tactile Push Button Code
Counting Presses
www.ResistorPark.com
//

int switchPin = 2;              // switch is connected to pin 2
int val;                        // variable for reading the pin status
int buttonState;                // variable to hold the button state
int buttonPresses = 0;          // how many times the button has been pressed

void setup() {
  pinMode(switchPin, INPUT);    // Set the switch pin as input

  Serial.begin(9600);           // Set up serial communication at 9600bps
  buttonState = digitalRead(switchPin);   // read the initial state
}


void loop() {
  val = digitalRead(switchPin);      // read input value and store it in val

  if (val != buttonState) {          // the button state has changed!
    if (val == LOW) {                // check if the button is pressed
      buttonPresses++;               // increment the buttonPresses variable
      Serial.print("Button has been pressed ");
      Serial.print(buttonPresses);
      Serial.println(" times");
    }
  }
  buttonState = val;                 // save the new state in our variable
}



 Find Similar Products by Category

Vendors Other Products

You Recently Viewed...

newsletter

Copyright 2019 Resistor Park. All Rights Reserved.
Sitemap | BigCommerce Design by PSDCenter

Click the button below to add the Arduino Tactile Push Button Switch KY-004 to your wish list.