Site icon Iotguider

Interfacing Tilt Switch with Raspberry Pi

Interfacing Tilt Switch Module in Raspberry Pi

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

Tilt Switch module x 1
Generic LED x 1
Breadboard x 1
Raspberry Pi x 1
Jumper Wires

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.

For running python code in Raspberry Pi, visit: raspberrypi.org/documentation/usage/python/
Learn basic hardware information of Raspberry Pi 3.

Exit mobile version