Source: https://mokxi.com/parts/tiltswitch
Updated: 2026-11-10

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

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

Hold the button

This is the simulator itself, running here. Click anything to open it in the editor.

Open this project in the editor Read the full tutorial

Waiting for the reading to hold, from the tilt alarm

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.

Lessons

## Where it turns up in a lesson

3 lessons place it in their own circuits.

### Learn articles

3 lessons

- Arduino 2D Array: Rows, Columns and Strings
- DIY Rhythm Game Controller: Guitar and Dance Pad
- Arduino Tilt Sensor (SW-520D): Wiring and Code

Boards

## The boards it is shown on

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

- Arduino Uno R3
- STM32F411 Black Pill

More parts

## The rest of the bench

Every one of these is drawn and simulated the same way.

Full-size breadboard

A real 0.1 inch grid with the rails and the center channel, 63 columns wide.

Jumper wires

Drag from any pin or hole to any other. Corners snap, and you can drag them.

Power

A supply rail at the voltage you choose.

Ground

The other end of every circuit.

LED

Lights when current flows. Five colors, and the brightness is what your eye would see.

Filament lamp

A tungsten bulb in a holder: an inrush when it is switched on cold, tens of milliseconds to warm up, and dim on half its voltage.

Resistor

Any value you like, with the color bands drawn to match.

ESP32-C3-DevKitM-1

A RISC-V board that runs your firmware at 160 MHz on the real memory map.

Pushbutton

A 12 mm tactile switch. Hold it while the simulation runs.

Raspberry Pi Pico

The RP2040 board on our own Cortex-M0+ core. Pick a program and press Run.

Raspberry Pi Pico W

Raspberry Pi Pico W (RP2040). The same board and the same pinout as a Pico, with the CYW43439 on it. The WiFi is simulated (no radio; real internet through the Cloud panel’s switch), and the on-board LED, which hangs off that chip rather than off GP25, is driven through the same path. Everything else is the Pico.

Raspberry Pi 4 Model B

Raspberry Pi 4 Model B: the 40-pin header, driven by main.py with RPi.GPIO or gpiozero.

See every part

## Wire up the Tilt switch

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

Start building free Open the editor
