Project16.Shock Sensor

Description

The KY-002 Vibration Switch Module detects shaking and knocking. When the module is moved, a spring mechanism will close the circuit sending a short high signal.

It can be used with a variety of microcontrollers like Arduino, ESP32, Raspberry Pi and others.

Specification

  • Operating Voltage 5V

  • Board Dimensions 18.5mm x 15mm [0.728in x 0.591in]

Connect

_images/16_bb.png

Code

int Led = 13; // define the LED Pin
int shock = 3; // define the sensor Pin
int val; // define a numeric variable val

void setup () {
    pinMode (Led, OUTPUT); // LED pin as output
    pinMode (shock, INPUT); // input from KY-002 sensor
}

void loop () {
    val = digitalRead (shock); // read the value from KY-002
    if (val == HIGH ) {// when sensor detects shock, LED flashes
        digitalWrite(Led, LOW);
    } else {
        digitalWrite (Led, HIGH);
    }
}

Phenomenon

_images/16.jpg