Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save iotguider/e917384c37b21204d9673bfd7d8de460 to your computer and use it in GitHub Desktop.

Select an option

Save iotguider/e917384c37b21204d9673bfd7d8de460 to your computer and use it in GitHub Desktop.
Code for interfacing Vibration Switch Module KY-002 in Arduino
int Led = 13 ;// define LED Interface
int vibration = 2; // define the vibration sensor interface
int val; // define numeric variables val
void setup ()
{
pinMode (Led, OUTPUT) ; // define LED as output interface
pinMode (vibration, INPUT) ; // output interface defines vibration sensor
}
void loop ()
{
val = digitalRead (vibration) ; // 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