Arduino UNO R4 - Rocker Switch Module
In this guide, we will learn how to use the DIYables ON/OFF rocker switch module with the Arduino UNO R4, and turn it into the run/stop switch of a tiny machine. Fans, drills and power strips often have this kind of switch on the front: press the "I" side and the device works, press the "O" side and it rests. Our machine is the Arduino UNO R4 itself. While the rocker is on "I", it runs a job that blinks the built-in LED and counts the cycles. On "O", it stops. In detail, we will learn:
- What the "I" and "O" marks mean, and what the SIG, VCC and GND pins do.
- How to connect the module to the Arduino UNO R4 WiFi or Minima with three jumper wires.
- How to print the rocker position, ON or OFF, to the Serial Monitor.
- How to start and stop a job with the switch, using a 50 ms debounce and millis() instead of delay().

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables STEM V4 IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables STEM V4B IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Rocker Switch Module
The module is a small blue board, about 24 x 24mm, with four mounting holes. A black KCD1 rocker switch sits on top. One half of the rocker shows "I", the other half shows "O". Push the "I" half down and the switch is ON. Push the "O" half down and it is OFF. The text printed next to the switch says the same: "ON (H)" and "OFF (L)". A 3-pin right-angle male header (2.54mm pitch) sticks out at one edge, so the wires come out from the side.
The rocker is a maintained (latching) switch. Once you flip it, it stays there, even when nobody touches it. That is the big difference from a push button. With a button, the code waits for a press and a release. With this switch, the code reads a position, ON or OFF, and does something when that position changes.

