KY-017 MERCURY TILT SWITCH MODULE

Click Here to View Step by Step

KY-017 MERCURY TILT SWITCH MODULE


Short description :

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.

Working with  (Compatible)

Arduino, ESP32, Nodemcu, ESP8266, Raspberry Pi, and ......

KY-017 MERCURY TILT SWITCH MODULE

KY-017 MERCURY TILT SWITCH MODULE

ARDUINO IDE CODE 

Example description :

The following sketch will light up the led 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);
  }
}