Tilt Sensor
Tilt sensors allow you to detect orientation or inclination. The sensor tested here is a very basic module that just has a rotating metal ball inside a container. The line closes when the metal ball completes the circuit on a tilt. In all other cases the line is open. So this is a binary sensor stating whether the object is tilted or not. It does not give the degree of the tilt.
Circuit
Arduino | Sensor |
5V | Middle Pin |
GND | Last Pin |
A0 | S Pin |
void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: int angle=analogRead(A0); if(angle>1) { Serial.println("tilted"); } else Serial.println("Not Tilted"); delay(1000); }