Skip to product information
1 of 2

Blue PCB Electronics

2D13 Knock Hit Tap Sensor Module KY-031 for Raspberry Pi Arduino

2D13 Knock Hit Tap Sensor Module KY-031 for Raspberry Pi Arduino

Regular price Dhs. 10.00
Regular price Sale price Dhs. 10.00
Sale Sold out
View full details

Description:

The Tap-Hit Knocking Sensor Module, detects the knocks and the taps. It can work like a switch. The sensor sends data momentarily to the board. To keep the LED on, the button state change codes should be used. So the sensor will work as a switch.

It is a vibration sensor that sends a signal when a knock/tap is detected. Compatible with Arduino, ESP8266, ESP32, Teensy, Raspberry Pi, and other popular platforms.

Specification:

  • Single channel signal output
  • Convenient to install 
  • Circuit board output switch
  • Working voltage: DC 3~5V;
  • Great for teaching demonstration or product development

CONNECTION DIAGRAM

Connect the module’s Power line (middle) and the ground (-) to +5 and GND respectively.

Connect signal (S) to pin 3 on the Arduino.

KY-031 Arduino
S Pin 3
middle +5V
– GND

 

Arduino KY-031 Knock sensor module connection diagram

Code

 The following sketch will turn on the LED on the Arduino’s pin 13 when the module detects vibration caused by knocking or tapping the sensor.

int Led = 13;	// LED on Arduino board 
int Shock = 3;	// sensor signal
int val;		// numeric variable to store sensor status

void setup()
{
	pinMode(Led, OUTPUT); 	// define LED as output interface
	pinMode(Shock, INPUT); 	// define input for sensor signal
}

void loop()
{
	val = digitalRead(Shock); // read and assign the value of digital interface 3 to val
	if(val == HIGH) // when sensor detects a signal, the LED flashes
	{
		digitalWrite(Led, LOW);
	}
	else
	{
		digitalWrite(Led, HIGH);
	}
}