KY-020 Tilt Switch Sensor Module with Arduino


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 UNO1Buy Now
KY-020 Tilt Switch Sensor module1Buy Now
LED 5mm1Buy Now
Jumper Wires3Buy Now
Breadboard1Buy 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.



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 Voltage3.3V ~ 5V
Output TypeDigital



Pin Configuration

Pin NamePin Type
SSignal Pin
MiddlePower 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

Pin 2S
Pin 13+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


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


  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

Leave a Comment