Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iotguider/97ee770bc337b1dc5e8c41bcc6378922 to your computer and use it in GitHub Desktop.
Save iotguider/97ee770bc337b1dc5e8c41bcc6378922 to your computer and use it in GitHub Desktop.
Code for Interfacing Knock Sensor Module KY-031 in Arduino
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