KY-031 Knock Sensor Module

$ 5.71

Categories: , ,
The KY-031 Knock Sen­sor mod­ule is a vibra­tion sen­sor that sends a sig­nal when a knock/tap is detect­ed. Com­pat­i­ble with Arduino, ESP8266, ESP32, Teen­sy, Rasp­ber­ry Pi, and oth­er pop­u­lar plat­forms.KY-031 SpecificationsThis mod­ule con­sists of a spring-based sen­sor, a 10 kΩ resis­tor and 3 male head­er pins. The spring emits a high sig­nal when a vibra­tion is detect­ed.Oper­at­ing Volt­age3.3V ~ 5VOut­put TypeDig­i­talConnection DIagramCon­nect the module’s Pow­er line (mid­dle) and the ground (-) to 5 and GND respec­tive­ly.Con­nect sig­nal (S) to pin 3 on the Arduino.KY-031ArduinoSPin 3mid­dle 5V–GNDKY-031 Arduino CodeThe fol­low­ing sketch will turn on the LED on the Arduino’s pin 13 when the mod­ule detects vibra­tion caused by knock­ing or tap­ping the sen­sor.Arduino 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); } }12345678910111213141516171819202122int Led = 13; // LED on Arduino board int Shock = 3; // sen­sor sig­nalint val; // numer­ic vari­able to store sen­sor sta­tus void set­up(){ pin­Mode(Led, OUTPUT); // define LED as out­put inter­face pin­Mode(Shock, INPUT); // define input for sen­sor sig­nal} void loop(){ val = dig­i­tal­Read(Shock); // read and assign the val­ue of dig­i­tal inter­face 3 to val if(val == HIGH) // when sen­sor detects a sig­nal, the LED flash­es { dig­i­tal­Write(Led, LOW); } else { dig­i­tal­Write(Led, HIGH); }}  Related