A switch that uses a small amount of mercury within a sealed glass tube to detect tilting is known as a mercury tilt switch. In 1922, Louis Austin Merritt Phelan invented a mercury switch through a glass envelope. After that, a more advanced mercury switch with a tubular glass envelope was invented in 1937 by Harold Olson. Whenever the switch tilts, then mercury will move and break the circuit. This is an electrical switch that opens & closes an electrical circuit whenever a small amount of the fluid metal mercury attaches metal electrodes to lock the circuit. An example of a mercury tilt switch is the KY-017 module. So this article elaborates on the KY-017 module, pin-out, working, and its applications.
What is the KY-017 Module?
KY-017 is a mercury tilt switch module that utilizes a mercury ball to identify changes within orientation. This is a small and economical sensor module that can be easily integrated with different microcontrollers like Arduino, ESP32, Raspberry Pi, etc. Thus, it can be used in motion detection, security systems, alarm systems & other electronic projects.
How KY-017 Module Work?
A KY-017 mercury tilt switch module works with a small mercury ball in a glass container that completes a circuit whenever the module is tilted. It works as a switch to register a change within orientation by observing whenever the mercury ball strokes the contact points in the switch.
After that, this change can be signaled throughout a digital output pin by allowing it to be read through a microcontroller to activate actions depending on the tilt detection. This module includes a mercury switch, an LED, and a 680Ω resistor that lights up whenever tilt is noticed. The mercury ball opens or closes the electrical circuit whenever the module is turned.
This KY017 module measures the direction. If this direction goes beyond a particular level then it lights up a light-emitting diode on the module. Thus, it provides a digital signal through the signal pin which reads through any development. The mercury ball within the glass envelopes either opens or closes the circuit in different directions.
Working Cases:
KY-017 mercury tilt switch module works in two cases when the sensor is not tilted and when the sensor is tilted.
Case 1: When the Sensor Module is Not Tilted
When the sensor is not tilted then it provides low output due to the liquid mercury completing the electrical circuit by simply connecting two electrodes. Whenever the output is less on board then the LED on the board remains on.
Case 2: When the Sensor Module is Tilted
Whenever the sensor module is tilted, the mercury can be inclined at a particular angle or direction. So the fluid mercury will break the connection between the metal electrodes & the electrical circuit will open. Thus we can get higher output in this condition & the onboard LED will turn off.
KY-017 Module Pin Configuration:
The KY-017 module pin configuration is shown below. This module includes three pins which are explained below.

KY-017 Module Pin Configuration
- Pin-1 (GND): It is a ground pin of the mercury tilt switch module.
- Pin-2 (+5V): It is a positive voltage supply pin of the module that supplies to operate this module.
- Pin-3 (Signal): It is a signal pin of the module that transmits (or) receives an electrical signal. So it acts as a communication point to communicate with other components within a circuit.
Features & Specifications:
The features and specifications of the KY-017 module include the following.
- The KY-017 is a mercury tilt switch module.
- This module includes a mercury ball that closes the electrical circuit whenever the module tilts.
- This module is well-matched with several electronic platforms.
- Input voltage ranges from 3.3V to 5.5V.
- The input current is 0.3mA.
- This module includes three pins like GND, Signal & VCC)
- It has high sensitivity.
- This module has an output LED light indicator.
- These are small in size,
- Its operating temperature ranges from -20°C to +50°C.
Equivalents & Alternatives :
The equivalents to KY-017 modules are; LIS3DH, ADXL345, MPU6050, etc. Alternatives to KY-017 modules are; SW520D, KY-020, G8Z-003, D6BN-1P, CM1600-0,20176, T08-2010, G10Z-003, T03-1026,T03-1015, etc.
KY-017 Module Interfacing with Arduino Uno
The KY-017 module interfacing with Arduino Uno is shown below. The KY-017 mercury switch module is a simple & efficient motion-detecting module. Whenever your autonomous vehicle is tilted then the mercury ball within the tube will shift to complete the circuit and send an output signal to the Arduino control system. This module is used commonly within the bike anti-theft system wherever tilt is observed and an SMS or alarm is sent to the concerned person.
The required components to make this interfacing include the KY-017 module, Arduino Uno, and connecting wires.
The connections of this interfacing follow as;
- Connect the GND pin of Arduino Uno to the pin – of the KY-017 module.
- Connect the +5V pin of the Arduino board to the middle pin of the mercury tilt switch module.
- Connect the -3 pin of the Arduino board to pin-S of the mercury tilt switch module.

KY-017 Module Interfacing with Arduino Uno
Working
The required code for interfacing the KY-017 module with Arduino Uno is shown below.
int Led = 13 ;// define LED Interface
buttonpin = 3; // define the mercury tilt switch sensor interface
int val ;// define numeric variables val
void setup ()
{
pinMode (Led, OUTPUT) ;// define LED as output interface
pinMode (buttonpin, INPUT) ;// define the mercury tilt switch sensor output interface
}
void loop ()
{
val = digitalRead (buttonpin) ;// read the values assigned to the digital interface 3 val
if (val == HIGH) // When the mercury tilt switch sensor detects a signal, LED flashes
{
digitalWrite (Led, HIGH);
}
else
{
digitalWrite (Led, LOW);
}
}
Once the above code is uploaded then supply the board. When the module is tilted then it will light up the LED on pin-13 of the Arduino board.
Advantages & Disadvantages
The advantages of the KY-017 module include the following.
- The KY-017 module is very simple to design.
- It is easy to use.
- These are not expensive.
- It has reliable detection of changes in tilt
- These modules can be interfaced easily with popular microcontrollers.
- These modules are reliable.
- This module has high sensitivity.
- It is appropriate for DIY projects.
- This module includes an output LED that indicates whenever a tilt is noticed.
- This module provides a digital output on the signal pin.
The disadvantages of the KY-017 module include the following.
- The KY-017 tilt switch module can be damaged from improper insertion.
- It may need to be turned upside-down
- This module depends on a mercury switch.
- The mercury usage presents a potential environmental exposure if the module is misused or injured which leads to mercury leakage.
- The module can activate a signal even with little tilts which causes potentially false positives within applications wherever exact tilt detection is necessary.
- The mercury switch is delicate and can be damaged from vibrations or impacts.
- This module is not suitable for all tilt detection-based applications, mainly those that need high precision (or) wherever ecological security is paramount.
Applications
The applications of the KY-017 module include the following.
- A KY-017 module is used primarily to detect many changes within tilt or orientation, thus it is suitable in different applications like: security systems, motion detection, level sensing within simple setups, tilt alarms, gaming controllers, and DIY projects that need basic tilt detection, inclinometers & any situation wherever a simple on/off signal depending on tilt is required.
- This module can be interfaced easily with different microcontrollers like Raspberry Pi or Arduino to activate specific actions depending on tilt detection.
- It is used in interactive toys and games to design games, responsive robots, etc,
- This module is used in alarm systems & security systems to implement tilt detection of windows, doors, etc.
- It is used in robotics and automation to control the robot’s movements, and start mechanisms, and enable automated processes depending on tilt.
- These are used in art installations & displays to design interactive arts that react to movement.
Please refer to this link for the KY-017 Module Datasheet.
Thus, this is an overview of the KY-017 tilt switch module, pinout, features, specifications, and applications. This module detects changes within movement and orientation. This is a small, inexpensive, and simple-to-use module that is appropriate for a lot of DIY projects. This is a type of switch that reacts to movement by using a little mercury ball to complete the circuit whenever the mercury module is tilted. This module is well-matched with different electronic platforms. Here is a question for you, what is the MPU6050 module?