For optimum performance of machines, it is imperative to continuously monitor physical parameters such as temperature, humidity, speed, vibration, etc. Timely detection of discrepancies in these parameters can prevent any downtime or machine damage which may ultimately lead to preventing huge sums of financial loss. Simple speaking, vibration can be defined as mechanical oscillation about an equilibrium position of a machine or component. Mechanical vibration in industrial equipment is usually a common occurrence but an abnormal amount of vibration is certainly a cause of concern. Due to this, the phenomenon of vibration requires constant monitoring. So, in this tutorial, we are going to go over a step by step process on How To Interface SW420 Vibration Sensor Module With An Arduino Uno.
What is SW420 Vibration Sensor?
Vibration Sensor Module SW-420 is a high sensitivity non-directional vibration sensor module that features an adjustable potentiometer, a vibration sensor, and a LM393 comparator chip to give an adjustable digital output based on the amount of vibration. The preset pot can be adjusted to both increase and decrease the sensitivity to the desired amount. The module outputs a logic level high (VCC) when it is triggered and a low (GND) when it isn’t. Additionally, there is an onboard LED that turns on when the module is triggered.
Key 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
- Interface: Digital
- Size: L: 40mm W: 20mm H: 10mm
- Weight: 4.3g
- Package size: L: 140mm W: 85mm H: 10mm
- Gross Weight: 10g
Hardware Components
You will need the following parts to build this project:
S.No | Component | Value | Qty |
---|---|---|---|
1) | Vibration Sensor Module | SW-420 | 1 |
2) | Arduino Uno Board | Rev3, 8KB | 1 |
3) | Arduino USB Cable | – | 1 |
4) | LED | 5mm, 3.5V | 1 |
5) | Resistor | 330 Ohm | 1 |
5) | Breadboard | – | 1 |
6) | Laptop/PC | – | 1 |
7) | Jumper wires | – | As per need |
SW420 Pinout
Useful Steps
1) Connect the SW – 420 vibration sensor on the breadboard.
2) After that, connect D0 pin of SW-420 with Digital I/O pin 9 of the Arduino Uno.
3) After that, Connect the GND pin of SW-420 with the GND pin of the Arduino Uno.
4) After that, connect the Vcc pin of SW420 with the 5V pin of the arduino uno.
5) Connect an LED on the breadboard. join the cathode side of the LED with the arduino’s GND and the anode side with Digital I/O pin 13 of the arduino uno through a 330 Ohm resistor.
6) Connect your Arduino board with a laptop and burn the code given below on the arduino controller.
7) Test the sensor output using the serial monitor option.
Source Code
int led = 13;
int vs =9;
void setup()
{
pinMode(led, OUTPUT);
pinMode(vs, INPUT);
Serial.begin(9600);
}
void loop()
{
long measurement =vibration();
delay(50);
Serial.println(measurement);
if (measurement > 50)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
}
long vibration()
{
long measurement=pulseIn (vs, HIGH);
return measurement;
}
SW420 Arduino Code Explanation
The operation of the above source code is given below:
First of all we are declaring the Digital I/O pins 13 and 9 for the LED and the SW-420 data pin respectively.
int led = 13;
int vs =9;
Setup()
In this part of the code, we are defining the I/O parameters for our LED and SW420 sensors. Here, we have set the LED as the output by declaring it’s pinMode() as the OUTPUT. Similarly, we have set the SW420 data pin (D0) as the input by declaring it’s pinMode() as the INPUT. Then we are initializing the serial monitor to begin fetching the sensor readings through Serial.begin(9600).
void setup()
{
pinMode(led, OUTPUT);
pinMode(vs, INPUT);
Serial.begin(9600);
}
long vibration()
Here we have written a function block that solely operates as to fetch the values from the SW420. After declaring long variable “measurement”, we have set the arduino to fetch the sensors reading every time the D0 pin has a voltage on it (or in other words is HIGH) by using the pulseIn() command. After that we have set the “measurement” variable to be returned to another point in the code by incorporating it with the return() command.
long vibration()
{
long measurement=pulseIn (vs, HIGH);
return measurement;
}
loop()
In this part of the code, First the function block vibration() is called to fetch and store the values in the “measurement” variable. After a delay of 50ms (so that serial monitor can catchup with the sensors D0), the serial monitor prints the sensors reading stored in the “measurement” variable. After this, the condition is set for the LED to turn ON. The LED will go HIGH every time the “measurement” value goes above 50, if the “measurement” value is below 50 the LED will go LOW through digitalWrite() command.
void loop()
{
long measurement =vibration();
delay(50);
Serial.println(measurement);
if (measurement > 50)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
}
Working Explanation
The working of this circuit is as following. On powering up the circuit the circuit the sensor initially is in rest condition as seen on the serial monitor, meaning that the spherical/cylindrical metal contact within the sensing element is away from the metal contacts.
When the sensing element detects vibration the metal contacts oscillate and make the circuit with in the sensor. The sensor then outputs a control signal through the Data pin (D0) of the module. The output from the D0 pin can function as a input control signal for any microcontroller or amplifier circuit.
Applications
- Generally used in places such as AC/DC motor production industry. In order to keep an eye on any vibrational discrepancies in shaft operation.
- Also used for measuring fluctuating accelerations or speeds or for normal vibration measurement.
See Also: How To Make An IoT Web Server Using ESP32 WROOM With Arduino IDE | How To Make A Temperature Controlled DC Fan Using An NTC Thermistor | How To Use HC-SR04 Ultrasonic Sensor With Arduino Uno