Phipps Electronics

Order within the next 

FREE SHIPPING OVER $199

50,000+ ORDERS

WORLDWIDE SHIPPING

SSL SECURED

Using the Knock Sensor Module KY-031 with Arduino

Contents

INTRODUCTION:

In this tutorial, we will learn about the KY-031 module, and we will build a simple project using the KY-031 module and an Arduino.

KNOCK SENSOR MODULE KY-031:

The KY-031 Module will be our main component for this tutorial. This module has a spring-based sensor mounted on a breakout board with a resistor. Figure 1 shows the module as seen in fritzing.

Figure 1: KY-031 Knock Sensor Module

 

PIN OUT:

The KY-031 module has three pins.

PinDescription
(-)GND
middle+5V
SSignal

 

HOW DOES IT WORK?

The sensor of the module has a conductive material near a spring. This spring-based sensor act like a switch. When the module experiences a shock, the spring makes contact with the adjacent conductive material and closes the circuit.

 

PROJECT – ARDUINO SHOCK DETECTOR:

After learning about the KY-031 module and how the vibration switch works, it is now time to build a project using the module. Our project will monitor if the module senses shock/vibration and will light-up the built-in LED of the Arduino Uno.

PROJECT COMPONENTS:

For this project, we need the following components:

  • Arduino Uno board (1 pc.)
  • KY-031 Knock Sensor Module (1 pc.)
  • Jumper wires

 

WIRING DIAGRAM:

Figure 2 shows the connection between the Arduino Uno and the KY-031 Knock Sensor Module.

Figure 2: Connection Diagram

 

The KY-031 module pins are connected to the Arduino Uno board as follows:

Component PinUNO Board Pin
(-)GND
middle+5V
S8

 

CODE:

Below is the Arduino sketch for our project. I have added comments to explain important parts of the code. Save the code as KY-031.ino and upload it to your Arduino board.

// Arduino and KY-031 module

void setup() {
pinMode(8, INPUT); // module is connected to pin 8
pinMode(13, OUTPUT); // set pin 13 to output which is also the built-in LED

}

void loop() {
if(digitalRead(8) == HIGH) { // module will make pin 8 HIGH if
// it detects vibration
digitalWrite(13, HIGH); // swtich ON the built-in LED
}
else digitalWrite(13, LOW); // switch off LED otherwise
}

 

PROJECT TEST:

Apply power to your Arduino Uno board. Shake the KY-031 module and observe the built-in LED. As you shake the module, the LED should blink giving a visual indication that the module senses vibration.

 

SUBSCRIBE FOR NEW POST ALERTS

Subscribe to be the first to know when we publish a new article!
List Subscriptions(Required)

POPULAR POSTS

Scroll to Top