• Arduino
  • Raspberry Pi
  • Raspberry Pi Pico
  • Micro:Bit

The KY-004 button module is equipped with a push button that short-circuits two signal outputs together when the button is pressed. It works in an operating voltage range of 3.3 V to 5 V and can be operated in a temperature range of -25 °C to 105 °C. With a service life of 100,000 actuation cycles, the KY-004 offers high reliability and durability. The KY-004 is ideal for applications where a reliable and durable push-button switch is required.

Technical Data
Operating voltage 3,3 V - 5 V
Operating temperature -25 °C - 105°C
Lifetime 100.000 Zyklen
Dimensions 18 x 15 x 6 mm

Pin assignment


Arduino Sensor
Pin 10 Signal
5 V +V
GND GND

Code-Example

To load the following code example onto your Arduino, we recommend using the Arduino IDE. In the IDE, you can select the appropriate port and board for your device.

Copy the code below into your IDE. To upload the code to your Arduino, simply click on the upload button.

int button = 10; // Declaration of the sensor input pin
int value; // Temporary variable
  
void setup () {
  pinMode(button, INPUT); // Initialization sensor pin
  digitalWrite(button, HIGH); // Activation of internal pull-up resistor
  Serial.begin(9600); // Initialization of the serial monitor
  Serial.println("KY-004 Button test");
}
  
void loop () {
  // The current signal at the sensor is read out.
  value = digitalRead(button); 
  // If a signal could be detected, this is displayed on the serial monitor.
  if (value == LOW) {
    Serial.println("Signal detected");
    delay(300); // 300 ms break
    }
}

The KY-004 module is equipped with a push button that short-circuits two signal outputs together when the button is pressed. It works in an operating voltage range of 3.3 V to 5 V and can be operated in a temperature range of -25 °C to 105 °C. With a service life of 100,000 actuation cycles, the KY-004 offers high reliability and durability. The KY-004 is ideal for applications where a reliable and durable pushbutton switch is required.

Technical Data
Operating voltage 3,3 V - 5 V
Operating temperature -25 °C - 105°C
Lifetime 100.000 Zyklen
Dimensions 18 x 15 x 6 mm

Pin assignment


Raspberry Pi Sensor
GPIO 24 [Pin 18] Signal
3.3 V [Pin 1] +V
GND [Pin 6] GND

Code-Example

This is a sample program that prints a console output when as signal is detected at the sensor.

from gpiozero import Button
import time

# The sensor is initialized as a button object with the internal pull-up resistor activated.
sensor = Button(24, pull_up=True)

print("Sensor test [press CTRL+C to end the test]")

# This function is executed when a signal is detected (falling edge).
def ausgabeFunktion():
    print("Signal recognized")

# The 'outputFunction' function is bound to the 'when_pressed' event of the sensor.
sensor.when_pressed = ausgabeFunktion

# Main program loop
try:
    while True:
        time.sleep(1)

# Clean-up work after the program has been completed
except KeyboardInterrupt:
    print("Program ended")

The KY-004 module is equipped with a push button that short-circuits two signal outputs together when the button is pressed. It works in an operating voltage range of 3.3 V to 5 V and can be operated in a temperature range of -25 °C to 105 °C. With a service life of 100,000 actuation cycles, the KY-004 offers high reliability and durability. The KY-004 is ideal for applications where a reliable and durable pushbutton switch is required.

Technical Data
Operating voltage 3,3 V - 5 V
Operating temperature -25 °C - 105°C
Lifetime 100.000 Zyklen
Dimensions 18 x 15 x 6 mm

Pin assignment


Micro:Bit Sensor
Pin 1 Signal
3 V +V
GND GND

Code-Example

	
		input.onPinPressed(TouchPin.P1, function () {
		    basic.showLeds(`
		        # . . . #
		        # . . . #
		        # . # . #
		        # . # . #
		        . # . # .
		        `)
		    basic.clearScreen()
		})
	

Sample program download

microbit-KY-004.zip

The KY-004 module is equipped with a push button that short-circuits two signal outputs together when the button is pressed. It works in an operating voltage range of 3.3 V to 5 V and can be operated in a temperature range of -25 °C to 105 °C. With a service life of 100,000 actuation cycles, the KY-004 offers high reliability and durability. The KY-004 is ideal for applications where a reliable and durable pushbutton switch is required.

Technical Data
Operating voltage 3,3 V - 5 V
Operating temperature -25 °C - 105°C
Lifetime 100.000 Zyklen
Dimensions 18 x 15 x 6 mm

Pin assignment


Raspberry Pi Pico Sensor
GPIO26 Signal
3.3V +V
GND GND

Code-Example

This is a sample program that counts up and outputs text serially when a signal is detected at the sensor.

To load the following code example onto your Pico, we recommend using the Thonny IDE. All you have to do first is go to Run > Configure interpreter ... > Interpreter > Which kind of interpreter should Thonny use for running your code? and select MicroPython (Raspberry Pi Pico).

Now copy the code below into your IDE and click on Run.

# Load libraries
from machine import Pin, Timer

# Initialization of GPIO26 as input
sensor = Pin(26, Pin.IN, Pin.PULL_DOWN)

# Create timer
timer = Timer()

# Initialization of variables
counter = 0

print("KY-004 Button test")

# Function for counting keystrokes
def up(timer):
    global counter
    counter = counter + 1
    print(counter)

# Set debounce function around timer
def btn(pin):
    timer.init(mode=Timer.ONE_SHOT, period=200, callback=up)

# Initialization of the interrupt
sensor.irq(trigger=Pin.IRQ_FALLING, handler=btn)