The KY-002 Vibration Switch Module detects shaking and knocking. When the module is moved, a spring mechanism will close the circuit sending a short high signal.
It can be used with a variety of microcontrollers like Arduino, ESP32, Raspberry Pi and others.


KY-002 Specifications
This module consists of a conductive spring, a 10k resistor, and 3 male header pins. Knocking or shaking the module will cause the spring to momentarily close the circuit.
Operating Voltage | 5V |
Board Dimensions | 18.5mm x 15mm [0.728in x 0.591in] |
Connection Diagram
Connect the module signal pin (S) to pin 3 on the Arduino.
Then connect the module’s power pin (middle) and ground (-) to +5V and GND on the Arduino respectively.
KY-002 | Arduino |
---|---|
S | Pin 3 |
middle | +5V |
– | GND |

KY-002 Arduino Code
The following Arduino sketch produces a shock flasher. The LED on Arduino pin 13 will flash when the KY-002 is knocked or shaked. Pin 3 receives the signal from the module.
int Led = 13; // define the LED Pin
int shock = 3 // define the sensor Pin
int val; // define a numeric variable val
void setup () {
pinMode (Led, OUTPUT); // LED pin as output
pinMode (shock, INPUT); // input from KY-002 sensor
}
void loop () {
val = digitalRead (shock); // read the value from KY-002
if (val == HIGH ) {// when sensor detects shock, LED flashes
digitalWrite(Led, LOW);
} else {
digitalWrite (Led, HIGH);
}
}
could you do an example on how to multiply the readings please as i cannot figure this out
could you do an example on how to multiply the readings?
Hi, first of all, I wanted to thank you for sharing this great site with us. Especially the Fritzing vectors and diagrams.
I detected a small mistake in your Example Code. You just have to switch if == HIGH, then HIGH, else LOW. Here is the corrected sktech code:
int led = 13; //Define the LED pin
int shock = 3; //Define the push button pin
int val; // Define a numeric variable
void setup()
{
pinMode(led,OUTPUT);
pinMode(shock,INPUT);
}
void loop()
{
val = digitalRead(shock); // read the value from KY-002
if(val==HIGH) { // when sensor detects shock (HIGH), LED flashes
digitalWrite(led,HIGH);
} else {
digitalWrite(led,LOW);
}
}