• Arduino
  • Raspberry Pi
  • Raspberry Pi Pico
  • Micro:Bit

This module contains a tilt switch that short-circuits the input pins depending on the tilt angle. Inside the switch is a small ball that connects the contacts when the position changes. When the module is tilted, the ball moves and closes the circuit, generating a signal. This simple but effective principle enables the detection of tilt changes and is ideal for applications such as security and alarm systems, motion detection or as a switching mechanism in various projects. The module is easy to integrate and offers a reliable way of detecting inclination and movement.

Pin assignment


Arduino Sensor
Pin 10 signal
5 V +V
GND GND
Arduino Sensor
Pin 13 LED +
GND LED -

Code example

This is a sample program that lights up an LED when a signal is detected at the sensor. The modules KY-011, KY-016 or KY-029 can also be used as LEDs, for example.

int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
   
void setup ()
{
  pinMode (Led, OUTPUT) ; // Initialize output pin
  pinMode (Sensor, INPUT) ; // Initialize sensor pin
}
   
void loop ()
{
  val = digitalRead (Sensor) ; // The current signal at the sensor is read out
   
  if (val == HIGH) // If a signal could be detected, the LED is switched on.
  {
    digitalWrite (Led, LOW);
  }
  else
  {
    digitalWrite (Led, HIGH);
  }
}

Example program download

KY017-Arduino.zip

This module contains a tilt switch that short-circuits the input pins depending on the tilt angle. Inside the switch is a small ball that connects the contacts when the position changes. When the module is tilted, the ball moves and closes the circuit, generating a signal. This simple but effective principle enables the detection of tilt changes and is ideal for applications such as security and alarm systems, motion detection or as a switching mechanism in various projects. The module is easy to integrate and offers a reliable way of detecting inclination and movement.

Pin assignment


Raspberry Pi Sensor
GPIO 24 [Pin 18] Signal
3.3 V [Pin 1] +V
GND [Pin 6] GND

Code example

This is a sample program that prints a console output when as signal is detected at the sensor.

# Required modules are imported and set up
import RPi.GPIO as GPIO
import time
   
GPIO.setmode(GPIO.BCM)
   
# Here the input pin is declared, to which the sensor is connected. Additionally the PullUP resistor at the input will be activated
GPIO_PIN = 24
GPIO.setup(GPIO_PIN, GPIO.IN)
   
print ("Sensor test [press CTRL+C to end test]")
   
# This outputFunction will be executed on signal detection
def outputFunction(null):
        print("Signal detected")
   
# When a signal is detected (falling signal edge) the output function is executed
GPIO.add_event_detect(GPIO_PIN, GPIO.FALLING, callback=outputFunction, bouncetime=100) 
   
# main program loop
try:
    while True:
        time.sleep(1)
   
# clean up after the program is finished
except KeyboardInterrupt:
    GPIO.cleanup()

Example program download

KY017-RPi.zip

To start with the command:

sudo python3 KY017-RPi.py

This module contains a tilt switch that short-circuits the input pins depending on the tilt angle. Inside the switch is a small ball that connects the contacts when the position changes. When the module is tilted, the ball moves and closes the circuit, generating a signal. This simple but effective principle enables the detection of tilt changes and is ideal for applications such as security and alarm systems, motion detection or as a switching mechanism in various projects. The module is easy to integrate and offers a reliable way of detecting inclination and movement.

Pin assignment


^
Micro:Bit Sensor
Pin 1 Signal
3 V +V
GND GND

Code example

This is a sample program that outputs text serially when a signal is detected at the sensor.

	
		pins.setPull(DigitalPin.P1, PinPullMode.PullUp)
		basic.forever(function () {
		    serial.writeLine("" + (pins.digitalReadPin(DigitalPin.P1)))
		    if (pins.digitalReadPin(DigitalPin.P1) == 0) {
		        serial.writeLine("Maximaler Neigungswert: erreicht ")
		    } else {
		        serial.writeLine("Maximaler Neigungswert: noch nicht erreicht ")
		    }
		    serial.writeLine("_____________________________________")
		    basic.pause(1000)
		})
	

Sample program download

microbit-KY-017.zip

This module contains a tilt switch that short-circuits the input pins depending on the tilt angle. Inside the switch is a small ball that connects the contacts when the position changes. When the module is tilted, the ball moves and closes the circuit, generating a signal. This simple but effective principle enables the detection of tilt changes and is ideal for applications such as security and alarm systems, motion detection or as a switching mechanism in various projects. The module is easy to integrate and offers a reliable way of detecting inclination and movement.

Pin assignment


Raspberry Pi Pico Sensor
GPIO26 Signal
3.3V +V
GND GND

Code example

This is a sample program that counts up and outputs text serially when a signal is detected at the sensor.

# Load libraries
from machine import Pin, Timer

# Initialization of GPIO as input
sensor = Pin(26, Pin.IN, Pin.PULL_DOWN)

# Create timer
timer = Timer()

# Variables initialization
counter = 0

# Function: Count steps
def step(timer):
    global counter
    counter = counter + 1
    print("Schräglage")
    print(counter)

# Function: Vibration
def shake(pin):
    # Debounce function: Set timer
    timer.init(mode=Timer.ONE_SHOT, period=100, callback=step)

# Initialization of the interrupt
sensor.irq(trigger=Pin.IRQ_FALLING, handler=shake)

Example program download

KY017-Pico.zip