Interfacing Vibration Switch Module KY-002 in Arduino

Learn interfacing Vibration Switch Module KY-002 in Arduino. 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
Arduino UNO Board x 1
Jumper Wires

Step 2: Circuit Time

Firstly, connect LED to digital pin 13 of Arduino. Now, connect the signal pin of vibration switch module to digital pin 7 of Arduino UNO. Then, connect VCC pin and GND pin of vibration switch module to +5v and GND pin of Arduino.

Step 3: Code Time

The code for Vibration Switch Module KY-002 in Arduino is simple. Firstly, declare sensor pin and LED pin as usual. Set LED pin as output and sensor pin as input. Also, declare a boolean variable ‘val’ and set it to 0. In loop, take reading from sensor pin and store it in boolean variable ‘val’. If value of ‘val’ is high then LED lights up.

Step 4: Upload the code to Arduino

Set components as per the Circuit Diagram and upload the code to the Arduino UNO Board. When module detects any vibration the spring will get in contact with outer covering creating a closed circuit. Closed circuit send digital value 1 to the Arduino and LED will glow.

For information about uploading code to Arduino UNO Click Here.

Leave a Reply