Arduino Nano - Rocker Switch Module
This tutorial instructs you how to use Arduino Nano to read the DIYables ON/OFF Rocker Switch Module. It is the same style of switch you see on extension leads and small appliances, but it sits on a small blue board with three labeled pins. Once you flip it, it stays there. So the Nano never waits for a press: it simply checks whether the switch is ON or OFF right now. In the last example, the switch becomes the arm switch of a tiny alarm box. In detail, we will learn:
- How to connect Arduino Nano to the rocker switch module with three wires: SIG, VCC and GND
- How to program Arduino Nano to show the rocker position (ON or OFF) on the Serial Monitor every 0.4 seconds
- How to program Arduino Nano to arm and disarm a small alarm box: a fast-blinking LED while armed, a dark LED while disarmed, and one message for each flip

We suggest:
- Utilizing a bare ON/OFF switch if you want to fit the switch into a hole in a box and wire its two legs yourself.
- Utilizing a button module if you are looking for a key that jumps back after each press. For a very small switch that sits on a PCB, see Arduino Nano - Slide Switch.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of ON/OFF Rocker Switch Module
Look at the module from the top and you see a black KCD1 rocker switch on a square blue board (about 24 x 24mm). Every corner has a hole, so you can screw the module to the lid of a box. The three header pins are bent at 90 degrees and point sideways. On the rocker, "I" stands for ON and "O" stands for OFF. The print beside it, "ON (H)" and "OFF (L)", tells the code what to expect: H for HIGH, L for LOW.
This is a maintained switch (also called latching). Tip it to "I" and it stays at "I" until you tip it back. A push button works the other way: it is only ON while your finger holds it. That is why there is no press to catch here. The Nano just asks for the current position, and it acts when the answer is not the same as last time.
Inside, it is a simple SPST switch (one contact that is open or closed). When the switch is closed, the SIG pin is joined to VCC. When it is open, a 10kΩ pull-down resistor on the board (marked "103") pulls SIG down to 0V. Thanks to that resistor, the input never floats, and you do not need any extra resistor.
| ON/OFF Rocker Switch Module | |
|---|---|
| Switch | KCD1 rocker, SPST, maintained (stays in place) |
| Rocker marks | I = ON, O = OFF |
| Operating voltage | 3.3V to 5V |
| Output on SIG | HIGH (the VCC voltage) when ON, LOW (0V) when OFF |
| Resistor on board | 10kΩ pull-down on the SIG line |
| Header | 3 pins, 2.54mm pitch, right-angle, male |
| Size | about 24 x 29 x 22mm with the pins |
| Pack | 5 modules |
What about the "6A 250VAC / 10A 125VAC" text on the switch? It belongs to the switch part alone. The module uses that switch for one small job: giving a logic level to a Nano pin. Keep mains wires and motor currents far away from its header.

