Getting Started with Tilt Sensor (SN-TILT)

Last Updated on 30 June 2017

This article is written by internship student Tan Khim Huang


INTRODUCTION

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.

SPECIFICATION

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

HARDWARE REQUIREMENT

SOFTWARE REQUIREMENT

Arduino IDE

HARDWARE SETUP

Here are the connections between the sensor and the Arduino:

SAMPLE CODE

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);
  Serial.begin(9600);
}
 
void loop()
{
  int switchstate;
  reading = digitalRead(inPin);
  Serial.println(reading);
 
  // 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;
    else
      LEDstate = HIGH;
  }
  digitalWrite(outPin, LEDstate);
 
  // Save the last reading so we keep a running tally
  previous = reading;
}

REFERENCES

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

VIDEO

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

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorail

Display Temperature and Humidity on OLED using DHT22 and Arduino
Getting Started With Teensy Using Arduino IDE
Night Light
Arduino Device Tracker Using GSM GPS SIM7600E Module
Chocolate Box with Touch Sensor and Arduino
Scroll to Top