Measure Vibration with Arduino and SW-18020P Sensor


In this tutorial, we are going to Measure Vibration with Arduino and SW-18020P Sensor, we will explore the capabilities of this sensor and its seamless integration with Arduino for precise vibration measurements. From structural health monitoring to anti-theft systems, the SW-18020P opens up a realm of exciting applications. Let’s dive into the fascinating realm of measuring vibration with Arduino and the versatile SW-18020P Sensor.

Hardware Required

You will require the following Hardware Components for Interfacing SW-18010P Vibration Sensor with Arduino

Components#Buy From Amazon
Arduino UNO1Buy Link
Vibration Sensors SW-18020P1Buy Link
LED 5mm1Buy Link
9v DC Adapter (Optional)1Buy Link
Jumper WiresFewBuy Link
Breadboard1Buy Link

What is a vibration sensor?

A vibration sensor is a device that reacts to sudden movements, shocks, or vibrations, but not constant or progressive movements. In the case of detecting a vibration, it generates a digital signal, which ceases at the end of the vibration.

The operating principle is very simple. The device has a cylinder, with two contacts. One of the contacts is attached to a metal rod located in the center of the cylinder around him. The other contact coils around him like a spring.

In the event of a vibration, the spring deforms by the effect of inertia, establishing contact at various points with the fixed contact. In this way, an electrical connection is established between both contacts, which can be read with a microprocessor, as if it were a button, as we saw in digital inputs in Arduino.


Circuit Diagram

The following circuit shows you the connection of the Measure Vibration with Arduino and SW-18020P Sensor Please make the connection carefully


Installing Arduino IDE Software

First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow

Code example

Next, we have a code example to read the sensor. We read the state of the sensor through the digital input, using the internal Pull Up resistor. On the other hand, we use the shake time value and the previous state variable to control the change of state, and thus detect the vibration.

//For more Projects:

const int sensorPin = 2;
const int ledPin = 13;

int tiltSensorPreviousValue = 0;
int tiltSensorCurrentValue = 0;
long lastTimeMoved = 0;
int shakeTime = 50;

void setup() {
    pinMode(sensorPin, INPUT);
    digitalWrite(sensorPin, HIGH); // activate the internal resistance PULL UP
    pinMode(ledPin, OUTPUT);

void loop() {
    tiltSensorCurrentValue = digitalRead(sensorPin);
    if (tiltSensorPreviousValue != tiltSensorCurrentValue) {
        lastTimeMoved = millis();
        tiltSensorPreviousValue = tiltSensorCurrentValue;
    if (millis() - lastTimeMoved < shakeTime) {
        digitalWrite(ledPin, HIGH);
    else {
        digitalWrite(ledPin, LOW);


  1. Structural Health Monitoring: The SW-18020P sensor uses in structural health monitoring systems to assess the structural integrity of buildings, bridges, or other infrastructure. By detecting vibrations or changes in vibrations, it can help identify potential structural defects or damages.
  2. Vehicle Safety and Anti-Theft Systems: The sensor uses in vehicle safety and anti-theft systems. By detecting vibrations caused by unauthorized access or tampering, it can trigger alarms or alerts to deter potential thieves and protect the vehicle.
  3. Earthquake Detection and Seismic Studies: The SW-18020P sensor can be part of earthquake detection systems to sense seismic vibrations. When deployed in an array, it can provide valuable data for seismic studies and earthquake research, helping to understand earthquake patterns and potential risks.

Leave a Comment