Tilt Sensor
It is a device used for knowing the planar movement. Although they are available in various types, their basic function remains the same. Their function is to detect the plane shift from horizontal to vertical and sent of a signal when it happens. There are modules which could sense even small plane shifts.

Working principle
A Tilt switch is similar to a normal switch except that the current flows through it only when it is tilted at a certain angle a blob of mercury is placed in a small glass tube with two metal contacts coming out. When the sensor is held upright, the mercury will make contact with both the terminals and the switch is closed.
When the sensor is tilted in either direction, the mercury goes off contact with the terminals and the switch is open.

Types of Tilt Switch:
Mercury switches
It use a drop of mercury in the tube. The sensor is positioned with respect to gravity forces so that the mercury moves away from the contacts when the switch is open. A change in the orientation of the sensor causes the bead to roll in the tube, touching both the contacts and closing the switch.

Advantages
- Mercury tilt switches are their low cost and ease of use.
- Disadvantages include the toxic nature of the material and that they can perform only on/off functions.
Ball-in-cage switches
A small metal ball held in a housing unit with two or more contacts. When the housing is tilted the ball shorts the two electrical contacts, turning off the switch. Multiple contacts can be added to this device so that tilt direction can be determined.

An advantage of ball-in-cage switches is that this type of switch can have multiple contacts so that the direction of the tilt can be determined, In addition, ball-in-cage products are less toxic than mercury switches.
Force balance sensors

Gravity-referenced sensors often used in tilt meters. The sensor consists of a balance system in which a pendulous mass is suspended between two position detectors. When the mass tries to move in the direction of tilt due to the force of gravity, the position of the mass is detected by the position sensors and induces a current change.
Solid state sensors

Micro-electromechanical systems (MEMs). They are miniature devices with movable proof mass plates that are attached through a mechanical suspension system to a reference frame.
Electrolytic tilt sensors

Capable of producing extremely accurate pitch and roll measurements in a variety of applications. They function by using a glass or ceramic cavity filled with an electrically conductive fluid. As the sensor is rotated an imbalance is created between the electrodes. The imbalance of one of the electrodes is proportional to the angle of rotation.
Capacitive tilt sensors

Designed to take noncontact measurements of tilt and inclination. Capacitors can operate both as sensors and switches. Capacitive sensing is independent of the base material and relies on variation of capacitance when the geometry of the capacitor is changing.
Features
- Contact Rating: 12V
- Contact Resistance: 10M ohm
- Capacitance: 5PF
Specification
- Model number: SW-520D
- Type: Ball
- Material: Housing and cover: PE heat shrinkable tubing/ Ball: Stainless steel, gold-plated / Guide pin: Brass, gold-plated / Copper tube: Brass
- Shape: Round
- color: Black / Gray
Link to datasheet:
http://funduino.de/DL/SW-520D.pdf
Do’s:
- Always take sensor from sides only.
- Read the specifications before using any sensor.
Don’t’s:
- Do not make wrong connections like, power supply to gnd. It may damage the sensor.
- Do not put hands of circuit elements, the static energy from your hands can damage the sensor.
- Do not excerpt force on sensor.
Storing Instructions:
It must be handle with care, because static energy may damage the sensor.
Advantages:
- Switch signals simple, circuit is simple in design.
- Economic price.
- It is very cost effective.
Disadvantages:
- Due to small tilt angle, it may give false switching.
Schematics:

Interfacing with Arduino:

Arduino Code:
const int ledPin = 13;
void setup()
{
pinMode(ledPin,OUTPUT);
pinMode(2,INPUT);
digitalWrite(2, HIGH);
}
void loop()
{
int digitalVal = digitalRead(2);
if(HIGH == digitalVal)
{
digitalWrite(ledPin,LOW);
}
else
{
digitalWrite(ledPin,HIGH);
}
}
Applications:
- Robotic Arm
- Security System
- Construction Equipment
FAQ’s:
Q1. Does the number of balls in different types of tilt switch vary?
Ans. Yes, it will depends on the manufacturer.
Q2. How many balls are there in SW-520D?
Ans. It has two balls.
Reference:
http://www.instructables.com/howto/tilt+switch/
http://funduino.de/DL/SW-520D.pdf
https://components101.com/sensors/sw-520d-tilt-sensor-module
https://www.elprocus.com/tilt-sensor-types-working-principle-and-its-applications/
http://osoyoo.com/2017/07/31/arduino-lesson-sw-520d-tilt-sensor/