KY-002 Vibration-switch module

From SensorKit X40 Wiki

Jump to: navigation, search



Technical Data / Short discription

On vibration, the contact of the two input pins will be connected.


3 S V G.png

Code example Arduino

This example will activate a LED as soon as the sensor detects a signal.

The modules KY-011, KY-016 or KY-029 can be used as a LED.

int Led = 13 ;// Declaration of the LED output pin
int Sensor = 10; // Declaration of the Sensor input pin
int val; // Temporary variable
void setup ()
  pinMode (Led, OUTPUT) ; // Initialisation output pin
  pinMode (Sensor, INPUT) ; // Initializstion sensor pin
  digitalWrite(Sensor, HIGH); // Activating of the internal pull-up resistors
void loop ()
  val = digitalRead (Sensor) ; // The active signal at the sensor will be read
  if (val == HIGH) // If a signal was noticed, the LED will be on
    digitalWrite (Led, LOW);
    digitalWrite (Led, HIGH);

Connections Arduino:

LED + = [Pin 13]
LED - = [Pin GND]
Sensor Signal = [Pin 10]
Sensor +V = [Pin 5V]
Sensor - = [Pin GND]

Example program download


Code example for Raspberry Pi

# needed modules will be imported
import RPi.GPIO as GPIO
import time
# The input pin of the Sensor will be declared. Additional to that the pullup resistor will be activated.
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP)
print "Sensor-Test [press ctrl+c to end it]"
# This output function will be started at signal detection
def outFunction(null):
        print("Signal detected")
# At the moment of detecting a Signal ( falling signal edge ) the output function will be activated.
GPIO.add_event_detect(GPIO_PIN, GPIO.FALLING, callback=outFunction, bouncetime=100) 
# main program loop
        while True:
# Scavenging work after the end of the program
except KeyboardInterrupt:

Connections Raspberry Pi:

Signal = GPIO24 [Pin 18]
+V = 3,3V [Pin 1]
GND = GND [Pin 6]

Example program download SensorTest_RPi

To start use the following command line:

sudo python