Created
December 9, 2017 16:55
-
-
Save iotguider/97ee770bc337b1dc5e8c41bcc6378922 to your computer and use it in GitHub Desktop.
Code for Interfacing Knock Sensor Module KY-031 in Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Led = 13 ;// define LED Interface | |
int knockmodule = 2; // define the vibration sensor interface | |
int val; // define numeric variables val | |
void setup () | |
{ | |
pinMode (Led, OUTPUT) ; // define LED as output interface | |
pinMode (knockmodule, INPUT) ; // output interface defines vibration sensor | |
} | |
void loop () | |
{ | |
val = digitalRead (knockmodule) ; // read digital interface is assigned a value of 3 val | |
if (val == HIGH) // When the vibration sensor detects a signal, LED flashes | |
{ | |
digitalWrite (Led, LOW); | |
Serial.print(val); | |
} | |
else | |
{ | |
digitalWrite (Led, HIGH); | |
Serial.print(val); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment