Interfacing Knock Sensor with Arduino (Vibration/Tap Sensor)

Table of Contents

In this project, we will learn about Knock Sensor or Vibration Sensor (sometimes called as Tap Sensor). In the process, we will see what are components of a Knock Sensor, how a Knock Sensor works and finally how to Interface a Knock Sensor with Arduino.

A Brief Note on Knock Sensor

A Knock Sensor or a Vibration Sensor is a simple device that detects vibrations or shocks from knocking or tapping it. It is basically an electronic switch which normally open. When it detects any shock or vibrations, it closes (for that moment and returns back to its default open position).

Several Knock Sensors are available in the market and the cheaper ones are called KY-031 Knock Sensors. The following image shows the Knock Sensor Module used in this project.

Knock Sensor with Arduino Knock Sensor Vibration Sensor


Components of a Knock/Vibration Sensor

A typical knock sensor consists of the main sensing element, which is a conductive vibrating spring, a Resistor and three Pins.

The three pins of the Knock Sensor Module are GND, +5V and S. The following image shows the components of a Knock Sensor Module as well as the pins on it.

Knock Sensor with Arduino Knock Sensor Pins

Schematic of Knock Sensor

In order to understand how a Knock Sensor Module works, I thing knowing its schematic is important. The following image shows a simplistic representation of the schematic of a Knock Sensor Module.

Interfacing Knock Sensor with Arduino Knock Sensor Internal Circuit

How does a Knock Sensor Work?

If you take a look at the schematic of the knock sensor, it basically consists of a switch and a resistor. The Vibrating Spring is represented as a switch here.

The output pins of the sensor (which is connected to one end of the switch) is pulled HIGH with the help of a 10KΩ Pull-up resistor.

Under normal condition i.e. when there is no shock or vibrations, the output of the Knock Sensor is HIGH.

When the sensor detects any vibrations or shocks, the vibrating spring i.e. switch closes and hence the output of the sensor (at the output pin) will become LOW.


Interfacing Knock Sensor with Arduino

Now that we have seen the components of a knock sensor and how a typical knock sensor works, let us proceed with interfacing a knock sensor with Arduino.

I have designed a simple circuit using Arduino, Knock Sensor and an LED where the LED is turned on by Arduino when the knock sensor detects any vibrations.

Also the information of the knock sensor (knock or no knock) is displayed on the Arduino IDE’s serial monitor.

Circuit Diagram for Interfacing Knock Sensor with Arduino

The following image shows the circuit diagram of Interfacing a Knock Sensor with Arduino UNO.

Interfacing Knock Sensor with Arduino Circuit Diagram

Components Required

  • Arduino UNO
  • Knock Sensor Module
  • 1KΩ Resistor
  • LED

Circuit Design

The design of the circuit for Arduino Knock Sensor interface is very simple. Connect the Supply and GND pins of the Knock Sensor to +5V and GND pins of Arduino.

Then connect the OUT (S) pin of the sensor to Digital I/O pin 8 of Arduino UNO. Finally, an LED is connected to Pin 7 of Arduino UNO through a 1KΩ current limiting resistor.

Interfacing Knock Sensor with Arduino Image 2


The code of interfacing knock sensor with Arduino is given below.


const int knockPin = 8;
const int ledPin = 7;
int knockVal = HIGH;
boolean knockAlarm = false;
unsigned long prevKnockTime;
int knockAlarmTime = 100;
void setup ()
pinMode (ledPin, OUTPUT) ;
pinMode (knockPin, INPUT) ;
void loop ()
knockVal = digitalRead (knockPin) ;
if (knockVal == LOW)
prevKnockTime = millis();
if (!knockAlarm)
Serial.println(KNOCK, KNOCK);
knockAlarm = true;
if( (millis()-prevKnockTime) > knockAlarmTime && knockAlarm)
Serial.println(No Knocks);
knockAlarm = false;



Make the connections as per the circuit diagram and upload the code to Arduino. Fix the knock sensor to a door and knock on the door.

If the vibrations are sufficient enough for the sensor to detect, the OUT of the sensor becomes low for that moment. This is detected by Arduino and it turns ON the LED for a second.

The results are also displayed on the serial monitor.

Knock Sensor with Arduino Serial Output


As per the experiments conducted at ElectronicsHub, we found that the Knock Sensor is not a very sensitive device. It doesn’t detect small knocks or taps but rather requires hard vibrations for it to detect.

Using this type of knock sensor for experimenting with some security applications like Door Knock Monitoring Systems is fine but using it as a serious sensor in a real time application is not suggested.


The main purpose of the Knock Sensor is to detect vibrations or shocks. Hence, the main application of such sensor can be in Door Knock System, where when a door is knocked, a notifications (like a light or a buzzer) can be activated.



Similar Articles & Blogs

Explore similar articles on various electronics and electrical topics – 

BCD Counter Circuit

We saw previously that toggle T-type flip flops can be used as individual divide-by-two counters. If we connect together several toggle flip-flops in a series

Learn More >>

Simple LED Flasher

The electronics student or hobbyist’s always likes to make various circuits for their home or school and especially ones that flashes a few lights, and

Learn More >>

Synchronous Counter

In the previous Asynchronous binary counter tutorial, we saw that the output of one counter stage is connected directly to the clock input of the

Learn More >>

Frequency Division

In the Sequential Logic tutorials we saw how D-type Flip-Flop´s work and how they can be connected together to form a Data Latch. Another useful

Learn More >>

Asynchronous Counter

An Asynchronous counter can have 2n-1 possible counting states e.g. MOD-16 for a 4-bit counter, (0-15) making it ideal for use in Frequency Division applications. But it

Learn More >>

Binary Weighted DAC

Digital-to-Analogue Converters, or DAC’s as they are more commonly known, are the opposite of the Analogue-to-Digital Converters we looked at in a previous tutorial. DAC’s convert binary

Learn More >>