.. 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_slide: 2.16 Slide Switch ================== Overview ------------ In this lesson, you will get to know something about Switch. A slide switch, just as its name implies, is to slide the switch bar to connect or break the circuit, and further switch circuits. The slide switch is commonly used in low-voltage circuit. It has the features of flexibility and stability, and applies in electric instruments and electric toys widely. Components Required ------------------------ .. image:: img/Part_two_16.png * :ref:`cpn_mega2560` * :ref:`cpn_breadboard` * :ref:`cpn_wires` * :ref:`cpn_resistor` * :ref:`cpn_slide` * :ref:`cpn_capacitor` Fritzing Circuit --------------------- In this example, digital pin 2 is used to read the signal of Switch. In addition, you need to connect a 10 kΩ resistor and a 104 capacitor in parallel to form a RC circuit (Resistor - Capacitance circuit) which is set between pin 2 and GND to realize debounce that may arise from your toggle of switch. .. image:: img/image160.png :align: center Schematic Diagram .. image:: img/image161.png :align: center Code --------- .. note:: * You can open the file ``2.16_switch.ino`` under the path of ``sunfounder_vincent_kit_for_arduino\code\2.16_switch`` 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 check the readings of the pin. When the Switch toggles to the left, the serial monitor displays 「1」; when toggles to the right, the serial monitor displays「0」. Refer to :ref:`ar_digital_read` to check the code explanation. Phenomenon Picture ------------------------ .. image:: img/image162.jpeg