Learn the interfacing Tilt Switch Module in Raspberry Pi. The tilt switch is just like a normal switch with a little difference. The 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 the Tilt switch module and Raspberry Pi 3. So, let’s start.
Step 1: Required Components
Step 2: Circuit Time
Firstly, connect LED to GPIO 17 of Raspberry Pi. Now, connect the signal pin to the tilt switch module to GPIO 27 of Raspberry Pi. Then, connect the VCC pin and GND pin of the tilt switch module to the +5v and GND pin of the board.
Step 3: Code Time
This is code for interfacing the Tilt Switch Module. 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 the ‘add event detect’ function to identify the signal. If we get high signaled, it will turn on.
Step 4: Run code to Raspberry Pi
Run the Python program in your Raspberry Pi after setting components as per the circuit diagram. Tilting switch will turn on the LED.