Skip to product information
1 of 1

Blue PCB Electronics

2D7 SW-420 Motion Sensor Module Vibration Switch Alarm Sensor Module

2D7 SW-420 Motion Sensor Module Vibration Switch Alarm Sensor Module

Regular price Dhs. 15.00
Regular price Sale price Dhs. 15.00
Sale Sold out
View full details

Description

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.

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).

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

// Define the pin numbers for Vibration Sensor
const int sensorPin = 7;

void setup() {
  Serial.begin(9600);         // Start serial communication at 9600 baud rate
  pinMode(sensorPin, INPUT);  // Set the sensorPin as an input pin
}

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 "..." other wise
  }

  // Add a delay to avoid flooding the serial monitor
  delay(100);
}

Output

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);
    }