|
|
Rad 1: |
Rad 1: |
| == Bild ==
| |
| [[Fil:KY031.JPG]]
| |
|
| |
|
| == Om sensorn ==
| |
| Shock är en stötsensor som skickar ut HIGH på signalstiftet när den får en stöt/vibration
| |
|
| |
| == Synonymer ==
| |
| KEYES Shock Module, KY031, Hit sensor module, 02 ARDUINO vibration switch module
| |
|
| |
| == Koppling ==
| |
|
| |
|
| |
| == Arduino exempelkod ==
| |
|
| |
| <pre>
| |
| int LED = 13 ;// define LED pin
| |
| int SHOCK = 2; // vibration sensor pin
| |
| int val ; // define numeric variable val
| |
| void setup ()
| |
| {
| |
| pinMode (LED, OUTPUT) ; // define LED as output
| |
| pinMode (SHOCK, INPUT) ; // define SHOCK as input
| |
| }
| |
| void loop ()
| |
| {
| |
| val = digitalRead (SHOCK) ;// read SHOCK and put it into val
| |
| if (val == HIGH) // When the shock sensor detects a signal, LED flashes
| |
| {
| |
| digitalWrite (LED, LOW);
| |
| }
| |
| else
| |
| {
| |
| digitalWrite (LED, HIGH);
| |
| }
| |
| }
| |
| </pre>
| |
|
| |
| == Bibliotek ==
| |
| * [[Arduino]]
| |
| * [[C]]
| |