Part

Tilt switch

A ball that rolls off the contacts when you tip it. Click to tip it.

See every part
  • 2 pins
  • 1 setting
  • In 2 projects
  • In 3 lessons
12
Drawn live by the editor's own code, at the size you see it.
At a glance

The Tilt switch in brief

What it is, and every setting the properties panel gives it.

The SW-520D tilt switch is a small metal can with two legs and a conductive ball inside. Upright, the ball rests across both contacts and the switch is closed; tip it past about fifteen degrees and the ball rolls off, opening it. There is no chip and no supply pin, so it wires like a button: one leg to ground and the other to an Arduino Uno or ESP32 pin with INPUT_PULLUP, reading LOW while upright and HIGH when tipped. Mokxi’s part is a 50 milliohm contact when closed and two floating pins when open. Click it to tip it and it stays tipped. The ball rattles before it settles, so every tip produces a burst of makes and breaks spread over the settle property, 20 milliseconds by default, with 0 turning it off. That is the mistake it is there to show: a sketch that acts on the first edge fires several times for one tip; the fix is a debounce of tens of milliseconds. There is no angle in the model, only upright or tipped, and the chatter is the same fixed pattern every time.

Family
Inputs
Pins
2
settle
20
how long the ball takes to stop rattling once tipped, 20 ms by default; 0 turns the chatter off.
Pins

2 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
1
One contact.
2
The other contact.
How to use it

How to use the SW-520D tilt switch with an Arduino

One leg to a digital pin, the other to GND, and INPUT_PULLUP on the pin. Upright, the ball closes the switch and the pin reads LOW; tipped, the pull-up takes it HIGH. In the tilt alarm here the switch is on pin 2 and an arcade button on pin 3 resets the alarm.

Do not believe the first edge. The ball rattles as it lands, so the sketch only accepts a reading once it has held for 50 milliseconds, and then latches the alarm so that standing the switch back up does not silence it. Only a press of the button on pin 3 resets it, which is what an alarm is for.

Part pin
Board pin
One leg
Pin 2
The other leg
GND
Arduino Uno: tilt alarmlive0.000 s 0.00x
Hold the button
This is the simulator itself, running here. Click anything to open it in the editor.
Waiting for the reading to hold, from the tilt alarm
int raw = digitalRead(TILT);
if (raw != lastRaw) {
  lastRaw = raw;
  changedAt = millis();
} else if (raw != tilt && millis() - changedAt >= SETTLE_MS) {
  tilt = raw;
  if (tilt == HIGH && !alarm) {
    alarm = true;
  }
}
How it is modeled

What is true about the Tilt switch, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

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.

Not modeled

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.

From Tilt switch (SW-520D), in full.

Projects

See the Tilt switch in a project

2 built-in projects use it. Each opens in the editor, already wired.

Boards

The boards it is shown on

Each of these 2 boards has a built-in project with the Tilt switch in it.

Wire up the Tilt switch

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.