.. note:: Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts. **Why Join?** - **Expert Support**: Solve post-sale issues and technical challenges with help from our community and team. - **Learn & Share**: Exchange tips and tutorials to enhance your skills. - **Exclusive Previews**: Get early access to new product announcements and sneak peeks. - **Special Discounts**: Enjoy exclusive discounts on our newest products. - **Festive Promotions and Giveaways**: Take part in giveaways and holiday promotions. 👉 Ready to explore and create with us? Click [|link_sf_facebook|] and join today! .. _ar_tilt: 2.17 Tilt Switch ================== Overview --------------- In this lesson, you will learn about tilt switch. Tilt switch can be used to detect whether objects tilt, which is of great value in practical applications. It can be used to judge the tilt of bridges, buildings, transmission line tower and so on, so it has an important guiding function in carrying out maintenance work. Components Required ------------------------- .. image:: img/Part_two_17.png * :ref:`cpn_mega2560` * :ref:`cpn_breadboard` * :ref:`cpn_wires` * :ref:`cpn_resistor` * :ref:`cpn_tilt` Fritzing Circuit --------------------- In this example, digital pin 2 is used to read the signal of Tilt Switch. .. image:: img/image165.png :align: center Schematic Diagram ----------------------- .. image:: img/image166.png :align: center Code ---------- .. note:: * You can open the file ``2.17_tiltSwitch.ino`` under the path of ``sunfounder_vincent_kit_for_arduino\code\2.17_tiltSwitch`` directly. * Or copy this code into Arduino IDE. .. raw:: html After the codes are uploaded to the Mega2560 board, you can open the serial monitor to see the readings of pins, which displays 「1」 or 「0」 when Tilt Switch is vertical (bringing the internal metal ball into contacting with the Wire Pins) or tilted. For detailed explanation of codes, you can turn to :ref:`ar_digital_read`. Phenomenon Picture ----------------------- .. image:: img/image167.jpeg :align: center