Use a vibration sensor with an Arduino

FunduinoPublished on

Erschütterungen mit dem SW-420 erfassen

In dieser Anleitung wird kurz erklärt, wie du mithilfe eines Vibrationssensors Erschütterungen erfassen und anschließend verarbeiten kannst. Das kannst du dir zunutze machen, wenn du beispielsweise überprüfen möchtest, ob die heimische Waschmaschine noch in Betrieb ist.

Vibration sensor SW-420 connected to the microcontroller

You need this

SW-420 vibration sensor - tilt sensor, digital, 3.3-5 V SW-420 vibration sensor - tilt sensor, digital, 3.3-5 V 1,35 € *Item no. F23106475About the product — SW-420 vibration sensor - tilt sensor, digital, 3.3-5 V
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
830-point Breadboard - solderless breadboard for Arduino 830-point Breadboard - solderless breadboard for Arduino 2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard cables male-female - 40 pieces, 20 cm Breadboard cables male-female - 40 pieces, 20 cm 1,74 € *Item no. FUN-1010554About the product — Breadboard cables male-female - 40 pieces, 20 cm

All 4 parts together 17,11 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

Pinout

Wiring the sensor is very simple. It has only three pins:

  • + – Power supply connection, to be connected to the microcontroller’s 5V pin
  • OUT – Data output connection, to be connected to a digital pin on the microcontroller
  • – – Ground connection, to be connected to the microcontroller’s GND pin

At rest, the digital value is 0 (LOW). As soon as the vibration sensor detects a shock, the digital value 1 (HIGH) is output. This value drops again once the vibration sensor is at rest.

Vibration sensor SW-420 connected to the microcontroller

Example sketch

Example sketch
int Wert;
void setup()
{
    Serial.begin(9600); // Baudrate wird auf 9600 festgelegt. Nur so werden die Werte korrekt ausgegeben.
}
void loop()
{
  Wert = digitalRead(2); // Der digitale Sensorwert wird am digitalen Pin2 des Mikrocontrollers ausgelesen
    Serial.print("Wert: ");
    Serial.println(Wert); // … und anschließend ausgegeben.
  delay(100);
}

Serial monitor output

Serial monitor output
Serial monitor output
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.