KY-002 Vibration Switch Module

View on Amazon
Overview
About KY-002 Vibration Switch Module
The KY-002 is a vibration switch module designed to detect shocks and movement. Using a conductive spring mechanism, it closes the circuit momentarily upon detecting vibrations, sending a digital signal to microcontrollers like ESP32 and Arduino. This makes it ideal for motion detection in security systems, interactive devices, and monitoring equipment.
⚡ Key Features
- Shock & Vibration Detection – Activates when movement or impact is detected.
- Simple Digital Output – Easily interfaces with ESP32, Arduino, and other MCUs.
- Compact & Low Power – Suitable for battery-powered projects.
- Versatile Applications – Used in security alarms, motion-sensitive devices, and monitoring systems.
With its reliable motion detection capabilities, the KY-002 is an excellent choice for interactive and security-based applications. 🚀
Get Your KY-002
💡 Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
KY-002 Specifications
Complete technical specification details for KY-002 Vibration Switch Module
📊 Technical Parameters
KY-002 Pinout
The **KY-002** is a 3-pin vibration/shock detection module:
Visual Pinout Diagram

Pin Types
Quick Tips
**Interface**: Digital output (active high on vibration),🔨 **Detection**: Conductive spring mechanism closes on impact
**Operation**: Momentary signal when shock/vibration occurs,⚡ **Power**: 3.3V or 5V operation
**Low Power**: Minimal current consumption when idle,🚨 **Applications**: Security alarms, motion detection, interactive devices
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 Pin (-) | Power | Ground connection | |
2 Pin (middle) | Power | Power supply | 3.3V or 5V |
3 Pin (S) | Communication | Digital signal output | Goes HIGH when vibration detected |
Wiring KY-002 to ESP32
To interface the **KY-002** with an **ESP32** for vibration detection:
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| KY-002 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 Pin (-) Required | GND | Ground | |
2 Pin (middle) Required | 3.3V or 5V | Power supply | |
3 Pin (S) Required | GPIO4 | Digital input (any GPIO) |
**GPIO Selection**: Any digital GPIO pin works, GPIO4 is just an example
**Voltage**: Use 3.3V for ESP32 compatibility
**Debouncing**: May require software debouncing for clean signal
**Sensitivity**: Fixed sensitivity, no adjustment possible
KY-002 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The module does not detect any vibrations or shocks.
Solutions:
- Verify all connections are secure and correctly placed.
- Ensure the module is receiving the appropriate voltage (3.3V or 5V).
- Check the microcontroller's GPIO pin configuration in the code.
Issue: The module sends signals without any actual vibration.
Solutions:
- Reduce environmental noise or interference that might affect the sensor.
- Implement software debouncing to filter out spurious signals.
- Ensure the module is securely mounted to prevent unintended movements.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
KY-002 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#define VIBRATION_PIN 10
#define LED_PIN 13
void setup() {
pinMode(VIBRATION_PIN, INPUT);
digitalWrite(VIBRATION_PIN, HIGH); // Enable internal pull-up resistor
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("KY-002 Vibration detection");
}
void loop() {
int sensorValue = digitalRead(VIBRATION_PIN);
if (sensorValue == LOW) {
Serial.println("Vibration detected");
digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
}
delay(100);
}This Arduino code sets up the KY-002 vibration sensor on pin 10 and an LED on pin 13. When a vibration is detected, the sensor outputs a LOW signal, triggering the LED to flash and a message to be printed to the serial monitor.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define VIBRATION_PIN GPIO_NUM_4
#define LED_PIN GPIO_NUM_2
void app_main(void) {
gpio_set_direction(VIBRATION_PIN, GPIO_MODE_INPUT);
gpio_set_pull_mode(VIBRATION_PIN, GPIO_PULLUP_ONLY);
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
printf("KY-002 Vibration detection\n");
while (1) {
int sensor_value = gpio_get_level(VIBRATION_PIN);
if (sensor_value == 0) {
printf("Vibration detected\n");
gpio_set_level(LED_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(100));
gpio_set_level(LED_PIN, 0);
}
vTaskDelay(pdMS_TO_TICKS(100));
}
}This ESP-IDF code configures GPIO4 as an input for the KY-002 vibration sensor and GPIO2 as an output for an LED. When a vibration is detected (sensor outputs LOW), the LED flashes, and a message is printed to the console.
binary_sensor:
- platform: gpio
pin:
number: GPIO4
mode: INPUT_PULLUP
name: "KY-002 Vibration Sensor"
filters:
- delayed_on: 10ms
- delayed_off: 10ms
on_press:
- then:
- lambda: |-
ESP_LOGD("sensor", "Vibration detected!");This ESPHome configuration sets up the KY-002 vibration sensor as a binary sensor on GPIO4 with an internal pull-up resistor. It includes filters to debounce false triggers caused by short vibrations and logs when a vibration is detected.
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduinomain.cpp
#include <Arduino.h>
#define VIBRATION_PIN 4
#define LED_PIN 2
void setup() {
pinMode(VIBRATION_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("KY-002 Vibration detection started");
}
void loop() {
if (digitalRead(VIBRATION_PIN) == LOW) {
Serial.println("Vibration detected");
digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
}
delay(100);
}This PlatformIO code configures the KY-002 vibration sensor on GPIO4 and an LED on GPIO2. When the sensor detects vibration, it outputs a LOW signal, triggering an LED blink and logging a message to the serial monitor.
import machine
import time
VIBRATION_PIN = machine.Pin(4, machine.Pin.IN, machine.Pin.PULL_UP)
LED_PIN = machine.Pin(2, machine.Pin.OUT)
while True:
if VIBRATION_PIN.value() == 0:
print("Vibration detected")
LED_PIN.on()
time.sleep(0.1)
LED_PIN.off()
time.sleep(0.1)This MicroPython script configures the KY-002 vibration sensor on GPIO4 and an LED on GPIO2. When a vibration is detected (LOW signal), the LED blinks, and a message is printed to the console.
Wrapping Up KY-002
The ESP32 KY-002 Vibration Switch Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the KY-002 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the KY-002? Check out these similar sensors that might fit your project needs.

KY-001 Temperature Sensor Module
The KY-001 is a temperature sensor module that operates within a wide temperature range. It supports 1-Wire communication and is based on...

KY-033 Line Tracking Sensor Module
The KY-033 is a line tracking sensor module that detects light-reflective and light-absorbing surfaces using infrared technology. It...

KY-050 Ultrasonic Distance Sensor Module
The KY-050 is an ultrasonic distance sensor module capable of measuring distances ranging from 2 cm to 300 cm with a resolution of...





