Tilt Switch Sensor – AT407
This AT407 tilt switch can easily be used to detect orientation. Inside the body of this device are a pair of balls that make contact with the pins when the case is upright. Tilt the case over and the balls will no-longer touch, and a connection will longer exist.
There are numerous uses for these basic sensors, but keep in mind you might need to use some debouncing code, as the sensor isn’t immune to small vibrations and such.