beginnerChapter 10 of 4520 min

10. Tilt Sensor

Learn the tilt sensor.

This lesson uses: Arduino UNO R3 board, TinkerBlock TK62 Tilt Sensor module, TinkerBlock TK01 XL LED module, jumper wires (or breadboard). Learn the tilt sensor. Outcome: tip the module so its left edge goes down and the LED turns on; tip it the other way and the LED turns off.

1. Wiring

  • TK62 tilt sensor: VCC → 5V, GND → GND, SIGNAL → D2, NC leave unconnected
  • TK01 LED: GND → GND, SIGNAL → D13

TK62 + LED wiring diagram

2. New sketch

  1. Arduino IDE: File → New (or Ctrl/Cmd + N) to create a blank sketch
  2. Confirm board and port are selected (same as Lesson 01)
  3. Type the code below into the default setup() and loop() yourself

3. Program structure

Same as last lesson: two fixed blocks setup() and loop().

  • setup(): Tell the board “pin 2 for reading the tilt sensor, pin 13 for the LED”; runs once.
  • loop(): Keep repeating “read pin 2 → if HIGH then LED on, else LED off → short delay”.

Type the code in; tip the module left edge down and the LED turns on, tip it right edge down and it turns off.

4. Code to write

Type the code below line by line into setup() and loop() (do not copy-paste; typing it yourself helps you remember):

lesson10.ino
// Tilt sensor on D2, LED on D13: output HIGH when tilted, LED on
#define TILT_PIN 2
#define LED_PIN 13

void setup() {
  pinMode(TILT_PIN, INPUT);   // D2 read tilt sensor
  pinMode(LED_PIN, OUTPUT);   // D13 control LED
}

void loop() {
  int state = digitalRead(TILT_PIN);   // TK62 is HIGH when tilted, LOW when level

  if (state == HIGH) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }
  delay(100);   // debounce
}
View on GitHub · workshop/10-tilt-sensor/arduino/lesson10/lesson10.ino @ v1.13

Program notes

Overall idea: Digital input on D2. The ball switch in the can closes when the module's left edge (parts up, header down) is lower than its right, and TK62 outputs HIGH, so the LED is on; with the right edge down it outputs LOW. Lying flat, the can is level and keeps whatever it last read. Same logic as button, touch, collision and other digital sensors.

CodeIn this lesson
digitalRead(TILT_PIN)Read the switch: left edge down = HIGH, right edge down = LOW
if (state == HIGH)If HIGH then LED on, else off

5. Hands-on

  1. After entering the code, click Verify (✓) to compile
  2. Click Upload (→) to upload to the board
  3. Tilt detection:
    • Tip the TK62 module left edge down: TK01 LED should turn on
    • Tip it right edge down: LED should turn off
  4. Try different tilt angles and see when it triggers

Expected result:

Tilt sensor effect

Note: If your kit has the TK19 4-Directions Tilt Sensor, you can try it; it can detect tilt in four directions (up, down, left, right).

Proceed to Lesson 11.

6. Common issues

SymptomWhat to do
LED does not turn on when tiltedCheck TK62 wiring VCC→5V, GND→GND, SIGNAL→D2; check TK01 SIGNAL→D13, GND→GND; tip the left edge down, not the header edge
LED always onThe module is resting left edge down, or lying flat after it was; tip it right edge down

Edit this page — content/guides/tinkerblock-workshop/10-tilt-sensor.mdx

Community

Questions about this product

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

This page covers several products. Choose yours to see the right 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 Projects and guides on the forum →