Arduino UNO Q - SW520D Tilt Sensor
A SW520D tilt sensor detects orientation changes and outputs a digital signal. It uses a simple ball switch mechanism — no potentiometer or analog output. Use it to trigger actions when an object is tilted, tipped, or moved. With Bridge and Telegram, your Arduino UNO Q can send you instant alerts when tilt is detected.
In this tutorial, you will learn:
- What a SW520D tilt sensor is and how it works
- How to wire the SW520D tilt sensor to the Arduino UNO Q MCU
- How to read the digital output to detect tilt
- How to use Bridge to expose tilt state and events to the Linux side (Python)
- How to receive Telegram alerts when tilt is detected on Arduino UNO Q
- How to use OpenClaw on Arduino UNO Q with the SW520D tilt sensor

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of the SW520D Tilt Sensor
A SW520D tilt sensor module detects orientation changes using a small metal ball inside a cylindrical housing. When the sensor is upright, the ball closes the electrical contact. When the sensor is tilted, the ball rolls away and opens the contact. The module outputs a simple digital signal:
- HIGH: Sensor is upright — no tilt detected
- LOW: Sensor is tilted — tilt detected
The module includes:
- VCC pin: 3.3V to 5V power supply
- GND pin: Ground
- DO pin: Digital output — HIGH = upright, LOW = tilt detected
- PWR LED: Power indicator
- Status LED: Reflects the tilt state — on when upright, off when tilted

Wiring Diagram

This image is created using Fritzing. Click to enlarge image
| SW520D Tilt Sensor Pin | Arduino UNO Q MCU |
|---|---|
| GND | GND |
| VCC | 5V |
| DO | D8 |
How To Program For SW520D Tilt Sensor
- Configure the sensor pin as a digital input:
- Read the digital output:
- Detect tilt events by comparing to the previous state:
Arduino UNO Q Code
The Arduino UNO Q has two processors working together:
- The STM32 MCU reads the SW520D tilt sensor's digital output and detects tilt events
- The Qualcomm MPU runs Debian Linux with Wi-Fi — in this section, only the MCU is programmed. A later section shows how both processors work together via Bridge.
Detailed Instructions
First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial before proceeding.
- Connect: Wire the SW520D tilt sensor to the Arduino UNO Q MCU as shown in the wiring diagram.
- Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
- Create a new App: Click the Create New App button.

- Give the App a name, for example: SW520DTiltSensor
- Click Create to confirm.

- Paste the sketch: Copy the MCU code above and paste it into sketch/sketch.ino.
- Upload: Click the Run button in Arduino App Lab.

- Tilt the sensor back and forth — observe the Serial Monitor output.
- Make sure the sensor is mounted in the correct upright position for reliable detection.
App Lab Console Output
Bridge: Linux + MCU
This section shows how to program both processors of the Arduino UNO Q so the Linux side can read tilt state and receive tilt events via Bridge:
- The SW520D tilt sensor is connected to the MCU — the MCU monitors the digital output continuously and caches the current state
- The MPU cannot read the sensor pin directly — it calls Bridge functions to get the current state or check for new tilt events
- The MPU has Wi-Fi — running full Debian Linux, it can send Telegram alerts the moment tilt is detected
- Arduino_RouterBridge enables RPC communication between the two processors
- ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) are RESERVED by the router — never open them in user code
In short: MCU detects tilt via DO pin → sets event flag → MPU polls Bridge → MPU sends Telegram alert.
MCU Code (Bridge)
Python Code (Bridge)
Detailed Instructions
- Connect: Wire the SW520D tilt sensor to the Arduino UNO Q as shown in the wiring diagram.
- Open Arduino App Lab and create a new App named TiltSensorBridge.
- Paste the MCU sketch into sketch/sketch.ino.
- Paste the Python code into the Python file.
- Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.

- Search for Arduino_RouterBridge created by Arduino and click the Install button.
- Upload: Click the Run button.

- Tilt the sensor — observe the event appear in both consoles.
App Lab Console Output
Telegram
Receive instant Telegram alerts when tilt is detected on the Arduino UNO Q SW520D tilt sensor.
MCU sketch: Keep the same MCU sketch from the previous Bridge section.
Python Code (Telegram)
Detailed Instructions
- Replace YOUR_TELEGRAM_BOT_TOKEN with your actual bot token from BotFather.
- Replace YOUR_CHAT_ID with your Telegram chat ID.
- Paste this Python code into your App's Python file (keep the same MCU sketch).
- Click the Run button — tilt the sensor to trigger a Telegram alert.
App Lab Console Output
ArduinoBot
OpenClaw
You can adapt the OpenClaw to this tutorial by refering the instruction on Arduino Uno Q - OpenClaw Tutorial
Project Ideas
You can build many useful projects with the SW520D tilt sensor and Arduino UNO Q:
- Anti-Tamper Alert: Attach the sensor to an enclosure — if it is tilted or moved, the MPU sends an immediate Telegram alert with a timestamp so you know when tampering occurred
- Tilt-Activated Switch: Use the tilt sensor with a relay via Bridge — Python detects the tilt event and toggles a light or fan on or off based on orientation
- Equipment Monitor: Mount the sensor on machinery or furniture — the MPU logs each tilt event to a CSV file on Linux and sends a Telegram report at the end of the day
- Smart Safe Alert: Combine the tilt sensor with a door sensor — Telegram alerts when either the safe door opens or the safe itself is moved
- RC Tilt Controller: Use two SW520D sensors mounted on different axes — the MPU reads both states via Bridge and sends orientation commands to control a remote device over Wi-Fi