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 a conductive spring in the 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 the circuit is closed. We are going to light up LED when the 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 the vibration switch module to GPIO pin 17 of Raspberry Pi. Then, connect the 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 a sensor pin and an LED pin as usual. Set LED pin as output and sensor pin as input and use pull up down resistor. The event detect will detect the signal (falling edge) of the sensor. If the signal is detected then the call is made to active function and LED will light up. The exception will detect the 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 the circuit diagram. The LED will turn on when vibration is detected by the sensor.

For running python code in Raspberry Pi, visit: raspberrypi.org/documentation/usage/python/
Learn basic hardware information of Raspberry Pi 3.

Leave a Reply

Your email address will not be published. Required fields are marked *