Danny van den Brande
Published © CC BY-SA

Arduino - Switching Light On/Off with Mercury Switch

Hello World! I made another example for one of the Sensors from my arsenal :)This time the Mercury Switch Module KY-017.

BeginnerFull instructions provided1 hour2,036
Arduino - Switching Light On/Off with Mercury Switch

Things used in this project

Story

Read more

Schematics

Schematic

Code

KY-017_Kwik_Switch_Module.ino

Arduino
This example will show you how a Mercury switch works.
This example is very basic and easy to understand.
/*
Author:Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
This example will show you how a Mercury switch works.
This example is very basic and easy to understand.
It will turn on a relay when tilting the switch.
You can add a lamp or any device to the relay.
 */

int BlueLed = 9;
int KwikSwitch = 8;
int Relay = 7;
int val;

void setup() 
{
pinMode (BlueLed, OUTPUT);
pinMode (Relay, OUTPUT);
pinMode (KwikSwitch, INPUT);

}

void loop() 
{
  val = digitalRead (KwikSwitch) ;
  if (val == HIGH)
  {
    digitalWrite (BlueLed, HIGH);
    digitalWrite (Relay, HIGH);
  }
  else
  {
    digitalWrite (BlueLed, LOW);
    digitalWrite (Relay, LOW);
  }
  
}

Credits

Danny van den Brande
36 projects • 110 followers
"Hello world."

Comments