Turn the module over to find the pin labels, right beside the header:
- SIG pin: must be connected to D2 (or another free digital pin) of Arduino Nano. It is HIGH while the rocker is on "I" and LOW while it is on "O"
- VCC pin: must be connected to the 3V3 pin of Arduino Nano (the 5V pin also works). When the switch is ON, SIG takes this voltage
- GND pin: must be connected to GND (0V)
※ NOTE THAT:
Other makers may put these three pins in a different order. Always follow the labels printed on your own module, not the order in a photo.
Wiring Diagram
In the diagram, the VCC wire of the module goes to the 3V3 pin of the Nano. The Nano reads 3.3V as HIGH, so 3V3 is enough. If that pin is already busy, use the 5V pin instead. SIG goes to D2, and both sketches of this tutorial read that pin.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module | Arduino Nano |
|---|---|
| SIG | D2 |
| VCC | 3V3 (or 5V) |
| GND | GND |
A screw terminal keeps each wire tight, even when the board shakes. A Screw Terminal Expansion Board for Arduino Nano solves this. Plug the Arduino Nano into it and screw the wires in. This is how it looks with the screw terminal board:

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
How To Program For Rocker Switch Module
You do not need a library. Think of the switch as a state that you check, not as an event that you wait for.
- The first step is to give a name to the Arduino Nano pin that receives the SIG signal:
- Set that pin to INPUT mode in setup() with pinMode(). Skip INPUT_PULLUP: the module already has its pull-down resistor, and the internal pull-up would work against it.
- To do something only at the moment of a flip, store the last confirmed state and compare each new reading with it. The metal contacts bounce for a few milliseconds when you flip the rocker. So trust a new level only when it has not changed for about 50 milliseconds.
Arduino Nano Code for Rocker Switch Module - Read ON/OFF
This first sketch is a simple wiring test. It reads SIG every 400 milliseconds and prints the raw value (1 or 0) next to the word ON or OFF. A switch that stays in place does not need anything faster, and no debounce is needed at this slow speed.
Detailed Instructions
- If this is the first time you use Arduino Nano, see how to set up the environment for Arduino Nano in Arduino IDE.
- Wire the components as shown in the diagram.
- Connect the Arduino Nano board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- In the Tools menu, set the board to Arduino Nano and pick its COM port. Many Nano clones need ATmega328P (Old Bootloader) under Processor if the upload fails.
- Copy the code above into a blank sketch.
- Click Upload and wait for "Done uploading".
- Open the Serial Monitor and pick 9600 baud in its speed list.
- Start with the rocker on "O". After a moment, press the "I" side, wait a second or two, then press the "O" side again.
- Each line shows the level on D2 and what it means:
Do you see only 0, even on "I"? Then the module gets no power: check that VCC goes to the 3V3 or 5V pin. If the value jumps around at random, the SIG wire is probably not in D2.
Arduino Nano Code for Rocker Switch Module - Arm and Disarm an Alarm Box
Many alarm boxes have one switch on the side. ON means "watch the room". OFF means "I am home, stay quiet". This sketch turns the rocker module into that arm switch:
- Rocker on "I": the Serial Monitor prints "System ARMED", and the small "L" LED of the Nano (LED_BUILTIN, pin D13) blinks fast, five times per second.
- Rocker on "O": it prints "System DISARMED" and the LED stays off. It also tells you how long the box was armed.
Each flip prints one line only. A new level must stay steady for 50 milliseconds before the sketch accepts it, so contact bounce cannot print extra lines. Both the debounce and the blinking use millis() instead of delay(), like in Arduino Nano - LED - Blink Without Delay. The loop never stops, so the Nano sees a flip at once, even in the middle of a blink.
Detailed Instructions
- Leave the wiring as it is. The LED is already on the Nano board.
- Paste this sketch into Arduino IDE in place of the first one, then click Upload.
- Set the rocker to "O" and open the Serial Monitor (9600 baud).
- Flip the rocker to "I": the "L" LED starts to flash quickly. Wait a few seconds and flip it back to "O": the LED goes dark.
- Do it once more and keep it armed a bit longer. The output looks like this:
If the rocker is already on "I" when the Nano starts, the first state line says "System ARMED" and the LED blinks right away.
Additional Knowledge
Rocker Switch Module vs Bare ON/OFF Switch
| Rocker Switch Module | Bare ON/OFF Switch | |
|---|---|---|
| Pins | 3, labeled SIG, VCC, GND | 2 legs, no labels |
| Resistor | 10kΩ pull-down already on the board | none, so use the internal pull-up |
| pinMode() setting | INPUT | INPUT_PULLUP |
| Level when the switch is ON | HIGH | LOW (upside down) |
| How it is connected | jumper wires on a 2.54mm header | wires soldered to the legs |
| How it is mounted | screws through the 4 corner holes | pressed into a cut-out in a panel |
It is evident that the module is the faster way to get started: no soldering, labeled pins, and ON reads as HIGH. The bare ON/OFF switch is still the better pick when the switch must sit in the wall of a box.
Project Ideas
- A door alarm: add a door sensor and a piezo buzzer to the arm/disarm sketch, and let the buzzer sound only while the system is armed
- A service switch that pauses a pump or a fan while you work on it
- A unit switch that shows a temperature in °C on one side and in °F on the other
- A quiet-hours switch that turns off all the beeps of a clock project at night