1K
In this article, we connect an KY-004 Key Switch Module to an Arduino Uno
The KY-004 Key Switch Module is a simple on/off Micro switch compatible with Arduino systems.
Parts Required
You can connect to the module using dupont style jumper wire.
This should work with other Arduino board – I have tried an Uno and Mega
Name | Link | |
Arduino Uno | ||
37 in one sensor kit | ||
Connecting cables |
Schematic/Connection
ARDUINO | SENSOR |
---|---|
Pin 3 | S |
+ | middle pin |
GND | GND |
Code Example
int led = 13; //Define the LED pin int buttonpin = 3; //Define the push button pin int val; //Define a numeric variable void setup() { pinMode(led,OUTPUT); pinMode(buttonpin,INPUT); } void loop() { val = digitalRead(buttonpin); // check the state of the button if(val==HIGH) // if button is pressed, turn LED on { digitalWrite(led,HIGH); } else { digitalWrite(led,LOW); } }
Serial Monitor Output
Press the switch and watch the onboard LED
Links