Site icon Iotguider

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 the Vibration module. The major difference between these two is its sensitivity. The vibration sensor detects even a small shock, whereas the knock sensor requires a powerful knock or a jolt to activate. To check if the module has detected a knock or jolt, we will light up an 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 the Knock Sensor module to digital pin 7 of Arduino UNO. Then, connect the VCC pin and GND pin of the Knock sensor module to the +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 a sensor pin and an LED pin as usual. Set the LED pin as output and sensor pin as an input. Also, declare a boolean variable ‘val’ and set it to 0. In the loop, take the reading from the sensor pin and store it in the boolean variable ‘val’. If the 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 the module detects any powerful knock or jolt, the closed-circuit will be formed and LED will light up.

Learn more information about uploading code to Arduino Uno.

Exit mobile version