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 Tilt Sensor – AT407 basic tilt switch can easily be used to detect orientation. Inside the can is a ball that make contact with the pins when the case is upright. Tilt the case over and the ball does not touch the pins, thus not making a connection. Tilt sensors can also 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. ?

, , ,

Related Post

Getting Started with Colour Sensor Module (SN-COLOUR-MOD)

Getting Started with Vibration Sensor Module (Normally Off) (SN-VIBRATE-MOD)

Getting Started with IR Distance Click

Getting Started with Temperature Sensor (Celsius) (SN-LM35DZ)

Leave a Reply

Your email address will not be published. Required fields are marked *