Interfacing Knock Sensor Module KY-031 in Arduino

Learn interfacing Knock Sensor Module KY-031 in Arduino. Knock sensor module KY-031 is similar to Vibration module. The major difference between these two is its sensitivity. Vibration sensor detects even a small shock, whereas knock sensor requires a powerful knock or a jolt to activate. To check if module has detected a knock or jolt, we will light up LED. So, Let’s start.

Step 1: Required Components

Knock Sensor Module KY-031 x 1
Generic LED x 1
Breadboard x 1
Arduino UNO Board x 1
Jumper Wires

Step 2: Circuit Time

Firstly, connect LED to digital pin 13 of Arduino. Now, connect the signal pin of Knock Sensor module to digital pin 7 of Arduino UNO. Then, connect VCC pin and GND pin of Knock sensor module to +5v and GND pin of Arduino.

Step 3: Code Time

This is code for Knock Sensor Module KY-031 in Arduino. It is as same as Vibration Switch Module. Firstly, declare sensor pin and LED pin as usual. Set LED pin as output and sensor pin as input. Also, declare a boolean variable ‘val’ and set it to 0. In loop, take reading from sensor pin and store it in boolean variable ‘val’. If value of ‘val’ is high then LED lights up.

Step 4: Upload the code to Arduino

Set components as per the Circuit Diagram and upload the code to the Arduino UNO Board. When module detects any powerful knock or jolt, closed circuit will be formed and LED will light up.

For information about uploading code to Arduino UNO Click Here.

Leave a Reply