Arduino - Rocker Switch Module
A rocker switch is the wide ON/OFF key you know from power strips: press the "I" side and it stays down until you press the "O" side. In this tutorial, we are going to learn:
- What the rocker switch module is, and how its three pins work
- How to connect the module to Arduino Uno with three jumper wires
- How to program Arduino to print the switch state (ON or OFF) a few times per second
- How to program Arduino to print one message only at the moment you flip the switch, with a millis() debounce that never pauses the loop

Hardware Required
Or you can buy the following kits:
| 1 | × | DIYables STEM V3 Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some links direct to products from our own brand, DIYables .
About Rocker Switch Module
The module is a black KCD1 rocker switch soldered on a small blue board, about 24 x 24mm, with a mounting hole in each corner. A 3-pin right-angle header sticks out of one side, so the jumper wires plug in straight. The rocker has two marks: "I" means ON and "O" means OFF. Next to it, the board is printed with "ON (H)" and "OFF (L)", which tells you the level that Arduino will see.
This switch is latching (also called maintained). It does not spring back like a push button. Whatever side you press, it stays there, even with the power off. So the program does not wait for a "press". It reads a state, and the interesting moment is when that state changes.
| Rocker Switch Module | |
|---|---|
| Switch | KCD1 rocker, ON/OFF, latching |
| Contact Type | SPST (one circuit, open or closed) |
| Operating Voltage | 3.3V to 5V |
| On-board Resistor | 10 kOhm pull-down on SIG (marked "103") |
| Output Logic | ON = HIGH, OFF = LOW |
| Header | 3-pin, 2.54mm, right-angle |
| Board Size | about 24 x 24mm, 4 mounting holes |
| Size with Pins | about 24 x 29 x 22mm |

The pin names are printed on the back of the board, next to the header.
- SIG pin: needs to be connected to a digital input pin of the Arduino Uno. It gives the VCC voltage (HIGH) when the rocker is on "I", and 0V (LOW) when it is on "O".
- VCC pin: needs to be connected to the 3.3V or the 5V pin of the Arduino Uno.
- GND pin: needs to be connected to GND (0V).
The switch body is printed with "6A 250VAC / 10A 125VAC". That is the rating of the bare switch alone. On this module, the switch only carries a tiny logic signal to Arduino. Never connect mains power or a motor to the header pins.
Maybe you have used the bare 2-leg switch from the Arduino - Switch tutorial. The module works in a simpler way:
| Bare ON/OFF Switch | Rocker Switch Module | |
|---|---|---|
| Wires to Arduino | 2 | 3 |
| Resistor | INPUT_PULLUP needed | pull-down already on the board |
| Reading when ON | LOW (inverted) | HIGH (not inverted) |
| Pin Labels | none | SIG, VCC, GND |
Wiring Diagram
The module plugs into Arduino with three jumper wires. No breadboard and no resistor are needed.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module Pin | Arduino Uno Pin |
|---|---|
| VCC | 3.3V (or 5V) |
| SIG | Pin 7 |
| GND | GND |
Loose wires are a common cause of strange bugs. Put a Screw Shield V2 or a Proto Screw Terminal Block Shield on top of the Arduino Uno, then tighten each wire under a screw. This is how it looks with the Screw Shield V2:

This image is created using Fritzing. Click to enlarge image
The diagram uses the 3.3V pin for VCC. You can move that wire to 5V: SIG then goes up to 5V when ON, which is fine for the Arduino Uno. Pin 7 is also just a choice. Any free digital pin works if you change the number at the top of the code.
How To Program For Rocker Switch Module
- Give the input pin a name, so you only change one line if you move the wire:
- Make it a plain input with pinMode(). Do not use INPUT_PULLUP. The module already holds SIG at LOW when the switch is OFF.
- Read the state with digitalRead(). HIGH means the rocker is on "I":
- To react to a flip, keep the last known state in a variable and compare each new reading with it. Use millis() to check that a new level stays the same for 50 ms before you accept it.
Arduino Code - Rocker Switch Module ON/OFF State
This first sketch is a wiring test. It prints the raw level of SIG (1 or 0) and the matching word, about two and a half times per second.
Quick Steps
- Connect the module to Arduino as in the wiring diagram.
- Connect Arduino to PC via USB cable.
- Open Arduino IDE, then choose the Arduino Uno board and its COM port.
- Copy the above code and paste it to Arduino IDE.
- Click Upload button on Arduino IDE to upload code to Arduino.
- Open the Serial Monitor and set the baud rate to 9600.
- Press the "I" side of the rocker, wait a moment, then press the "O" side.
The line repeats as long as the switch stays in one place. That is fine for a test, but most projects do not want it.
If you only ever see 0, turn the module over and read the labels: the wire on pin 7 must sit on SIG, and VCC must go to 3.3V or 5V.
Arduino Code - Detect When the Rocker Switch Is Flipped
Think of a rocker switch on a machine. It may stay ON for an hour. During that hour, the loop() runs many thousands of times. If your code starts a motor, sends a message or counts something every time it sees ON, it does that job again and again. In real projects, you usually want to act once: start when the switch turns ON, stop when it turns OFF. So the normal way to use a latching switch is to watch for the change, not the level.
This sketch does that:
- In setup(), it reads where the rocker already is. A latching switch can be ON before Arduino even starts.
- In loop(), it compares each reading with the last known position.
- When the level changes, it does not believe it at once. The contacts bounce for a few milliseconds. The level must stay the same for 50 ms, measured with millis().
- Only then it prints "Switch turned ON" or "Switch turned OFF", with the time in milliseconds.
Unlike delay(), millis() never stops the loop. So you can add other work to the same sketch later.
Quick Steps
- Keep the same wiring.
- Copy the above code and paste it to Arduino IDE.
- Click Upload button on Arduino IDE to upload code to Arduino.
- Open the Serial Monitor (baud rate 9600).
- Flip the switch ON, wait a few seconds, then OFF. Do it twice.
The Serial Monitor now stays quiet while you leave the switch alone, no matter how long. Each flip gives exactly one line. To make the switch do something, put your own code in the place of the two Serial.println() lines.
For more about contact bounce, see Arduino - Button - Debounce. Need a key that springs back after each press? See Arduino - Button Module.
Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.