The pin names are printed on the back of the board, next to the header:
- SIG pin: connect to a digital input pin of the Arduino UNO R4. It is HIGH (the VCC voltage) when the rocker is on "I", and LOW (0V) when it is on "O".
- VCC pin: connect to 3.3V or 5V.
- GND pin: connect to GND (0V).
| ON/OFF Rocker Switch Module | |
|---|---|
| Switch | KCD1 rocker, ON/OFF, SPST |
| Action | maintained (latching), it stays where you put it |
| Marks | I = ON, O = OFF |
| Header | 3 pins, 2.54mm pitch, right-angle (SIG, VCC, GND) |
| Operating voltage | 3.3V to 5V |
| SIG when ON | HIGH (same as VCC) |
| SIG when OFF | LOW (0V) |
| On-board resistor | 10 kOhm pull-down on SIG |
| Size with pins | about 24 x 29 x 22mm |
The pull-down resistor (marked "103") holds SIG at LOW while the switch is open, so the pin never floats. For this reason, the code uses plain INPUT mode. Do not turn on INPUT_PULLUP, and do not add a resistor of your own.
SIG gives out the same voltage that you feed to VCC. The input pins of the Arduino UNO R4 accept 5V, so VCC can go to the 3.3V pin or to the 5V pin. The wiring diagram below uses 3.3V.
You may see "6A 250VAC / 10A 125VAC" on the side of the switch. That is the rating of the bare switch part. On this module, the switch only sends a small logic signal to an input pin. Never run mains power or motor current through the header pins of the module.
Like all mechanical switches, the contacts bounce for a few milliseconds at each flip. A sketch that reads the switch a few times per second does not notice it. A sketch that reacts to each change should wait until the new level is stable, for example 50 ms. The second example below does this.
How the module compares with the plain 2-leg switch of the Arduino UNO R4 - Switch tutorial:
- The plain switch needs INPUT_PULLUP and reads LOW when it is ON. The module reads HIGH when it is ON, with plain INPUT.
- The module has its resistor on board and named pins, so you just plug in three wires.
If your project needs a key that springs back after each press instead, see Arduino UNO R4 - Button Module.
Wiring Diagram
Only three jumper wires are needed, and no breadboard. Connect SIG to digital pin 7, VCC to the 3.3V pin, and GND to one of the GND pins of the Arduino UNO R4.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module Pin | Arduino UNO R4 Pin |
|---|---|
| SIG | 7 |
| VCC | 3.3V (or 5V) |
| GND | GND |
If you plan to keep this circuit, think about screw terminals. The Arduino UNO R4 works with both the Proto Screw Terminal Block Shield and the Screw Shield V2. Both turn the header pins into screw terminals. The wiring stays the same. Only the wires now go to the screw terminals, as shown below.

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
How To Program For Rocker Switch Module
No library is used. A few built-in functions are enough.
- Name the pin that SIG is wired to:
- Make it a plain input, because the pull-down is already on the module:
- Read the position. HIGH means ON ("I"), LOW means OFF ("O"):
- To react to a flip, keep the last accepted state. When the reading is different, note the time with millis(), and accept the new state only after it has stayed the same for 50 ms. Nothing has to wait, so the rest of the code keeps running.
Arduino UNO R4 Code - Read the Rocker Switch Position
The first sketch is a quick test of the wiring. About two and a half times per second, it reads SIG and prints the raw value next to its meaning.
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Make the three connections shown in the wiring diagram.
- Connect the Arduino UNO R4 to your computer with a USB Type-C cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino UNO R4 board (e.g., Arduino UNO R4 WiFi or Arduino UNO R4 Minima) and COM port.
- Copy the code above and paste it into the Arduino IDE.
- Click the Upload button.
- Open the Serial Monitor and set it to 9600 baud.
- Begin with the rocker on "O". After a few lines, press the "I" side down, wait about two seconds, and then go back to "O".
The same line keeps coming as long as the rocker stays put, because the switch holds its position by itself. The 400 ms pause also hides the contact bounce. If the value stays at 0 in both positions, check the VCC wire first: without power on VCC, the pull-down keeps SIG at LOW all the time.
This is good for a test, but a machine should act when the switch changes, not print the same line again and again. That is what the next sketch does.
Arduino UNO R4 Code - Run/Stop Switch for a Machine
Now the Arduino UNO R4 plays a small machine, and the rocker is its run/stop switch.
- Rocker on "I": the job runs in cycles of one second. In each cycle, the built-in "L" LED is on for half a second and off for half a second, and the Serial Monitor prints "Running - cycle" with the cycle number.
- Rocker on "O": the job stops at once. The LED goes off, and "Stopped" is printed one time.
How the sketch works:
- Debounce: every pass of loop() reads SIG. If the reading changes, the sketch saves the time. The reading becomes the new switch state only after it has stayed the same for 50 ms. So the bounce of one flip cannot start and stop the job several times.
- The job is timed with millis(), not delay(). The sketch checks the switch thousands of times per second, even while the LED blinks. This is why the job stops right away and not at the end of a cycle. If millis() is new to you, see Arduino UNO R4 - Blink LED Without Delay.
- The cycle counter is not reset when the job stops. Like the counter of a real machine, it shows the total number of cycles since power-up.
Detailed Instructions
- Keep the same wiring.
- Paste this code into a new sketch and click the Upload button.
- Open the Serial Monitor at 9600 baud, and keep an eye on the "L" LED of the board. If you do not see the first "Stopped" line, press the RESET button of the board once.
- With the rocker on "O", flip it to "I" and let the job run for about four seconds. Flip it back to "O". Then run it again for about two seconds and stop it.
The second run continues from cycle 5, because the counter keeps the total. If you want every run to start again from cycle 1, add the line cycleCount = 0; inside the stopJob() function.
To give the job real work, put your own code in beginCycle(). For example, take one sensor reading per cycle, or move a motor one step.
Project Ideas
More ways to use the rocker switch module with the Arduino UNO R4:
- A master switch for a small robot: the motors may move only while the rocker is on "I".
- A data logger switch: the Arduino UNO R4 WiFi sends sensor values to the cloud only while the switch is ON.
- A "machine status" display: show RUN or STOP on the built-in 12x8 LED matrix of the Arduino UNO R4 WiFi.
- An enable switch for a timer: a countdown runs only while the switch is ON and pauses when it is OFF.