KY-004 KEY SWITCH MODULE
Short description :
The KY-004 Key Switch Module is a push button that will close the circuit when pressed, sending a high signal.
Working with (Compatible)
Arduino, ESP32, Nodemcu, ESP8266, Raspberry Pi and ......
ARDUINO IDE CODE
Example description :
The LED on Arduino pin 13 will flash when the KY-004 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);
}
}