In this example we take a look at the KY-017 Mercury Tilt Switch Module and connect this to a Raspberry Pi.
This info is from wikipedia
Mercury switches have one or more sets of electrical contacts in a sealed glass envelope that contains a small quantity of mercury. The envelope may also contain air, an inert gas, or a vacuum.
Gravity constantly pulls the drop of mercury to the lowest point in the envelope. When the switch is tilted in the appropriate direction, the mercury touches a set of contacts, thus completing an electrical circuit.
Tilting the switch in the opposite direction moves the mercury away from that set of contacts, breaking that circuit.The switch may contain multiple sets of contacts, closing different sets at different angles, allowing, for example, single-pole, double-throw (SPDT) operation.
The contacts are enclosed, so oxidation of the contact points is unlikely.
In hazardous locations, interrupting the circuit does not emit a spark that could ignite flammable gases.
Contacts stay clean, and even if an internal arc occurs, the contact surfaces renew on every operation, so they don’t wear out.
Even a small drop of mercury has low resistance, so switches can carry useful amounts of current in a small size
Sensitivity of the drop to gravity provides a unique sensing function, and lends itself to simple, low-force mechanisms for manual or automatic operation.
The switches are quiet, as no contacts abruptly snap together.
The mass of the moving mercury drop provides an over center effect to avoid chattering as the switch tilts.
The envelope can include contacts for two or more circuits.
Their relatively slow operating rate (due to the inertia of the mercury drop) makes them unsuitable for applications that require many operating cycles per second.
Glass envelopes and wire electrodes may be fragile and require flexible leads to prevent damage to the envelope.
The mercury drop forms a common electrode, so circuits are not isolated from each other in a multi-pole switch.
Their sensitivity to gravity may make them unsuitable in portable or mobile devices that can change orientation or vibrate.
Mercury compounds are highly toxic and accumulate in any food chain, so safety codes exclude mercury in many new designs.
We use Pin 13 (GPIO27) for the sensor, one of the examples also has an LED connected to Pin 11 (GPIO17). We have not shown this in the schematic and layout below