The KY-004 Key Switch Module is a small, versatile component designed for detecting button presses in various electronic projects. It features a push-button switch that outputs a digital signal when pressed, making it an ideal choice for simple user input in microcontroller-based systems. This module is commonly used in DIY electronics, prototyping, and educational projects due to its ease of use and reliability.
Parameter | Value |
---|---|
Operating Voltage | 3.3V to 5V |
Output Type | Digital |
Dimensions | 18.5mm x 15mm x 7mm |
Button Type | Momentary push-button |
Pin Count | 3 |
Pin Number | Pin Name | Description |
---|---|---|
1 | S | Signal output (digital) |
2 | Middle | Not connected (NC) |
3 | - | Ground (GND) |
Connect the Pins:
S
pin to a digital input pin on your microcontroller (e.g., Arduino).-
pin to the ground (GND) of your microcontroller.Power the Module:
Read the Button State:
S
pin outputs a digital HIGH signal.S
pin outputs a digital LOW signal.S
pin and GND to ensure a stable LOW signal when the button is not pressed.// KY-004 Key Switch Module Example Code for Arduino UNO
const int buttonPin = 2; // Pin connected to the S pin of KY-004
const int ledPin = 13; // Pin connected to the onboard LED
void setup() {
pinMode(buttonPin, INPUT); // Set button pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int buttonState = digitalRead(buttonPin); // Read the button state
if (buttonState == HIGH) { // If button is pressed
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.println("Button Pressed"); // Print message to serial monitor
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(50); // Small delay for debouncing
}
Button Not Responding:
S
pin is connected to the correct digital input pin on the microcontroller and the -
pin is connected to GND.Unstable Button Press Detection:
No Output Signal:
S
pin when the button is pressed and not pressed.By following this documentation, users can effectively integrate the KY-004 Key Switch Module into their projects, ensuring reliable and accurate button press detection.