Bukit Mertajam, Penang

Getting Started with Tilt Sensor (SN-TILT)

Last Updated on 30 June 2017

This article is written by internship student Tan Khim Huang


The AT407 tilt switch can easily be used as a tilt sensor to detect orientation. Inside the can is a ball that makes a connections between the pins when the case is upright. Tilt the case and the ball does not touch the pins, thus not making a connection. These kinds of tilt sensors can be found in game controllers such as the Microsoft Sidewinder Freestyle Pro and Sony’s PlayStation 3 controller.


Electrical Rating : <6mA 24VDC Electrical Life: >50,000 Cycles
Contact Resistance: 1Ω
Solder Temperature: 250℃ 3 Seconds
Ambient Temperature: 0℃~100℃



Arduino IDE


Here are the connections between the sensor and the Arduino:


int inPin = 2;         // the number of the input pin
int outPin = 13;       // the number of the output pin
int LEDstate = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 50;   // the debounce time, increase if the output flickers
void setup()
  pinMode(inPin, INPUT);
  digitalWrite(inPin, HIGH);   // turn on the built in pull-up resistor
  pinMode(outPin, OUTPUT);
void loop()
  int switchstate;
  reading = digitalRead(inPin);
  // If the switch changed, due to bounce or pressing...
  if (reading != previous) {
    // reset the debouncing timer
    time = millis();
  if ((millis() - time) > debounce) {
     // whatever the switch is at, its been there for a long time
     // so lets settle on it!
     switchstate = reading;
     // Now invert the output on the pin13 LED
    if (switchstate == HIGH)
      LEDstate = LOW;
      LEDstate = HIGH;
  digitalWrite(outPin, LEDstate);
  // Save the last reading so we keep a running tally
  previous = reading;


Simple Tilt-Activated LED
Guide for the Tilt Sensor (inclinometer) with Arduino


Note: For further inquiry, please visit our technical forum as we seldom check the comment here. ?

Related Posts

Leave a comment