Learn interfacing Tilt Switch Module in Raspberry Pi. The tilt switch is just like a normal switch with a little difference. Tilt switch has a ball inside its tube. On tilting the switch ball will roll down connecting the metal contact and activating the switch. We have connected led with the tilt switch which will be activated by tilting the switch. For this, we will use Tilt switch module and Raspberry Pi 3. So, let’s start.
Step 1: Required Components
Tilt Switch module x 1
Generic LED x 1
Breadboard x 1
Raspberry Pi x 1
Step 2: Circuit Time
Firstly, connect LED to GPIO 17 of Raspberry Pi. Now, connect the signal pin to tilt switch module to GPIO 27 of Raspberry Pi. Then, connect VCC pin and GND pin of tilt switch module to +5v and GND pin of Raspberry Pi.
Step 3: Code Time
This is code for interfacing Tilt Switch Module in Raspberry Pi. Firstly, initialize pins for tilt switch and LED. Set the tilt switch pin to input mode and led pin to output mode. We will use ‘add event detect’ function to identify the signal. If we get high signaled, will turn on.
Step 4: Run code to Raspberry Pi
Run the Python program in your Raspberry Pi after setting components as per circuit diagram. Tilting switch will turn on the LED.
For running python code in Raspberry PI, visit: raspberrypi.org/documentation/usage/python/
For basic hardware information about Raspberry PI 3, Click here.