Interfacing Vibration Switch Module KY-002 in Raspberry Pi

Learn interfacing Vibration Switch Module KY-002 in Raspberry Pi. Vibration Switch Module KY-002 has a cylindrical setup for the switch. There is conductive spring in middle covered by another conducting cylindrical plate. When any sort of shock is applied to the module, spring gets in contact with cylindrical covering and circuit is closed. We are going to light up LED when module detects shocks. So, let’s start.

Step 1: Required Components

Vibration Switch Module KY-002 x 1
Generic LED x 1
Breadboard x 1
Raspberry Pi x 1
Jumper Wires

Step 2: Circuit Time

Firstly, connect LED to GPIO pin 27 of Raspberry Pi. Now, connect the signal pin of vibration switch module to GPIO pin 17 of Raspberry Pi. Then, connect VCC pin and GND pin of vibration switch module to +5v and GND pin of Raspberry Pi.

Step 3: Code Time

The code for Vibration Switch Module KY-002 in Raspberry Pi is simple. Firstly, declare sensor pin and LED pin as usual. Set LED pin as output and sensor pin as input and use pull up down resistor. Event detect will detect the signal (falling edge) of the sensor. If signal is detected then call is made to active function and LED will light up. Exception will detect keyboard interrupt and perform GPIO cleanup.

Step 4: Run code to Raspberry Pi

Run the Python program in your Raspberry Pi after setting components as per circuit diagram. The LED will turn on when vibration is detected by the sensor.

For running python code in Raspberry PI, visit:

For basic hardware information about Raspberry PI 3, Click here.

Leave a Reply