Arduino - Tilt Switch, Switching On A RELAY With The KY-020

Arduino - Tilt Switch, Switching On A RELAY With The KY-020 © CC BY-SA

Hello world! I made another example. Today for the KY-020. We are simply going to switch on a relay to turn the lamp on and off.

  • 427 views
  • 0 comments
  • 0 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
KY-020 Tilt Switch. .
×1
KY-019 1 Channel relay
×1
11026 02
Jumper wires (generic)
×1
Lamp Socket + lamp & power Cable
×1

About this project

Hello world! I made another example. Today for the KY-020.

We are simply going to switch on a relay to turn the lamp on and off.

Follow the next step for the schematic code & Parts list.

Step 1: Parts List.


Parts List.

  • Arduino Uno, I used the RobotDyn Uno.
  • KY-020 Tilt Switch.
  • KY-019 1 Channel relay.
  • Jumper wires MM/FF/MF
  • Lamp Socket + lamp & power Cable. (Optional)

Good luck!


Code

KY-020_Tilt_Switch_With_RELAY.inoArduino
In this example we switch on a light with a relay and the KY-020 Tilt Switch
/*
Author: Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
In this example we switch on a light with a relay and the KY-020 Tilt Switch
 */
int Relay = 2;
int TiltSwitch = 3; 
int val ;
void setup ()
{
  pinMode (Relay, OUTPUT);
  pinMode (TiltSwitch, INPUT);
  Serial.begin(9600);
}
void loop ()
{
  val = digitalRead (TiltSwitch);
    if (val == HIGH) 
  {
    digitalWrite (Relay, HIGH);
    Serial.print ("Value: ");//You can remove the serial print section.
    Serial.println (val);
    delay(100);
  }
  else
  {
    digitalWrite (Relay, LOW);
    Serial.print ("Value: ");//You can remove the serial print section.
    Serial.println (val);
    delay(100);
  }
}

Schematics

Schematic
Ky 020%20tilt%20switch%20with%20relay bb

Comments

Similar projects you might like

Arduino - Magnetic Reed Switch KY-021

Project showcase by Danny van den Brande

  • 5,519 views
  • 0 comments
  • 3 respects

Arduino UNO and Vibration Sensor with Relay

Project tutorial by MichDragstar

  • 2,653 views
  • 2 comments
  • 10 respects

The Troll Switch

Project tutorial by Aitor Gamarra

  • 2,038 views
  • 3 comments
  • 7 respects

Switching Using Transistor

by SBR

  • 9,869 views
  • 16 comments
  • 40 respects

Amazing Applications of Tilt Sensors

by SURYATEJA

  • 5,843 views
  • 1 comment
  • 6 respects
Add projectSign up / Login