SW-520D Vibration Tilt Sensor Features
The SW-520 sensor consists of two metal balls which switches as a trigger. When the switch is positioned horizontally, and when the sensor angle is less than 10°, the circuit is open (off state) and more than 10°, it is closed (on stated). But when the switch is positioned vertically, the circuit is open when the sensor angle is less than 45°, and close when the angle is more than 45°. To see exactly how this sensor works, read the datasheet. The SW-520D sensor is also dustproof and waterproof.
It can be used in camera rotation detection, cars and motors, household appliances, toys, etc.
You can download the datasheet of this module here.
SW-520D Angle Vibration Tilt Switch Datasheet
SW-520D Vibration Tilt Sensor Pinout
The SW-520 sensor has two pins for connecting and disconnecting the circuit.
Required Materials
Hardware Components
Software Apps
Interfacing SW-520D Vibration Tilt Sensor with Arduino
Step 1: Circuit
The following circuit shows how you should connect Arduino to SW-520D sensor. Connect wires accordingly.
We use a 10 resistor to pull-down pin 7.
Step 2: Code
Upload the following code to your Arduino.
/*
SW-520D-Tilt-Switch-Sensor
made on 07 Nov 2020
by Amir Mohammad Shojaee @ Electropeak
Home
*/
const int Pin=7;
void setup() {
pinMode(Pin, INPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = digitalRead(Pin);
if(sensorValue==HIGH){
Serial.println("ON-State");
delay(500);
}
else{
Serial.println("OFF-State");
delay(500);
}
}
Connect pin 7 to one side of the switch via pull-down. Connect the other side of the switch to Vcc. If the switch is close, pin 7 will be HIGH, and if the switch is open, it will be LOW.
See the output of Serial Monitor in the image below. Shaking the sensor opens and closes the switch.