Tilt Sensor

Z2M Part: EMS-00021-A

Detect tilt or orientation with tilt sensor.

Circuit Diagram
Circuit diagram for Tilt Sensor
Wire Connections & Pin Configuration

Wire Color Connections:

Yellow → Digital Pin 2 to Tilt sensor (one leg)
Black → GND to Tilt sensor (other leg)

Pin Configuration:

Arduino Digital Pin 2 → Tilt sensor (one leg)
Arduino GND → Tilt sensor (other leg)
Arduino Code
Edit
const int LED = 13;  // LED connected to pin 13
const int Tilt = 2;  // Tilt sensor connected to pin 2
int val = 0;         // Variable to store sensor value

void setup() {
  pinMode(LED, OUTPUT);  // Set LED pin as output
  pinMode(Tilt, INPUT);  // Set tilt sensor pin as input
  Serial.begin(9600);    // Initialize Serial Monitor
}

void loop() {
  val = digitalRead(Tilt);  // Read digital value from tilt sensor
  Serial.println(val);      // Print sensor value to Serial Monitor

  if (val == HIGH) {        // If tilt is detected
    digitalWrite(LED, HIGH); // Turn ON LED
  } else {
    digitalWrite(LED, LOW);  // Turn OFF LED
  }
}

Instruction Details

Wiring: Connect tilt sensor one leg to Digital Pin 2, other leg to GND. Internal pull-up enabled in code.
Library: Not required (built-in).
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: LED (Pin 13) turns ON when sensor tilted. Open Serial Monitor at 9600 baud to see 0/1 values. Tilt sensor to test.

How to Use

  1. Connect the required components as per the Pin Configuration above
  2. Open Arduino IDE and create a new sketch
  3. Copy and paste the code above
  4. Select your Arduino board and COM port from Tools menu
  5. Click the Upload button to upload the code to your Arduino
  6. Open Serial Monitor (if applicable) to see the output

Components Required

  • Arduino Uno
  • Tilt Sensor Module (Ball Switch)
  • Breadboard
  • Jumper Wires

Category: Sensors