Contents

Interfacing KY-031 Knock Sensor Module with Arduino

KY-031 Knock Module Features

This module is a spring-based sensor that sends a HIGH signal when a vibration is detected. It can be widely used in security systems, or monitoring. You can easily use it with the Arduino board or any other microcontroller.

Tip
It is recommended to use microcontroller interrupt pins in order to increase accuracy.

You can download the datasheet of this module here.

KY-031 Knock Module Pinout

This sensor has 3 pins:

  •  VIN: Module power supply – 5 V
  •  GND: Ground
  •  OUT: Signal output

You can see the pinout of this module in the image bellow.

Required Materials

Hardware Components

Arduino UNO R3 × 1
KY-031 Knock Sensor Module × 1
Male to female jumper wire × 1

Software Apps

Arduino IDE

Interfacing KY-031 Knock Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to KY-031 module. Connect wires accordingly.

Step 2: Code

Upload the following code to Arduino.
/*
  on Sep 23, 2020
  by MohammedDamirchi
  
Home
*/ const byte interruptPin = 2; // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(interruptPin), Knock, RISING ); } void Knock() { Serial.println("1"); delay(2); } // the loop routine runs over and over again forever: void loop() { Serial.println("0");}
After running the code, you will see the following image in the serial output.
Liked What You See?​
Get Updates And Learn From The Best​

Leave a Reply

Your email address will not be published. Required fields are marked *