Lesson 7 Tilt-Switch Module

Share for us


The tilt-switch module (as shown below) in this kit is a ball tilt-switch with a metal ball inside. It is used to detect inclinations of a small angle.

Required Components

 1 * Raspberry Pi

1 * Breadboard

– 1 * Dual-color LED module

– 1 * Tilt-switch module

– 2 * 3-Pin anti-reverse cable

Experimental Principle

The principle is very simple. The ball in the tilt-switch changes with different angle of inclination to trigger the circuit. When the ball in tilt switch runs from one end to the other end due to shaking caused by external force, the tilt switch will conduct and the LED will emit red light, otherwise it will break and the LED will emit green light.

The schematic diagram of the module is as shown below:

Experimental Procedures

Step 1: Build the circuit.

Raspberry PiGPIO Extension BoardTilt Switch Module
Raspberry PiGPIO Extension BoardDual-Color LED Module

For C Users:

Step 2: Change directory. 

    cd /home/pi/SunFounder_SensorKit_for_RPi2/C/07_tilt_switch/

Step 3: Compile.

    gcc tilt_switch.c -lwiringPi

Step 4: Run.

    sudo ./a.out

For Python Users:

Step 2: Change directory.

    cd /home/pi/SunFounder_SensorKit_for_RPi2/Python/

Step 3: Run.

    sudo python3 07_tilt_switch.py

Place the tilt switch module horizontally, and the LED will flash green. If you tilt it, “Tilt!” will be printed on the screen and the LED will change to red. Place it horizontally again, and the LED will flash green again.