Tilt Sensor

Tilt Sensor Interface

Introduction

This experiment shows how to use a tilt sensor with an Arduino to detect changes in orientation.

Tilt Sensor

Components Needed

Circuit Setup

  1. Connect the tilt sensor's output to a digital input pin (e.g., D2) on the Arduino.
  2. Connect the LED to a digital output pin using a 220-ohm resistor in series.

The LED will turn on when the sensor detects a tilt.

Tilt Sensor Circuit Setup

Code for Tilt Sensor

Upload the following code to your Arduino to detect a tilt:


const int tiltPin = 2;
const int ledPin = 13;

void setup() {
  pinMode(tiltPin, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int tiltState = digitalRead(tiltPin);
  if (tiltState == HIGH) {
    digitalWrite(ledPin, HIGH);  // Turn on LED when tilted
    Serial.println("Tilt Detected!");
  } else {
    digitalWrite(ledPin, LOW);   // Turn off LED when upright
    Serial.println("No Tilt");
  }
  delay(500);
}
            

Explanation

The tilt sensor detects when the orientation changes and sends a signal to the Arduino, which turns on the LED and prints a message on the Serial Monitor.

Troubleshooting