Vibration Switch
Turns on and off a LED, when pressing button attach to pin 7
hardware
- Arduino Board
- Vibration Switch Board
wire
- SIG 8
- VCC VCC
- GND GND
code
const int vibswPin = 8; // the Vibration Switch attach to
const int ledPin = 13;
int val = 0; // variable
void setup() {
// put your setup code here, to run once:
pinMode(vibswPin, INPUT);
pinMode(ledPin, OUTPUT);
// Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(vibswPin);
// Serial.println(val);
if (val == LOW) { // without vibration signal
digitalWrite(ledPin, HIGH); // turn off LED
delay(500); // delay 500ms, the LED will be on for 500ms
} else {
digitalWrite(ledPin, LOW);
}
}