What it is: The SW-520D is a ball tilt switch — a tiny tube with a rolling ball that closes two contacts when upright and opens them when tilted. It's the cheapest way to detect orientation, used in toys, alarms and "shake to wake" gadgets.
How it works: It's just a switch, so you wire it like a button: one side to the GPIO with the internal pull-up on, the other to GND. Upright, the ball bridges the contacts and the pin reads LOW; tilt past ~15° and it opens, reading HIGH.
Wiring:
SW-520D pin 1 -> GPIO10
SW-520D pin 2 -> GND
(if your module has VCC/GND/SIG headers: VCC -> 3V3, GND -> GND, SIG -> GPIO10)
OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5
Libraries: only "Adafruit SSD1306" and "Adafruit GFX Library".
On screen / Serial: "FLAT" when upright, "TILT!" when tipped. Rock the board to toggle it.
Gotchas: The ball bounces, so the reading can flicker at the tilt threshold — add a short debounce if you act on it. Which state is "flat" depends on how you mount it; adjust the comparison to match your orientation.