Interfacing Vibration Switch Module KY-002 in Arduino

Learn to interface with Vibration Switch Module KY-002 in Arduino. 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
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 the vibration switch module to digital pin 7 of Arduino UNO. Then, connect the 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 a sensor pin and an LED pin as usual. Set the LED pin as output and sensor pin as an input. Also, declare a boolean variable ‘val’ and set it to 0. In the loop, take a reading from the sensor pin and store it in the boolean variable ‘val’. If the 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 the module detects any vibration the spring will get in contact with outer covering creating a closed circuit. The closed-circuit sends digital value 1 to the Arduino and LED will glow.

Learn more information about uploading code to Arduino Uno.

Leave a Reply