Created
December 2, 2017 06:25
-
-
Save iotguider/e917384c37b21204d9673bfd7d8de460 to your computer and use it in GitHub Desktop.
Code for interfacing Vibration Switch Module KY-002 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 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