Electronics

Knocking Sensor Module KY-031

AED 6.30

1

Description

    Knock Impact sensor (KY-031) - is a device that is capable of detecting shock or vibration in the area. It is a great alternative for the SW-420 vibration sensor. It consists of a spring sensor that will detect the vibration, a pull-up resistor, and three headers pin that is allocated for the VCC (+5 Volts), GND (Ground), and S (Signal).

      Interfacing Knock Sensor with Arduino (Vibration/Tap Sensor ...

      Specification:

      - Model: KY-031

      - The Highest Voltage: 5V

      - Module Output Form: ON/OFF

      - Output Model Category: Digital Sensor

      - Sensor Category: Vibration and Shock Sensors

      - Working Principle: Vibration Sensor

      - Total Size: 27mm x 15mm x 9mm


      Schematic of Knock Sensor

      In order to understand how a Knock Sensor Module works, I think 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 on 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 the 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.

      Code

      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 ()
      {
        Serial.begin(9600);  
        pinMode (ledPin, OUTPUT) ;
        pinMode (knockPin, INPUT) ;
      }
      void loop ()
      {
        knockVal = digitalRead (knockPin) ;
        
        if (knockVal == LOW)
        {
        
          prevKnockTime = millis();
          
          if (!knockAlarm)
          {
            Serial.println("KNOCK, KNOCK");
            digitalWrite(ledPin,HIGH);
            knockAlarm = true;
            delay(1000);
          }
        }
        else
        {
          if( (millis()-prevKnockTime) > knockAlarmTime &&  knockAlarm)
          {
            digitalWrite(ledPin,LOW);
            Serial.println("No Knocks");
            knockAlarm = false;
          }
        }
      }
      

      Working

      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

      Conclusion

      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.

      Applications

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