Documentation

Documentation / SW-520D Tilt Ball Switch Vibration Sensor for Arduino, Raspberry Pi & ESP32 | ShillehTek Product Manual

SW-520D Tilt Ball Switch Vibration Sensor for Arduino, Raspberry Pi & ESP32 | ShillehTek Product Manual

ESP32manualMotionshillehtekTilt Sensortilt-switch-sw-520d-vibration-sensor

Overview

The SW-520D is a tiny tilt and vibration ball switch. Inside its metal can, a conductive ball bridges two contacts when the switch is roughly upright and rolls away to break the connection when it is tilted or shaken. That makes it a cheap, power-free way to detect orientation changes, knocks, and movement for alarms, toys, tilt-activated lights, and anti-theft triggers.

It reads just like a button on any Arduino, ESP32, Raspberry Pi, or Pico, so no special library or calibration is needed.

At a Glance

Type
Ball tilt switch
Detects
Tilt, shake, vibration
Reads Like
A button
Power
None required
Leads
2 (non-polarized)
Default
Closed when upright

Specifications

Parameter Value
Type SW-520D conductive ball switch
Function Closes upright, opens when tilted
Max Voltage ~12V (use at logic levels)
Max Current ~20 mA
Body Cylindrical metal can, 2 leads
Power Passive, no supply needed
Response Instant, somewhat bouncy

Wiring Guide

Arduino / ESP32 Wiring

Wire it like a push button using the internal pull-up. One lead to a digital pin, the other to ground.

Switch Lead Goes To
Lead 1 Digital pin (e.g., D2), INPUT_PULLUP
Lead 2 GND
Tip: The output is naturally bouncy as the ball rolls. Debounce in software, or treat any change within a short window as movement rather than reading a clean level.

Code Examples

Arduino

tilt.ino
// SW-520D tilt switch on pin 2
const int TILT = 2;
int last = HIGH;

void setup() {
  pinMode(TILT, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  int s = digitalRead(TILT);
  if (s != last) {
    Serial.println(1);  // movement detected
    last = s;
  }
  delay(50);
}

Frequently Asked Questions

Does it need power?
No. Like a reed switch or button it is passive. Wire it between a GPIO pin with a pull-up and ground, and read the state in code.
Is it open or closed when upright?
Upright, the internal ball bridges the contacts so it is closed (conducting). Tilt it past a certain angle and the ball rolls away, opening the circuit.
Can it measure angle?
No, it is only on or off. For actual angle or orientation, use an accelerometer such as an MPU6050 or ADXL345.
Why is the signal noisy?
The rolling ball makes and breaks contact rapidly, which is great for detecting vibration but bouncy for clean reads. Debounce in software for stable on/off detection.
Does mounting orientation matter?
Yes. The trigger angle depends on how you mount it. Experiment with the angle and direction so it reliably switches for your specific motion or tilt.