SW-520D Tilt Sensor Module Featurs
A SW-520D Tilt Sensor is an electronic device that detects the orientation of an object and gives its output High or Low accordingly. Basically, it has a metallic ball inside it which moves and makes the circuit. The sensor’s sensitivity is at 10 degrees tilt.
This module has two output pins for each path. When tilt angle is more than 10 degree, the output is low.
Note
The output is on trigger mode.
You can download the datasheet of this module here.
SW-520D Tilt Sensor Datasheet
SW-520D Tilt Sensor Module Pinout
This sensor has 4 pins:
- VCC: Module power supply – 5-12 V
- GND: Ground
- D01: Digital output for sensor 1
- D02: Digital output for sensor 2
You can see the pinout of this module in the image below.
Required Materials
Hardware Components
Software Apps
Interfacing SW-520D Tilt Sensor with Arduino
Step 1: Circuit
The following circuit shows how you should connect Arduino to this sensor. Connect wires accordingly.
Step 2: Code
Upload the following code to Arduino.
/*
SW-520D-2-Way-Angle-tilt-Sensor
made on 20 oct 2020
by Amir Mohammad Shojaee @ Electropeak
Home
*/
const int DO1=2;
void setup() {
pinMode(DO1, INPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = digitalRead(DO1);
if(sensorValue==LOW){
Serial.println("DO1 more than 10 degree");
delay(1000);
while(sensorValue==HIGH){}
}
else{
Serial.println("DO1 less than 10 degree");
delay(1000);
}
}
In this code, we used the first digital output to measure tilt. When tilt is less than 10 degrees, “DO1 less than 10 degree”, and more than 10 degrees, “DO1 more than 10 degree” appears on the Serial Monitor. The tilt is measured in one second intervals.
The output is as follows. As you see, the tilt has been more than 10 degrees for more than 5 seconds.