Tilt switch (SW-520D)
The rolling-ball tilt sensor, SW-520D and its twins: a little metal can with two legs and a conductive ball rolling between two contacts inside.
Stand it upright and the ball sits on both contacts, closing the circuit; tip it past about fifteen degrees and the ball rolls off one of them, opening it. There is no chip, no supply and no output pin. It is a switch that gravity operates.
Pins
| Pin | What it does |
|---|---|
1 |
One contact. |
2 |
The other contact. |
Properties
settle: how long the ball takes to stop rattling once tipped, 20 ms by default; 0
turns the chatter off.
While it runs
Click to tip it over; it stays tipped, because a box you knock over stays knocked over.
What the model gets right
It is electrically the slide switch with two legs instead of three and a physical story behind it: closed, the pins are a low-resistance contact passing current either way; open, both are high impedance. The chatter is real and on by default, because a ball rolling onto a contact is the noisiest switch in a kit. A hundred milliseconds of it is not unusual while the ball settles, which is why every real tilt-sensing sketch debounces in software over tens of milliseconds rather than microseconds.
What it does not model
No angle sensitivity beyond the toggle itself. The part is upright-and-closed or tipped-and-open, not a continuous tilt reading. The "about fifteen degrees" in the description is a fact about the real part, not something this model measures: there is no angle in it at all, only a click.
The chatter is a fixed pattern, not a rolling ball. Every tip produces the same
three makes and breaks, evenly spread over settle and ending where the ball landed.
It is not random, it does not decay, and it does not differ between one tip and the
next the way the pushbutton's does. The default settle is
20 ms, at the short end of what a real can does; the hundred milliseconds the
description mentions is not the default here.
Common mistakes
Debouncing in microseconds the way a clean digital signal would need. A tilt switch's settle time is measured in tens of milliseconds, and a sketch that reacts to the first edge rather than waiting it out will fire many times for one tip.
See it in action
Tilt alarm and STM32 tilt lamp both use this as the trigger. Open them at /templates.