Introduction
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 Pi | GPIO Extension Board | Tilt Switch Module |
GPIO0 | GPIO17 | SIG |
3.3V | 3V3 | VCC |
GND | GND | GND |
Raspberry Pi | GPIO Extension Board | Dual-Color LED Module |
GPIO1 | GPIO18 | R |
GND | GND | GND |
GPIO2 | GPIO27 | G |

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.
