Language: EN

medir-inclinacion-con-arduino-y-sensor-tilt-sw-520d

Measure tilt with Arduino and SW-520d tilt sensor

What is a tilt sensor?

A tilt sensor is a device that provides a digital signal if its inclination exceeds a threshold. This type of sensor does not allow you to know the degree of inclination of the device, it simply acts as a sensor that closes when a certain inclination is reached.

Formerly, these sensors were made by placing a drop of mercury inside a glass bulb, inside of which two conductors were housed. Upon reaching a certain inclination, the mercury drop would move, closing the contact between the two conductors.

Currently, for environmental reasons, almost all mercury sensors have been replaced by double-sphere Tilt sensors. There is a cylinder whose wall constitutes an electrical contact, while the other contact is located in the center of the base. By tilting the device enough, both spheres form a bridge between the two contacts, closing the circuit.

sw520d

Due to its operating principle, these sensors are sensitive to sudden movements and vibrations.

Price

SW-520D tilt sensors are inexpensive devices. We can find 10 vibration sensors for 1€ from international sellers on Ebay or AliExpress.

sw18020p

Electrical schematic

The electrical schematic that we need is as follows.

arduino-tilt-esquema

Assembly

While the assembly on a breadboard would be as follows.

arduino-tilt-montaj

Code example

The code needed to perform the reading is simple. We simply read the state of the sensor through the digital input, using the internal Pull Up resistor.

const int SensorPin = 2;
const int LEDPin = 13;

void setup() {
    pinMode(SensorPin , INPUT);
    digitalWrite(SensorPin , HIGH);    //activate the internal PULL UP resistor
    pinMode(LEDPin, OUTPUT);
}

void loop() {
    if (digitalRead(SensorPin))  {
        digitalWrite(LEDPin, HIGH);
    }  else  {
        digitalWrite(LEDPin, LOW);
    }
}

Download the code

All the code from this post is available for download on Github. github-full