TK19DIGITALbeginner

4-Direction Tilt Sensor

One metal roller in a square switch with four corner contacts, on a TinkerBlock board: tip an edge down and the roller joins that side's two lines. Your board finds which pair by holding one line LOW and reading who follows. Four answers and none, no angle, and four red LEDs that light when a line is held LOW.

Comes in this kit — not sold separately

Specifications

TypeFour-direction tilt switch: one roller, four corner contacts. It joins two neighbouring lines, never a line to GND
SwitchRB-6635S-1T, 6 × 6 × 3.5 mm SMD, in the upper middle of the board
Directions4 plus none: left edge down joins A–B, top B–C, right C–D, header edge D–A. A–C and B–D never join
Reading itA scan: hold A LOW and read B and D, then hold C LOW and read them again. Every line INPUT_PULLUP otherwise, never OUTPUT HIGH
LevelNot a reading: the roller stays where it last rolled, and a corner can read none
Indicators4 red LEDs, one per line, each with 1 kΩ from VCC. Lit only while its line is held LOW: about 3 mA from 5 V, 1.3 mA from 3.3 V
Supply3.3 V or 5 V on VCC, matching your board: 3V3 beside an ESP32, ESP32-S3 or Pico, 5V beside an Uno. VCC feeds only the LEDs
Pins to wireAll 6: GND, VCC and four GPIOs for A, B, C and D. No NC pin
Header6-pin right-angle male, 2.54 mm pitch: GND, VCC, A, B, C, D, with GND on the square pad
Board22.4 × 30.4 mm, two 4.8 mm mounting holes 16 mm apart
In the box1 × TK19 block. It also ships inside the TinkerBlock kits

What it is

A square tilt switch with a metal roller inside, four red LEDs, and a six-pin header. Tip one edge of the board down and the roller rolls to that side of its cell and joins the two contacts there. Each contact is one of the lines A, B, C and D, so the four edges are four pairs: A–B, B–C, C–D and D–A.

The TK19 at an angle: a black board with a gold border, a black square tilt switch in the upper middle with two bent legs out of each side, four small LEDs near the left and right edges beside those legs, small resistors above and below the switch, a printed tilt icon between two big mounting holes, and six right-angle header pins pointing out past the bottom edge.
The TK19. The switch is the black square; each LED beside it belongs to one leg.

It is not an accelerometer. It has four answers and none, no angle, and it cannot say level: the roller stays wherever it last rolled. For "which edge is down" or "has this box been tipped over", that is enough.

The page this replaces said it was four balls in four tubes, that each pin can be read on its own, that a flat board is a neutral state, and that two sides can both be closed near a diagonal. None of that is true of this switch.

You cannot read it like a button

Nothing on the board goes to GND. The roller only joins two lines to each other, so four pins set to INPUT_PULLUP read HIGH whichever way it leans. Your board finds the pair with a small scan:

  1. Hold A LOW, read B and D. B LOW: left edge down. D LOW: header edge down.
  2. Let A go, hold C LOW, read B and D. B LOW: top edge down. D LOW: right edge down.
  3. Let everything go.

A released line is always an input with its pull-up, never an output driven HIGH, because the roller could join it to a line held LOW.

Which pin is which

Parts up, header at the bottom, reading left to right:

GNDto your board's GNDthe square pad: count from here. Reaches nothing on the board; it is the common ground
VCCto 3V3 or 5Vyour board's logic voltage. Feeds the four LEDs only
Ato a GPIOlower-left leg of the switch
Bto a GPIOupper-left leg
Cto a GPIOupper-right leg
Dto a GPIOlower-right leg

The back prints TK19 4-DIRECTIONS TILT SENSOR and no pin names. Turned over, the square pad is on the right, and it is still GND.

The lights, and VCC

Each line has a red LED from VCC through 1 kΩ, lit only while that line is held LOW. With only power wired they stay dark. Holding a line LOW lights its LED at:

Your boardVCC toPer lit LED
Arduino Uno5Vabout 3 mA
ESP32, ESP32-S3, Pico3V3about 1.3 mA

Never 5V beside a 3.3 V board. The currents are worked out from a red LED's typical forward voltage rather than measured.

