博文

目前显示的是标签为“Resistor”的博文

How to wire a rocker switch to an Arduino?

图片
Wiring a rocker switch to an Arduino is a fundamental skill for controlling your projects. There are two main ways to do it, depending on your goal: As a Digital Input (Read the Switch State):  This is the most common use. You read whether the switch is ON or OFF to trigger actions in your code (e.g., turn on an LED, start a motor, change a mode). As a Power Switch (Control Arduino's Power):  This is less common and physically cuts power to the entire Arduino board. This guide will focus on the first and most useful method: using the switch as a digital input. Method 1: Using the Switch as a Digital Input (Recommended) In this setup, the switch doesn't power the Arduino on/off. Instead, the Arduino is always powered, and it constantly checks the state of the switch pin to decide what to do in its code. What You'll Need Arduino Board (Uno, Nano, etc.) A Rocker Switch (SPST or SPDT, see explanation below) A 10k Ohm Resistor (Pull-down resistor) Jumper Wires A Breadboard St...