DIGITALbeginner

Tilt Sensor

An SW-520D ball tilt switch on a TinkerBlock board: two steel balls in a brass can that close the switch when its lead end, the board's left edge, is the lower one. It sits between VCC and SIGNAL with a 10 kΩ pull-down and a 100 nF, so left edge down reads HIGH, and a red LED lights while it is closed. It draws nothing while open, reads nothing definite near level, and VCC must be your board's logic voltage.

Comes in this kit — not sold separately

Specifications

TypeBall tilt switch with a pull-down and an indicator LED. Left edge down reads HIGH
SwitchSW-520D: two steel balls in a brass can, 12 × Ø5 mm, lying flat with its leads at the board's left edge
AngleCloses with the lead end about 10° below level and opens with the other end about 10° below, by one maker's sheet; in between it keeps its last state. Not measured on this block
AxisOne: across the board, left edge against right. Tipping the header or top edge down leaves it level
SIGNALThe switch's other end, with a 10 kΩ pull-down and 100 nF to GND. Open: 0 V, LOW. Closed: VCC, HIGH. Read it with INPUT, not INPUT_PULLUP
FilteringThe 100 nF hides openings under about 1 ms on a 3.3 V board, 0.5 ms on an Uno. Filter longer rattles in the sketch, 50 ms
SupplyYour board's logic voltage on VCC: 3V3 on an ESP32, ESP32-S3 or Pico, 5V on an Uno. A closed switch puts VCC straight on the pin
Current0 mA while open: VCC reaches only the switch. Closed, about 1.6 mA at 3.3 V and 3.5 mA at 5 V, from VCC, none from your pin. The switch is rated 12 V, 10 mA
IndicatorRed LED and 1 kΩ on SIGNAL: lit while the switch is closed, fed through it. Not a power light
Pins to wire3 of the 4: GND, VCC and SIGNAL. NC is connected to nothing on the board
Header4-pin right-angle male, 2.54 mm pitch: GND, VCC, NC, SIGNAL, with GND on the square pad
Board22.4 × 30.4 mm, two 4.8 mm mounting holes 16 mm apart. The front prints ACTIVE HIGH, the back ANGLE DETECTION
In the box1 × TK62 block. It also ships inside the TinkerBlock kits

What it does

It tells your board which end of the block is lower. The brass can across the top is a ball tilt switch: two steel balls loose inside, and the switch's contacts at the end with the leads. When that end is the lower one the balls roll onto the contacts and close the switch; when the other end is lower they roll away.

Drag to turn it
The TK62. The tilt switch is the brass can; its leads, and its closed end, are at the left. Turn it over for the back.

On this board the can lies flat, leads at the left edge, and the switch joins VCC to SIGNAL. A 10 kΩ holds SIGNAL LOW while it is open, so the left edge down reads HIGH, as ACTIVE HIGH on the front says. A 100 nF beside it smooths the shortest flickers, and a red LED on SIGNAL lights while the switch is closed. Open, the block draws no current.

The page this replaces called the resistor a pull-up (it is a pull-down), said it reads HIGH whenever it is tilted (it reads HIGH when one particular edge is down, and either way near level), put the switching angle three times higher than the one sheet that gives an angle, and wired SIGNAL to a Pico's GPIO 0.

Three things to know before wiring

  • Only left against right. The can lies across the board. Tipping the header edge or the top edge down leaves it level, and a level can keeps whatever it last read.
  • VCC is your board's logic voltage. A closed switch puts VCC straight on your pin: 3V3 on an ESP32, an ESP32-S3 or a Pico, 5V on an Uno.
  • Read it with INPUT. The pull-down is on the board. INPUT_PULLUP fights it, and on an Uno can leave the open level where the pin does not promise to read LOW.

Wiring, in four lines

  1. GND to your board's GND.
  2. VCC to 3V3 on an ESP32, ESP32-S3 or Pico; 5V on an Uno.
  3. SIGNAL to GPIO 4 on an ESP32-S3, GPIO 25 on an ESP32, D2 on an Uno, GP15 on a Pico.
  4. NC to nothing: it is connected to nothing on the board.

Then pinMode(pin, INPUT), and digitalRead(pin) is HIGH while the left edge is down.

Where to start

The handbook below is ten short articles, each with a working figure. The first read is the whole build in three wires and a few lines, and counting tips adds the filter a ball switch needs.

For how it works, read two balls in a can and which end is lower. If it reads the wrong thing, when it reads wrong. For four sides at once, the four-direction tilt sensor.

When it doesn’t work

Which way up reads HIGH?
Left edge down: the edge the brass can's two leads are at, seen from the front with the header at the bottom. The balls roll to that end and close the switch. Right edge down reads LOW.
It reads HIGH one time and LOW the next lying flat. Is it broken?
No. Flat, the can is level, and within about 10 degrees of level the balls stay wherever they last rolled. Level is not a reading on a ball switch. Mount it with one edge clearly down.
I tip it forwards and nothing happens.
The can lies across the board, so tipping the header edge or the top edge down only rolls it about its own length. Only the left or right edge going down tilts it.
At what angle does it switch?
Bailin's SW-520D sheet says about 10 degrees past level, either way; the sheet from the maker of this board's part gives no angle, and nobody has measured this block. Tip it slowly and watch the LED.
It flickers when the block is moved.
The balls bounce off the contacts. The board's 100 nF hides the shortest gaps; believe a change only after it has held for about 50 ms, which the handbook's counter does.
Should VCC go to 3V3 or 5V?
To your board's logic voltage: 3V3 on an ESP32, ESP32-S3 or Pico, 5V on an Uno. A closed switch joins SIGNAL straight to VCC, so 5 V on VCC is 5 V on a 3.3 V pin.

The tilt sensor handbook

10 articles · about 45 minutes

This page is the reference: what the part is, what it is made of, and the questions people arrive already asking. The handbook is the walk — the same part in the order somebody actually meets it.

The board

2 articles

Four pins of which three are wired, a brass can between VCC and SIGNAL, a 10 kΩ that holds SIGNAL LOW while it is open, a 100 nF beside it, and a light that shows it closed.

How it works

4 articles

Two balls that roll to the lower end, one axis that matters, a pull-down that makes it active high, and why VCC has to be your board's logic voltage.

Reading it

2 articles

Three wires and digitalRead, then the rattle: what the capacitor hides and what the sketch has to.

Using it

2 articles

A counter for something that tips back and forth, and the short list of reasons it reads the wrong thing.

Lessons using TK62

Each one is a working build, not a snippet.

Edit this page — content/modules/tilt-sensor.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Tilt Sensor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →