KY-002 Vibration Switch Module

Description

Arduino Vibration Switch Module KY-002 Keyes allows detection of shock and vibration.

Specifications

The KY-002 Vibration Switch Module consists of a conductive vibration spring and a 10k resistor, it will react to shock and vibration by closing the circuit.

Operating Voltage5v
Dimensions18.5mm x 15mm [0.728in x 0.591in]

Connection Diagram

Connect the Power line (middle) and ground (-) to +5 and GND respectively. Connect signal (S) to pin 3 on the Arduino.

Arduino KY-002 connection diagramclick to enlarge

Example Code

The following Arduino sketch produces a shock flasher. Pin 13 (LED) on the Arduino will flash when KY-002 detects movement. Pin 3 is used as input from KY-002.

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);
	}
}

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Kei Kaneda Recent comment authors
Kei Kaneda
Kei Kaneda

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);
}
}