Logo

Interfacing Rotary Switch with Arduino

Rotary Switch

A Rotary Switch is a manual switch that is rotated to select one of many electrical connections. It's commonly used in control panels, audio gear, and mode selection circuits due to its mechanical reliability and ease of use.

Working Principle of Rotary Switch

The Rotary Switch works by turning a knob that aligns the common terminal with one of several output terminals. This mechanical rotation changes the circuit path, allowing selection of different inputs or modes.

Types of Rotary Switches

Single Pole Rotary Switch

  • User rotates the shaft to a specific position.
  • Common pin connects to one selected output terminal.
  • Changes signal path or operating mode.

Multi-Pole Rotary Switch

  • Each pole operates independently but rotates together.
  • Allows switching of multiple circuits simultaneously.
  • Ideal for multi-input or multi-mode systems.

Requirements

1. Arduino Board

2. Rotary Switch (2 to 12 positions)

3. Jumper Wires

4. Optional: Pull-up or Pull-down Resistors

Pin Configuration of Rotary Switch

Typical Rotary Switch

  • COM (Common): Connect to input signal or power.
  • POS1–POSn: Connect each position to a digital input pin or circuit line.
  • Ground (if applicable): Sometimes present for mechanical reference.

Wiring the Rotary Switch to Arduino

To wire a Rotary Switch to Arduino, connect the common pin to ground or voltage (based on logic), and connect each selectable pin to digital inputs. Use pull-up or pull-down resistors if needed to ensure accurate readings.

Algorithm

  1. Connect the Rotary Switch

    • Connect COM pin to GND (or 5V depending on design).
    • Connect each selectable position pin to a digital input on the Arduino.
  2. Configure Arduino Pins

    • Set the corresponding pins as INPUT or INPUT_PULLUP in setup().
    • Use digitalRead() in loop() to detect active position.
  3. Interpret Rotary Position

    • Check which pin is LOW or HIGH to identify the selected position.
    • Trigger appropriate actions like changing mode or activating components.
  4. Test the Setup

    • Upload the code to the Arduino.
    • Rotate the switch and observe the output changes via Serial Monitor or LED indicators.

Arduino Code

1const int rotaryPins[] = {5, 6, 7}; // Assuming 3-position rotary switch
2
3void setup() {
4  Serial.begin(9600);
5  for (int i = 0; i < 3; i++) {
6    pinMode(rotaryPins[i], INPUT_PULLUP);
7  }
8}
9
10void loop() {
11  for (int i = 0; i < 3; i++) {
12    if (digitalRead(rotaryPins[i]) == LOW) {
13      Serial.print("Rotary Switch: Position ");
14      Serial.println(i + 1);
15    }
16  }
17  delay(500);
18}
19

Applications of Rotary Switches

  • Mode selection in embedded systems
  • User interface control
  • Channel selector for audio equipment
  • Manual motor speed or direction control
  • Device function toggling
  • Simple menu navigation for DIY projects

Conclusion

Using a Rotary Switch with Arduino is a great way to allow manual input selection in your projects. Whether you're building a control panel or a mode selector, this interface is reliable and easy to implement.