Home Code KY-017 Mercury Tilt Switch Module and Raspberry Pi

KY-017 Mercury Tilt Switch Module and Raspberry Pi

by shedboy71

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.

Parts List

Name link
Raspberry Pi3 Raspberry Pi 3 Model B With WiFi & Bluetooth
37 sensor kit 37 IN 1 SENSOR KITS FOR ARDUINO HIGH-QUALITY FREE SHIPPING (Works with Official for Arduino Boards)
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



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


pi and ky-017 layout

pi and ky-017 layout


pi and ky-017 schematic

pi and ky-017 schematic


Code Examples


code download from github

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More