Acoptex.Com

Learn ESP32, ESP8266, Arduino, and Raspberry Pi

Arduino Guide for vibration sensor

We are going to learn about the vibration sensor and how to use it with Arduino board.

We will detect the vibration using the vibration sensor and print the values in Arduino Serial Monitor.

Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you. Acoptex.com

Tag: Project 004 Arduino Guide for vibration sensor

Project resources

  • Libraries: None used
  • Sketch: sketch
  • Other: fritzing drawing, views can be found here.

Part required:

  1. Arduino Uno with USB 2.0 Cable – A-Male to B-Male 1 pc;
Arduino Uno | Acoptex.com

2. Vibration module SW-420 1 pc;

Vibration sensor sw-420 | Acoptex.com

3. Jumper cables F-M 3 pcs

jumper cables

4. Arduino IDE (you can downloat it here)

Introduction

There are several critical machines or expensive equipment which suffer damages due to vibrations. In such a case, a vibration sensor is required to find out whether the machine or equipment is producing vibrations or not. Identifying the object which is continuously vibrating is not a tricky job if the proper sensor is used to detect the vibration. There are several types of vibration sensors available in the market which can detect the vibration by sensing acceleration or velocity and could provide excellent result. However, such sensors are too expensive where the accelerometer is used. Accelerometer is very sensitive and can be used to make Earthquake detector circuit. But, there are few dedicated and cheap sensors are also available to detect the vibrations only, one such vibration sensor is SW-420 which we are going to interface with Arduino board.

Applications of Vibration Sensor Module

  • Shocks triggering
  • Theft alarm
  • Smart car
  • Earthquake alarm
  • Motorcycle alarm

Understanding the vibration sensor SW-420

The SW-420 vibration module can work from 3.3V to the 5V. The sensor uses LM393 comparator to detect the vibration over a threshold point and provide digital data, Logic Low or Logic High, 0 or 1. During normal operation, the sensor provides Logic Low and when the vibration is detected, the sensor provides Logic High. There are three peripherals available in the module, two LEDs, one for the Power state and other for the sensor’s output. Additionally, a potentiometer is available which can be further used to control the threshold point of the vibration. In this project, we will use 5V to power the module.

Features & Specifications

Operating Voltage: 3.3V to 5V DC
Operating Current: 15mA
Using SW-420 normally closed type vibration sensor
LEDs indicating output and power
LM393 based design
Easy to use with Microcontrollers or even with normal Digital/Analog IC
With bolt holes for easy installation
Small, cheap and easily available

Understanding the Arduino Uno

Check our Arduino Uno Rev 3 – Quick Guide for Beginners for more details.

Signals and connections of the vibration sensor SW-420

Pin NameDescription
VCCThe Vcc pin powers the module, typically with +5V
GNDPower Supply Ground
DODigital Out Pin for Digital Output.
SCan be digital signal output or analog signal output (depends on vibration sensor module – if digital module will be digital signal output, in other cases analog signal output

Wiring

Arduino Uno and vibration sensor SW-420
Arduino Uno and vibration sensor SW-420

Step by Step Instruction

1.Do wiring.

2. Download the latest version of Arduino IDE for your system here and install it in your PC/laptop.

3.Plug your Arduino board into your PC/laptop USB port.

3. Open Arduino IDE. Select the correct board and COM port.

4. Verify and upload sketch to your Arduino board.

5. After uploading the code, open Arduino Serial Monitor at 9600 bps. When it detects vibration that is above its set threshold, it will send a HIGH signal and if no vibration or below the threshold, it will send a LOW signal. The threshold can be adjusted by turning the potentiometer.

Code

const int sensorPin = 3; // vibration sensor DO pin attached to the digital pin D3 of the Arduino board
 
void setup()
{     
  Serial.begin(9600)         // initialise the serial communication at 9600 bps
  pinMode(sensorPin, INPUT); // set the D3 pin as INPUT
  }
  
void loop() 
{     
  int sensorValue = digitalRead(sensorPin); // get the vibration sensor digital output value and store it in sensorValue variable of type int.     
    
  if (sensorValue == HIGH) // if vibration detected by the vibration sensor then
  {    
    Serial.println("Vibration detected");    // print the message
  }   
  else 
// if no vibration detected then
  {     
    Serial.println("No vibration detected");     // print the message
  }
  delay(1); 
}

Wrapping up

You have learnt about the vibration sensor and how to use it with Arduino board.

Thank you for reading and supporting us.

Check for more DIY projects on Acoptex.lt and Acoptex.com!

If you are looking for high quality PCBs PCBWay is the best choice: