Project25.Mercury Tilt Switch

Descriptio

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.

Specification

  • Operating Voltage 3.3V ~ 5.5V

Connect

_images/25_bb.png

Code

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);
    }
}

Phenomenon

_images/25.jpg