Description
Arduino Key Switch Module Keyes KY-004 is a push button that will output a high signal when pressed.
Specifications
The module consists of a FZ1713 tactile push button switch and a resistor. Compatible with popular electronics platforms like Arduino, Raspberry Pi and Esp8266.
Rating | 50mA 12VC |
Environment temperature | -25°C to 105°C [ -13°F to 221°F] |
Electrically Life | 100,000 cycles |
Operating Force | 180/230(±20gf) |
Dimensions | 18.5mm x 15mm [0.728in x 0.591in] |
KY-004 Connection Diagram
Connect the power line (middle) and ground to +5V and GND respectively. Connect signal (S) to pin 3 on the arduino.
KY-004 | Arduino |
S | Pin 3 |
middle | +5V |
- | GND |

Example Code
The following sketch will turn on Arduino's pin 13 LED when the button on KY-004 is pressed.
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);
}
}
KY-004 Related Products
Hot Deals from AliExpress
Agreed, this code didn’t work for me. I had to use the code here:
https://sensorkit.en.joy-it.net/index.php?title=KY-004_Button-module
I’ve just tested this module out and it seems that the KY004 Module constantly send a HIGH signal that interrupt only when pressed. Meaning the displayed code example is incorrect and the condition should be if(val==LOW).