KY-017 Mercury Tilt Switch Module

The KY-017 Mercury Tilt Switch module is a switch that responds to movement. It uses a small mercury ball that completes the circuit when the module is tilted.

Compatible with many electronics platforms like Arduino, Raspberry Pi, ESP32 and others. For less sensitive tilt detection use the KY-020 tilt switch.

KY-017 Fritzing part image
Arduino KY-017 mercury switch module

KY-017 Specifications

This module consists of a mercury switch, a 680Ω resistor and a LED that will light up when tilt is detected. The mercury ball will open/close the circuit when the module is rotated.

Operating Voltage3.3V ~ 5.5V

Connection Diagram

Connect the module power line (middle) and ground (-) to +5 and GND on the Arduino respectively. Connect signal (S) to pin 3.

KY-017Arduino
SPin 3
middle+5V
GND
KY-017 Arduino connection diagram

KY-017 Arduino Code

The following sketch will light up the led on pin 13 of the Arduino when the module is tilted.

int led_pin = 13; // Define the LED interface
int switch_pin = 3; // Definition of mercury tilt switch sensor interface
int val; // Defines a numeric variable

void setup()
{
	pinMode(led_pin, OUTPUT);
	pinMode(switch_pin, INPUT);
}

void loop()
{
	val = digitalRead(switch_pin); // check mercury switch state
	if(val == HIGH)
	{
		digitalWrite(led_pin, HIGH);
	}
	else
	{
		digitalWrite(led_pin, LOW);
	}
}

Downloads

Leave a Comment


1 thought on “KY-017 Mercury Tilt Switch Module”

  1. The Fritzing Diagram is wrong: the blue and the black wires on the side of the switch must be swapped. The Signal of the Switch is the third Pin.

    Reply