Vibration Sensor Module (SW-420)

../_images/04_sw420_vibration_module.png

Introduction

SW-420 vibration sensor is a module that can detect vibrations or shocks on a surface. It can be used for various purposes, such as detecting door knocks, machine malfunctions, car collisions, or alarm systems. It operates from 3.3 V to 5 V. The module has three peripherals, two LEDs, one for the power status and the other for the sensor output. In addition, there is a potentiometer that can be further used to control the threshold point of the vibration.

Principle

SW-420 vibration sensor module consists of a SW-420 vibration switch and an LM393 voltage comparator. A SW-420 vibration switch is a device that has a spring and a rod inside a tube. When the switch is exposed to a vibration, the spring touches the rod and closes the circuit. The vibration sensor in the module detects these oscillations and converts them into electrical signals. The LM393 comparator chip then compares these signals with a reference voltage set by the potentiometer. If the amplitude of the signal exceeds this reference voltage, the output of the comparator goes high (1), otherwise it goes low (0).

Usage

Hardware components

  • Arduino Uno R4 or R3 board * 1

  • Vibration Sensor Module(SW-420) * 1

  • Jumper Wires

Circuit Assembly

../_images/04_vibration_module_circuit.png

Code



Code explanation

  1. The first line of code is a constant integer declaration for the vibration sensor pin. We use digital pin 7 to read the output from the vibration sensor.

    const int sensorPin = 7;
    
  2. In the setup() function, we initialize the serial communication at a baud rate of 9600 to print readings from the vibration sensor to the serial monitor. We also set the vibration sensor pin as an input.

    void setup() {
      Serial.begin(9600);         // Start serial communication at 9600 baud rate
      pinMode(sensorPin, INPUT);  // Set the sensorPin as an input pin
    }
    
  3. The loop() function is where we continuously check for any vibrations detected by the sensor. If the sensor detects a vibration, it prints “Detected vibration…” to the serial monitor. If no vibration is detected, it prints “…”. The loop repeats every 100 milliseconds.

    void loop() {
      if (digitalRead(sensorPin)) {               // Check if there is any vibration detected by the sensor
        Serial.println("Detected vibration...");  // Print "Detected vibration..." if vibration detected
      }
      else {
        Serial.println("...");  // Print "..." otherwise
      }
      // Add a delay to avoid flooding the serial monitor
      delay(100);
    }
    

Additional Ideas

  • Could connect an LED to turn ON when vibration is detected

  • An alarm sound or buzzer could be triggered on vibration sense

More Projects