Based on the Gaoxin SW-18010P vibration switch, the Keyes 002 Vibration Sensor allows you to use an Arduino to detect impacts, shocks or shaking.
When the switch detects a jolt, the output of the module is sent low.

How Vibration Switch Works ?

      The switch primarily consists of a terminal that forms a center post and a second terminal that is a spring that surrounds the center post. When a sufficient force is transferred to the switch, the terminal consisting of the spring moves and shorts both terminals together.
The connection between the terminals is momentary and will require a little thought as you implement it in your Arduino project. Positioning of the switch is also important. Generally speaking the switch should be physically located as close as possible to the area being monitored. Otherwise, the vibration being detected may be dampened by other structural components in your project.
     An exception to this rule may be where you find that the switch is too sensitive for your application. In this case, moving the switch further away from the area of interest may make it less sensitive.

Arduino Connections with KY-002 Vibration Switch

Pin (-) = GND, connect to GND of the Arduino
Pin (middle pin) +5 v, connect to Arduino +5V
Pin (S) signal, connect to Arduino pin 3
When there is vibration the Arduino LED on pin 13 flashes.

Arduino Code for KY-002 Vibration Switch

//KY-002 Vibration Switch
// Steps2Make.com
int Led = 13 ;// define LED Interface
int Shock = 2; // define the vibration sensor interface
int val; // define numeric variables val
void setup ()
{
  pinMode (Led, OUTPUT) ; // define LED as output interface
  pinMode (Shock, INPUT) ; // output interface defines vibration sensor
}
void loop ()
{
  val = digitalRead (Shock) ; // read digital interface is assigned a value of 3 val
  if (val == LOW) // When the shock sensor detects a signal, LED flashes
  {
    digitalWrite (Led, HIGH); //Turn LED on
    delay(1000); //Hold LED in on state for one second
  }
  else
  {
    digitalWrite (Led, LOW);   //Turn off LED
  }
}

Results

After a successful upload, observe on board LED pin 13 gently tap on the sensor.
When the sensor detects a shock, it will be indicated by on Board LED.

Responses