Wiring, in three lines

  1. GND to your board's GND.
  2. VCC to 5V on an Uno, 3V3 on an ESP32, ESP32-S3 or Pico.
  3. A, B, C, D to four GPIOs: D2 to D5 on an Uno, GPIO 25, 26, 27 and 32 on an ESP32, GPIO 4 to 7 on an ESP32-S3, GP10 to GP13 on a Pico.

Example

// Uno: 2 3 4 5. ESP32: 25 26 27 32. ESP32-S3: 4 5 6 7. Pico: 10 11 12 13.
const int PIN_A = 4, PIN_B = 5, PIN_C = 6, PIN_D = 7;

void releaseAll() {             // every line an input with its pull-up
  pinMode(PIN_A, INPUT_PULLUP);
  pinMode(PIN_B, INPUT_PULLUP);
  pinMode(PIN_C, INPUT_PULLUP);
  pinMode(PIN_D, INPUT_PULLUP);
}

void holdLow(int pin) {         // the only way a line is ever driven
  digitalWrite(pin, LOW);
  pinMode(pin, OUTPUT);
}

const char* scanTilt() {
  releaseAll();
  holdLow(PIN_A);
  delayMicroseconds(10);
  bool ab = digitalRead(PIN_B) == LOW;
  bool da = digitalRead(PIN_D) == LOW;
  releaseAll();
  holdLow(PIN_C);
  delayMicroseconds(10);
  bool bc = digitalRead(PIN_B) == LOW;
  bool cd = digitalRead(PIN_D) == LOW;
  releaseAll();
  if (ab) return "left";
  if (da) return "header";
  if (bc) return "top";
  if (cd) return "right";
  return "none";
}

void setup() {
  Serial.begin(115200);
  releaseAll();
}

void loop() {
  Serial.println(scanTilt());
  delay(200);
}

Where to start

The handbook below is eleven short articles, each with a working figure. The first read is the whole build in six wires and one scan. No line goes to ground explains why the scan is needed at all.

If the LEDs puzzle you, the lights wait for you. If a level board reads a side, level is not a reading. For a project, a tip-over alarm is a box that knows it has been knocked over.

When it doesn’t work

Why do all four pins read HIGH whichever way I tip it?
Because the switch never touches GND. The roller only joins two of the four lines to each other, so a pin set to INPUT_PULLUP sees nothing change. Your board has to hold one line LOW and read which neighbour follows it down: hold A LOW and read B and D, then hold C LOW and read B and D again. That finds every pair.
Why do the LEDs stay dark when I power it and tilt it?
Each LED hangs from VCC onto one line and lights only when your board holds that line LOW. With only VCC and GND wired, nothing holds any line, so they stay dark. The handbook's second build holds the pair on the low side LOW between scans, and then the two LEDs on the downhill edge light.
What does it read when the board is flat?
Usually whatever it read last. The roller is not sprung back to the middle, so level keeps the last side, or reads none if the roller stopped between contacts. The switch has no way to say level. Mount the block tipped towards one edge, or on its edge, if you need a resting state.
Can two directions read at once?
Not two opposite ones: one roller cannot be on two sides. Tipped towards a corner, the roller lands on one neighbouring side or the other, or rests against the single contact in the corner and joins nothing.
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. VCC feeds only the four LEDs, but each LED hangs from VCC onto a line your board's pin is holding, and 5V beside a 3.3 V pin can lift that pin above what it is meant to see.
It flickers when I move it.
That is the roller rattling. Believe a reading only after the same one five times in a row, 10 ms apart. The switch maker gives no bounce time, so 50 ms is a margin chosen for this book, and the sketch lets you change it.

The 4-direction tilt sensor handbook

11 articles · about 50 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.

What is on the board

2 articles

Six pins, all of them wired, and a small square switch with a roller inside that joins two of its four lines whenever one edge of the board goes down.

How it is wired

3 articles

Why no pin reads LOW by itself, why the four red lights stay dark until your board pulls a line LOW, and why VCC has to match your board.

Reading it

2 articles

Six wires and a scan that prints which edge is down, then the same scan lighting the two LEDs on the low side.

What it cannot tell you

2 articles

Level is not a reading, a corner can read nothing, and a knock looks like a tilt until the sketch waits for the roller to settle.

Using it

2 articles

A box that knows it has been tipped over, and the short list of reasons a tilt reads nothing.

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

Community

Questions about this product

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

Ask a question ↗

4-Direction 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