SW-18010P Motion Vibration Sensor review and code examples

This post reviews the SW-18010P motion vibration sensor. Here I review, test and provide code to use the sensor.

Overview of the Vibration Sensor

The SW-18010P vibration sensor is a small spring inside a metal casing. As the sensor vibrates or moves the spring will make contact with the metal casing and conduct through the sensor.

As this sensor is a simple circuit it will draw very little power and is ideal for a low power circuit.

The sensor has four pins, left to right they are, analogue out (AO), digital out (DO), ground (GND) and input voltage (VCC). The analogue out will give the raw data from the sensor module.

Digital out will be LOW when motion is detected above the set threshold and HIGH when none is. The threshold can be set by changing the onboard potentiometer.

Analogue out is the raw vibration level and will be 0 when large amounts of movement is detected and 1023 when no motion is detected.

Wiring it up to an Arduino

Here I am connecting first pin, the analogue output to analogue pin 0 on the Arduino.

I am also going to connect the digital out pin to the digital pin 7 on the Arduino. This will mean I can record both the analogue and digital output.

I also wire up VCC to the 5 volt output on the Arduino and the GND on the sensor to the GND pin on the Arduino.

Now I am ready to program the Arduino to monitor the sensor.

Programming the Arduino with the SW-18010P vibration sensor

I am going to program the Arduino to collect and print out both the analogue and digital signals. This can then be modified at a later date to only use one depending on your requirements.

#define ANALOG_IN_PIN 0
#define VIBRATION_SENSOR_PIN 7
int motionDetected = LOW;
int sensorVal = 0;

void setup() {
   Serial.begin(115200);
}

void loop() {
   motionDetected = digitalRead(VIBRATION_SENSOR_PIN);
   sensorVal = analogRead(ANALOG_IN_PIN);
   Serial.print("Anaologue: ");
   Serial.print(sensorVal);
   Serial.print(" Digital :");
   Serial.println(motionDetected);
   delay(100);
}

The first thing I do here is to create constants to hold the pins I have connected the data to. In addition to this, I also create two variables to store the results of getting the sensor values. In the setup I initialize the serial output so that I can output the data across serial to the computer.

In the loop I read the analogue and digital values and print them out. Once I have read and printed the values out I wait 100 milliseconds. Like many of these sensors the delay period will need to be adjusted depending on the level of vibration you want to measure. If you want to detect very small vibrations that last for a short period the delay will need to be reduced.

Final Review

This sensor is a nice little vibration/motion sensor that is easy to use with an Arduino. One of the benefits is that you have access to both the analogue and digital signal. In addition, you can use the onboard potentiometer to set the level that the digital signal will change. This makes it fit for a number of tasks regardless of whether you need a digital or analogue signal.

A benefit is that there are a number of different levels of sensitivity this sensor comes in. This means you can easily swap the component out and use a more/less sensitive one if required. The longer vibration sensor component means it is easier to bind or hold to something that is expected to move.

This is a very useful sensor for the price and I would buy it again.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.