Connecting tilt sensor with Arduino
A tilt sensor is a type of sensor that can detect the orientation or tilt of an object relative to the force of gravity. It works by measuring the change in angle of the object with respect to the vertical axis.
Tilt sensors can be found in various forms, such as simple mechanical switches, mercury switches, and electronic sensors. They are commonly used in applications that require the detection of tilting or changes in orientation, such as in construction equipment, automotive safety systems, robotics, and gaming controllers.
In addition to detecting tilt, some advanced tilt sensors can also measure the magnitude of the tilt angle and the rate of change in angle, which makes them useful for monitoring and controlling complex systems.
Components
1x Arduino Nano (or another Arduino module) $3.18 | |
1x Mini Breadboard $1.17 | |
1x Tilt sensor $1.92 | |
Dupont wires $1.61 |
How tilt sensor works
Tilt sensors are typically small in size, measuring just a few millimeters in length. They consist of one or two tiny conductive balls inside that can close the circuit with the lower metal pins of the cylinder.
When the conductive balls make contact, the circuit is completed, allowing the current to flow and functioning like a switch (in fact, they are operated in the same manner). However, when the sensor reaches a certain angle of inclination, the conductive balls no longer make contact, causing the circuit to open.
While it is not a new technology and has been around for a while, tilt sensors used to be made with a small amount of liquid mercury that acted as a conductor. As the mercury moved inside the cylinder, it would eventually close the circuit between a pair of contacts at the bottom.
Wiring schema
The process of connecting the tilt sensor with Arduino is simple and involves just two pins - one for ground and the other for the signal. Any digital pin on the Arduino can be used to make this connection.
You may attach tilt sensor to any object and it will determine whether the object is tilted or not. To test the tilt sensor, you can manipulate the angle of the sensor connecting it with dupont wires.
Arduino code
In our Arduino program, all we need is to read the data from the tilt sensor. The input will be in the form of a boolean value that represents the state of the sensor. When the sensor is tilted, the program will detect it and display a corresponding text on the serial monitor.
#define TILT_PIN 2
byte isTilted = LOW;
void setup()
{
pinMode(TILT_PIN, INPUT_PULLUP);
Serial.begin(115200);
}
void loop()
{
isTilted = isSensorTilted(TILT_PIN);
if (isTilted) {
Serial.println("Is tilted");
}
delay(100); // Small delay between readings
}
bool isSensorTilted(int pin)
{
return digitalRead(pin) == HIGH;
}
Conclusion
Tilt sensors are a useful type of sensor that can detect the orientation or tilt of an object relative to the force of gravity. Despite not being a new technology, tilt sensors are still widely used today due to their reliability, ease of use, and cost-effectiveness.
Credits
Official GitHub: https://github.com/hibit-dev/tilt-sensor
0 Comments