Introduction
The KY-020 Tilt Switch Sensor module is the switch that responds to movement around its area. Then the circuit closes when it’s tilted to the side as long as it is moved with enough force and degree of inclination to turn on the ball switch inside.
This module is compatible with popular electronic platforms like Arduino, ESP32, Raspberry Pi, and other microcontrollers. For more sensitive tilt detection use the KY-017 mercury tilt switch.
Hardware Required
You will require the following Hardware Components for the Interfacing of the KY-020 Tilt Switch Sensor module with arduino.
Components | # | Buy From Amazon |
---|---|---|
Arduino UNO | 1 | Buy Now |
KY-020 Tilt Switch Sensor module | 1 | Buy Now |
LED 5mm | 1 | Buy Now |
Jumper Wires | 3 | Buy Now |
Breadboard | 1 | Buy Now |
What is the KY-020 Tilt Switch Sensor module?
contains a small ball that moves around inside the sensor when it is tilted, and this movement is detected by the module. It is very easy to use and can be integrated into various projects and applications.
Specifications
This module contains the metallic ball switch with bidirectional conduction that will open/close the circuit when tilted, a 10kΩ resistor, and 3 male header pins. This module doesn’t measure tilt angle.
Operating Voltage | 3.3V ~ 5V |
Output Type | Digital |
Pinout
Pin Configuration
Pin Name | Pin Type |
---|---|
S | Signal Pin |
Middle | Power Pin |
( – ) | Ground Pin |
Circuit Diagram
The following circuit shows you the connection of the KY-020 Tilt Switch Sensor module with Arduino Please make the connection carefully
Circuit Connections
Place the module on the Breadboard and attach the Power line (middle) and ground (-) of the module to +5 and GND of the arduino and then connect signal (S) to pin 2 on the arduino respectively
Arduino | Module | LED |
---|---|---|
Pin 2 | S | |
+5V | Middle | |
Pin 13 | +Ve | |
GND | – | -Ve |
Installing Arduino IDE Software
First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow
Code
The following code will switch on the LED on pin 13 of the Arduino when the module inclination degree changes. Tilt the module to turn the LED on/off.
//For more Projects: www.arduinocircuit.com
int tiltPin = 2; // pin number for tilt switch signal
int ledPin = 13; // pin number of LED
int tiltState = 0; // variable for reading the tilt switch status
void setup() {
pinMode(ledPin, OUTPUT); // set the LED pin as output
pinMode(tiltPin, INPUT); // set the tilt switch pin as input
}
void loop(){
// get the tilt switch state
tiltState = digitalRead(tiltPin);
// check if tilt switch is tilted.
if (tiltState == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
Applications
- Security Alarm: The module can be used as a simple motion detector to trigger an alarm or alert if it is tilted or moved. This could be useful in applications where you want to detect unauthorized access to a secure area.
- Game Controller: The KY-020 module can be used as a tilt sensor in game controllers, allowing users to control a game by tilting the controller. This can add a fun and immersive element to games.
- Automatic Lighting: The sensor can be used to turn on lights automatically when it is tilted, for example, when a door is opened. This could be useful in situations where it is inconvenient or impractical to manually turn on lights.
- Robotics: The module can be used to control the movement of robots, for example, to trigger certain movements when it is tilted in a particular direction.
- Vehicle Alarm: The tilt switch sensor can be used in vehicles to detect when the vehicle is being towed or jacked up, triggering an alarm to alert the owner or the authorities of potential theft.