How to use a Flat Vibration Switch
What is Digitala InputFlat Pull-UpVibration resistor?Switch?
InThis Arduino,is a Digitallow-sensitivity, Inputdirectional Pull-Upvibration-induced Resistortrigger switch. Inside is ana internalvery resistorsoft thatspring youcoiled canaround enablea onlong digitalmetal inputpin. When the switch is bumped from the side only, the spring attached to the first pin touches the center pole to make contact with the second pin. So when there's a bump, the two pins towill ensureact like a knownclosed defaultswitch. voltageWhen leveleverything (HIGH)is whenstill, the pinswitch is not actively connected to anything (i.e. it’s “floating”).
We have anotheropen.
tutorial showing how to use a button the normal way.
Advantage of using a button this way
Fewer External ComponentsNo need for an external resistor—the internal pull-up does the job.Makes circuits simpler and saves space, especially on a breadboard.
Stable Default State (HIGH)Ensures the input pin has a known state (HIGH) when the button is not pressed.Prevents floating inputs, which can cause random or noisy readings.
Simpler WiringYou only need to wire the button between the pin and GND.Ground is often easier to route in a circuit than Vcc (especially with many buttons).
Wiring
Getting started
const int vibrationPin = 2; // Pin connected to vibration switch
const int ledPin = 13; // Built-in LED on most Arduino boards
void setup() {
pinMode(2, INPUT_PULLUP); // Internal pull-up enabled
Serial.begin(9600);
}
void loop() {
int buttonStatestate = digitalRead(2)vibrationPin);
if (state == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println(buttonState)"Vibration detected!");
//} Readselse HIGH{
whendigitalWrite(ledPin, notLOW);
pressed, LOW when pressed (to GND)}
delay(100);
}