Introduction
In this tutorial, we are going to Interfacing KY-004 Key Switch Module with Arduino, The KY-004 Key Switch Module is a push button that will close the circuit when someone pressed it, sending a high signal to activate the led or another type of load.
This module is compatible to interface with popular electronic platforms like Arduino, ESP32, Raspberry Pi, and other microcontrollers. On pressing the button it gives a high signal to activate the circuit.
Hardware Required
You will require the following Hardware Components for the Interfacing KY-004 Key Switch Module with Arduino
Components | # | Buy From Amazon |
---|---|---|
Arduino UNO | 1 | Buy Link |
KY-004 Key Switch Module | 1 | Buy Link |
LED ( Red ) | 1 | Buy Link |
Jumper Wires | – | Buy Link |
Breadboard | 1 | Buy Link |
Specifications
This module contains a 10kΩ resistor, an FZ1713 tactile push button, and 3 male header pins.
Rating | 50mA 12VC |
Environment temperature | -25°C to 105°C [ -13°F to 221°F] |
Durability | 100,000 cycles |
Operating Force | 180/230(±20gf) |
Board Dimensions | 18.5mm x 15mm [0.728in x 0.591in] |
Pinout
Pin Configuration
Pin Name | Pin Type |
---|---|
S | Signal Pin |
middle Pin | Vcc (+5) |
( – ) | Ground |
Circuit Diagram
The following circuit shows you the connection of the Interfacing KY-004 Key Switch Module with Arduino Please make the connection carefully
Circuit Connections
Place the module on the Breadboard and connect the power pin (middle) and ground (-) of the module to +5V and GND of the arduino. and then connect the signal pin (S) to pin 3 of the Arduino respectively
Arduino | KY-003 Module | LED |
---|---|---|
+5v | Middle | |
GND | GND | LED -Ve |
Pin 3 | Signal | |
Pin 13 | LED +Ve |
Installing Arduino IDE Software
First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow
Code
The following Arduino code will constantly read the button condition on the module, when someone pressed the button it will send a HIGH signal which will turn on the LED placed on pin 13 of arduino
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);
}
}
Applications
- Security Systems: The module can be integrated into security systems to act as an input device for arming or disarming alarms.
- Access Control: It is utilized in access control systems to grant or deny access to specific areas or devices.
- Home Automation: The KY-004 module can be used as a trigger for controlling smart home devices or appliances.
- Data Input: In data logging projects, the module functions as an input device to record events or data.
- Interactive Projects: It is employed in interactive installations or art projects to initiate actions based on user input.