Vibration Sensor KY-002 with Arduino

  
This little sensor worked far better than I had expected. It consists of a coil of wire inside a metal tube, vibration causes the two to touch and complete the circuit. It is therefore a simple switch. The sensor has three pins,  the pin marked ‘-‘ is connected to the Arduino Gnd, the centre pin is connected to the Arduino 5 volts and the pin marked ‘S’ is connected to an Arduino Digital pin, in the case of this sketch to pin 5. A resistor on the sensor board pulls the digital pin HIGH, until the sensor is vibrated, when it is pulled LOW.

The sketch sits in a loop and when the sensor is activated the onboard LED on pin 13 lights up. There is a delay of half a second to allow the sensor to settle, then the LED is turned off. A light tap close to the sensor board will light the LED while it requires a sharp knock on the surface that the sensor is on beyond a few inches. 

If you are looking for a ‘knock’ detector then this is the sensor to go for. It is more stable than using the ball type tilt switches.

/*********************************************************
Vibration Sensor Keys 002
Connections::
- on Sensor Board to Arduino Gnd
Middle pin on Sensor Board to Arduino 5 volts
S pin on Sensor Board to Arduino pin 5

*************************************************************/
void setup() {
 pinMode(13, OUTPUT); // onboard LED
 digitalWrite(13, LOW); // turn off onboard LED
 pinMode(5, INPUT); // connect to Vibration Sensor S pin
}


void loop() {
  if (digitalRead(5) == LOW){
    digitalWrite(13, HIGH); // turn ON LED
    delay(500);
  }
  else{
    digitalWrite(13, LOW);
  }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s