CCNAP

TPL-26Templates/Tilt Switch

Tilt Switch

Read a ball-and-tube tilt switch to detect orientation changes, printing the state to the Serial Monitor. The simulator alternates the switch on a timer since it has no clickable tilt control.

Open in Playgroundbeginner · switch · digital input · serial · tilt
beginner

FIG. 1Tilt Switch · circuitTPL-26

02Sketch

sketch.inoArduino C++
20 lines
// Tilt Switch — Orientation Detector
// Prints whether the switch is level or tilted.
// Note: this simulator's tilt switch has no clickable orientation control,
// so it alternates automatically on a timer to demonstrate the wiring and
// code — on real hardware it reacts to how you physically tilt the board.

const int TILT_PIN = 2;

void setup() {
  pinMode(TILT_PIN, INPUT);
  Serial.begin(9600);
}

void loop() {
  bool tilted = digitalRead(TILT_PIN) == HIGH;

  Serial.println(tilted ? "TILTED!" : "level");

  delay(200);
}

03Components

  • 01Arduino Uno
  • 02Tilt Switch

04Wiring

Component pinArduino pin
Tilt Switch VCC5V
Tilt Switch GNDGND
Tilt Switch OUT (Signal)Pin 2

All templates

Ready when you are

Have a circuit in mind?

No hardware, no installs — a browser is enough.