Tilt switch SW-520D with TinkerPie
A ball inside a tube: fall alarms, tilt toys.
| Type | Digital sensors |
|---|---|
| Connect to | any accessory pin (switch to GND) |
| Gives | true when tipped over |
| Simulator | Yes: a control appears under the simulated board |
How it works
The SW-520D has a small metal ball inside a tube. When the switch tilts, the ball rolls and opens or closes the contacts. It is a simple, cheap way to notice tipping or falling.
How to wire it
Signal (DO / OUT / S) to any accessory pin: S1-S4, P10-P13, P43 or P44. Power from 3.3 V where the module allows it.
Code
In blocks: Accessories category in TinkerPie Studio. As code:
// JavaScript
sensors.tiltSwitch(Pin.S1)
// Arduino C++
sensors::tiltSwitch(Pin::S1) Good to know
- It only says tipped or not; for angles use the board motion sensor or an MPU6050.
- Shaking can make it flicker, so wait a moment before acting.
- Any accessory pin works.
Similar modules
- PIR motion sensor HC-SR501
- IR obstacle sensor
- Touch sensor TTP223
- Push button module
- Reed switch (magnet)
- Vibration sensor SW-420
- Hall effect sensor A3144
- Line tracker TCRT5000
More projects to try
Questions
Can I try the Tilt switch SW-520D without buying one?
Yes. In TinkerPie Studio the simulator shows a control for it under the board, so you can test your program before you build it.
Can a tilt switch measure the angle?
No, it is only on or off. To measure angles, use the accelerometer on the TinkerPie board or the MPU6050.