TK62DIGITALbeginner

Tilt Sensor

A ball and two contacts. Upright or not, and nothing in between — which is exactly enough for a tilt alarm.

Comes in this kit — not sold separately

Specifications

TypeBall tilt switch
OutputDigital, open or closed by orientation
Pull-upFitted on the module
Supply voltage3.3 V or 5 V

What it is

A metal ball in a tube with two contacts at one end. Tilt it past roughly 30 degrees and the ball rolls off the contacts, opening the circuit.

It is a single axis and a single threshold — there is no angle and no direction, just above or below. For "has this been knocked over" or "is the lid open" that is the entire requirement, and it costs nothing.

For four directions in a plane, TK19 has one roller with four corner contacts. For an actual angle, you want an accelerometer, which is a different part and a lot more code.

Like every mechanical contact it bounces, and it also rattles when the board is moved rather than tilted. Require the same reading twice before believing it.

Tilt Sensor — front
Front
Tilt Sensor — back
Back
Tilt Sensor — side
Side

Pinout

  • GND (negative): Like the negative terminal (-) of a battery, connect to the control board's GND
  • VCC (positive): Like the positive terminal (+) of a battery, connect to the control board's 3.3V or 5V (this module supports both 3.3V and 5V)
  • NC (no connection): No actual circuit connection, included for unified interface, can be left unconnected
  • SIGNAL (signal output): Tilt detection output pin, connect to the control board's digital pin (e.g. Arduino D2 or Pico GPIO 0)
    • Outputs HIGH (HIGH/1) when tilt detected
    • Outputs LOW (LOW/0) when no tilt detected

Wiring

Tilt Sensor wiring

  1. GND → Control board GND
  2. VCC → Control board 3.3V or 5V
  3. SIGNAL → Control board digital pin (use the pin defined in your program)

Example

// Pin number: change this to match your wiring
#define TILT_PIN 2     // Arduino digital pin connected to SIGNAL (e.g. D2)
#define LED_PIN 13     // LED pin (Arduino built-in LED on pin 13, or external LED)

void setup() {
  // Initialize pin modes
  pinMode(TILT_PIN, INPUT);   // Set tilt sensor pin as input (to read detection state)
  pinMode(LED_PIN, OUTPUT);  // Set LED pin as output (to control LED on/off)
  
  // Start serial for debugging (9600 baud)
  Serial.begin(9600);
  
  Serial.println("Tilt sensor program started");
  Serial.println("LED on when tilt detected, LED off when level");
}

void loop() {
  // Read tilt sensor state
  int tiltState = digitalRead(TILT_PIN);  // Read sensor pin level: HIGH(1)=tilt, LOW(0)=level
  
  // Control LED based on detection state
  if (tiltState == HIGH) {
    // Tilt detected: LED on
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Tilt detected - LED on");
  } else {
    // Level state: LED off
    digitalWrite(LED_PIN, LOW);
    Serial.println("Level state - LED off");
  }
  
  delay(100);  // Brief delay to avoid reading too fast
}
Tilt Sensor running on an Arduino Uno

When it doesn’t work

It flickers when I move the board.
The ball is bouncing. Require the reading to be stable for 50 ms before acting on it.
It does not trigger until quite far over.
About 30 degrees is normal for a ball switch. If you need a smaller angle, use an accelerometer.
Which state is upright?
Depends which way you mounted it. Read it in both positions once and write down which is which.

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