KY-031 KNOCK SENSOR MODULE
Short description :
The KY-031 Knock Sensor module is a vibration sensor that sends a signal when a knock/tap is detected.
Working with (Compatible)
Arduino, ESP32, Nodemcu, ESP8266, Raspberry Pi, and ......
ARDUINO IDE CODE
Example description :
will turn on LED when the module detects vibration caused by knocking or tapping the sensor.
int Led = 13; // LED on Arduino board
int Shock = 2; // sensor signal
int val; // numeric variable to store sensor status
void setup()
{
pinMode(Led, OUTPUT); // define LED as output interface
pinMode(Shock, INPUT); // define input for sensor signal
}
void loop()
{
val = digitalRead(Shock); // read and assign the value of digital interface 3 to val
if(val == HIGH) // when sensor detects a signal, the LED flashes
{
digitalWrite(Led, LOW);
}
else
{
digitalWrite(Led, HIGH);
}
}