How to measure vibrations with the SW-18020P sensor and Arduino

  • The SW-18020P sensor detects vibrations through a simple contact mechanism.
  • It is inexpensive and easy to implement, perfect for Arduino beginners.
  • Includes clear connections: VCC, GND and output pin connected to Arduino.

SW-18020P

If you're exploring how to measure vibrations using the SW-18020P sensor with Arduino, you've come to the right place. With this affordable and versatile sensor, you can easily and efficiently detect sudden movements . Here we explain how it works , how to set it up , and provide a code example to help you implement it in your projects.

This type of sensor is ideal for basic applications due to its ease of use and low cost . In this article, you will find everything you need to know about the SW-18020P sensor, including electrical schematics , assembly instructions , and code implementation for vibration detection.

What is the SW-18020P sensor?

The SW-18020P is a vibration sensor designed to detect impacts or vibrations in environments where a rapid response is required . This sensor is ideal for identifying sudden movements , as it generates a digital signal when it detects vibrations, stopping when the movement ceases.

How does it work? The sensor incorporates an ingenious mechanical design : a fixed metal contact surrounded by a spring. When a vibration occurs, the spring makes contact with the fixed element, creating a closed circuit that can be read by a microcontroller such as an Arduino.

Advantages of the sensor

  • Affordable price: You can find packs of 10 sensors for less than € 1 on platforms like AliExpress.
  • Simplicity of implementation: His design basic makes it very accessible to beginners.

Electrical diagram and assembly

SW-18020P

The electrical schematic for this sensor is basic . Connect the sensor's VCC pin to the Arduino's 5V , the GND pin to the microcontroller's GND pin, and the digital output (DO) pin to a digital input, such as pin 8. This design allows the sensor to act as a switch that changes state when it detects vibrations.

To mount the sensor on a breadboard , connect a 220Ω resistor between the cathode of an LED and GND. The anode is connected to digital pin 13 of the Arduino to provide a visual detection signal.

code example

Implementing the SW-18020P sensor in your Arduino project is really easy. Here's a basic code example :


int sensorPin = 8;
int ledPin = 13;

void setup() {
  pinMode(sensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (digitalRead(sensorPin)) {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

What does this code do? It reads the sensor's digital input and, if it detects vibration, turns on the LED for one second . The structure is simple and effective , ideal for those starting out with projects of this type.

Practical applications

The SW-18020P sensor has multiple uses :

  • Detect scams o vibes in machinery.
  • Monitor movements in structures such as bridges or buildings.
  • Create reactive alarm systems to unusual vibrations.

This sensor, along with its simple assembly and code, offers an effective way to tackle vibration- related projects using Arduino. Its affordable price and versatility make it an essential tool for electronics enthusiasts and professionals alike. Take the time to experiment and explore the possibilities this device offers.


Add as preferred source in Google