SW-420 Motion Vibration Sensor Review and code examples

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

Overview of the Vibration Sensor

This motion vibration sensor detects small movements and reports this back as a digital signal. This digital signal represents whether there is motion above the configured value or not.

The amount of motion to trigger back a HIGH (true, motion is detected) is set by using the onboard potentiometer. By changing the potentiometer the level of motion required to trigger is changed. Looking at the sensor face on, turning clockwise will increase the level of motion needed. Turning this anticlockwise will reduce the level of motion needed.

There are two LED’s present on the sensor, the left LED is lit when no motion is detected according to the sensor. When the digital out reports HIGH (motion detected) this left LED will not be lit, when it reports LOW it will be lit. The right LED is the power indicator and will be lit all the time the sensor has power. If this is not lit then you will want to check your circuit for power.

To confirm you are turning the potentiometer the correct way you can use the left LED to help. When turned fully anticlockwise the LED will never be lit showing that all motion is detected. When turned fully clockwise the LED will be always be lit no matter the amount of motion, showing no motion is detected.

To set the level of detection you will want to set the potentiometer fully anticlockwise. Then slowly turn it clockwise until it has been set to the level you require.

Wiring it up to an Arduino

Here the sensor only requires three pins to connect to the Arduino. As in the diagram to the left the three pins are labelled DO, GND and VCC. These relate digital out, ground and voltage common collector respectively.

In the diagram I wire up both the 5V Arduino line to VCC and GND to the ground pin. The digital out pin is connected to Pin 3 on the Arduino. This however can be connected to any digital pin of the Arduino.

Pin 3 will be set into input mode using the Arduino IDE so that we can read the value from the sensor. This pin will be HIGH when motion is detected and low otherwise.

Programming the Arduino

Since the vibration sensor is triggered when the motion reaches the configured value reading this is simple. You only need one digital pin on the Arduino to check its output. In the below Arduino code I read the digital pin 10 times a second printing the value of the pin.


int motion_detected = LOW;

void setup() {

void loop() {
 motion_detected = digitalRead(VIBRATION_SENSOR_PIN);

You can improve this by taking action only if motion has been detected. Possibly triggering some kind of alarm with a piezo or lights.

Final Review

The sensor works well to detect motion at any level. Using the onboard potentiometer you can easily define at what level you want the device to trigger. This has a disadvantage as you need to manually set the detection level and only have a binary check of whether its detected or not.

You will need to have a quick loop checking whether motion is detected depending on the amount of motion you want to detect. For detecting short periods of motion this loop will need to be quite fast.

If you are looking for a vibration/motion sensor that returns an analogue signal you will want to look at the 801S Wide Range Vibration Sensor. This has an improvement over the SW-420 Motion Vibration Sensor as it gives both a digital and anlogue pin out.

Overall this is a nice cheap movement sensor that needs little electronics to get to work. Since it provides a simple on/off detection it can be easily joined with other electronics.

Would buy again.


Leave a Reply

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