Arduino Nano 33 IoT - Rocker Switch Module
This tutorial instructs you how to use Arduino Nano 33 IoT with the DIYables ON/OFF Rocker Switch Module, a panel-style switch that clicks to one side and then stays there. Because it holds its position, it is a natural "pause" control. Think of a work timer on your desk: rocker on "I" and the seconds tick, rocker on "O" during a coffee break and the number waits for you. That is exactly what the second sketch of this page builds. In detail, we will learn:
- What the I and O marks, the board print and the SIG, VCC and GND pins mean
- Why the module takes its power from the 3.3V pin of the Arduino Nano 33 IoT, and never from the pin marked 5V
- How to program the Arduino Nano 33 IoT to show the rocker position as ON or OFF, three times per second
- How to program the Arduino Nano 33 IoT to run a seconds counter that pauses when the rocker goes OFF and goes on from the same value when it comes back ON

We suggest:
- Reading the Arduino Nano 33 IoT - Switch tutorial if you have a bare two-leg ON/OFF switch with no board around it.
- Reading the Arduino Nano 33 IoT - Button Module tutorial if your project needs a key that pops back up as soon as you let go.
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 Rocker Switch Module and Its Pinout

The heart of the module is a KCD1 rocker, a small black switch with a tilting top. Its contact closes when the "I" end is pushed down, and it opens when the "O" end is pushed down. The rocker is soldered onto a blue board of about 24 x 24 mm. A mounting hole sits in each corner, and a 3-pin header bent at a right angle comes out of one edge. DIYables sells the module in a pack of five.
Next to the rocker, the board print says "ON (H)" and "OFF (L)". This is a hint for your code: ON gives a HIGH level on SIG, and OFF gives a LOW level.
The rocker remembers its position. In switch words, it is a maintained (latching) SPST switch: one contact that is either open or closed. This changes the way you write code for it. A push button module is only pressed for a moment, so its sketch waits for a press. The rocker module never has a "press": your sketch reads its state (ON or OFF), and it reacts when that state changes.
When the switch is open, a 10 kΩ pull-down resistor on the board (the one marked "103") holds SIG at 0V. So SIG never floats, and you do not add any resistor yourself.
| ON/OFF Rocker Switch Module | |
|---|---|
| Switch | KCD1 rocker, SPST, maintained (latching) |
| Marks on the rocker | I = ON, O = OFF |
| Supply voltage (VCC) | 3.3V to 5V |
| SIG when ON | HIGH, the same voltage as VCC |
| SIG when OFF | LOW (0V), held by the on-board pull-down |
| On-board resistor | 10 kΩ pull-down on SIG |
| Header | 3 pins, 2.54 mm pitch, right-angle, male |
| Size with the pins | about 24 x 29 x 22 mm |
The text "6A 250VAC / 10A 125VAC" on the switch body is the rating of the bare switch. On this module, the switch only passes a weak logic signal to one input pin. Never connect mains power or a motor to the header.
The pin names are printed on the back of the board, right beside the header:
- VCC pin: must be connected to the 3.3V pin of the Arduino Nano 33 IoT. The module itself accepts 3.3V to 5V, but this board needs 3.3V
- SIG pin: must be connected to a digital pin of the Arduino Nano 33 IoT (D2 in this tutorial). It is HIGH while the rocker sits on "I" and LOW while it sits on "O"
- GND pin: must be connected to GND (0V)
※ NOTE THAT:
Turn the module over and read the labels before you plug in any wire. A module from another maker may put SIG, VCC and GND in a different order.
Wiring Diagram
Three jumper wires do the whole job, with no resistor and no breadboard. Pay attention to the power wire. When the rocker is ON, SIG simply passes on the voltage of VCC. The SAMD21 chip of the Arduino Nano 33 IoT runs at 3.3V, and its pins do not accept 5V. So VCC goes to the 3.3V pin, and D2 then never sees more than 3.3V.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module Pin | Arduino Nano 33 IoT Pin |
|---|---|
| VCC | 3.3V |
| SIG | D2 |
| GND | GND |
Want a stronger connection than jumper wires? Try a Screw Terminal Expansion Board for Arduino Nano: the Arduino Nano 33 IoT sits on it, and each pin gets its own screw terminal. Each wire goes to the screw terminal of the same pin, as in the image below.

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
Do not use the pin marked 5V on the Arduino Nano 33 IoT for this module. That pin is VUSB: it stays unconnected until you close a solder jumper under the board, and even then it gives 5V only while the board runs on USB power. 5V on SIG could damage pin D2.
※ NOTE THAT:
Please note that the Arduino Nano 33 IoT pins A4 and A5 have built-in pull-up resistors for I2C communication. Although these pins can be used as digital input pins, it is recommended to avoid using them for digital input. If you must use them, do NOT use internal or external pull-down resistors for these pins
How To Program For Rocker Switch Module
Everything here uses the built-in Arduino functions. No library is needed.
- The first step is to choose a name for D2, the pin where the SIG wire ends:
- In setup(), make that pin a plain INPUT with pinMode(). INPUT_PULLUP is not wanted here: the pull-down resistor on the module already decides the level while the switch is open.
- Ask digitalRead() for the position. HIGH means the rocker is on "I" (ON), and LOW means it is on "O" (OFF):
- To act only at the moment of a flip, keep the last accepted state in a variable. The metal contacts bounce for a few milliseconds after each flip, so a new level is accepted only after it has stayed the same for 50 milliseconds. millis() measures those 50 milliseconds, so the loop never has to stop and wait.
Arduino Nano 33 IoT Code for Rocker Switch Module - Print the Switch State
The first sketch is a plain check of the wiring. Every 300 milliseconds, it reads D2 and prints the level (1 or 0) and the matching word. The rocker stays where you put it, so this slow, repeated reading is all you need here, and bounce does not matter.
Detailed Instructions
Before you start, make sure the Arduino IDE can program your board: the Getting Started with Arduino Nano 33 IoT tutorial shows how to add it to the IDE.
- Wire the module as shown in the diagram. Check one more time that VCC is on 3.3V.
- Connect the Arduino Nano 33 IoT board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Pick the Arduino Nano 33 IoT board and its COM port.
- Copy the code above into a new sketch.
- Click the Upload button. When the IDE says "Done uploading", the sketch is running.
- Open the Serial Monitor and set it to 9600 baud.
- Leave the rocker on "O" for a moment, press the "I" side and count to two, then press the "O" side again.
About seven ON lines for two seconds: that fits the 300 ms reading period. If every line shows 0, the module has no power: look at the VCC and GND wires. If the upload fails because the IDE cannot find the board, press the reset button of the Arduino Nano 33 IoT twice quickly and upload again.
Arduino Nano 33 IoT Code for Rocker Switch Module - Seconds Counter With a Pause Switch
Now the rocker becomes the pause switch of a counter. While it is on "I", the count goes up by one every second, a new line appears, and the built-in LED of the board (LED_BUILTIN, on pin D13) is lit. Flip it to "O" at, say, 37 seconds: the sketch prints "Paused at 37 s", the LED goes dark, and the number waits. Flip it back to "I" and the count goes on from 37, not from 0.
How does it work? The sketch adds up only the time that passes while the rocker is ON. It also keeps the milliseconds, so a pause in the middle of a second does not lose that part of the second. Each flip prints one line, because a new level must stay the same for 50 milliseconds before the sketch believes it. Both the counting and the debounce use millis(), as in Arduino Nano 33 IoT - LED - Blink Without Delay. One more detail: the Arduino Nano 33 IoT talks to the PC through its own native USB port, so setup() waits up to 3 seconds for the Serial Monitor. Without a PC, the sketch simply goes on.
Detailed Instructions
- Do not change the wiring. The LED is already on the board.
- Put the rocker on "O".
- Paste the code above into the Arduino IDE in place of the first sketch, and click Upload.
- Open the Serial Monitor (9600 baud) right after the upload.
- Flip the rocker to "I", let it count for a few seconds, then flip it to "O". Wait a moment, and flip it to "I" again.
While the counter is paused, no new lines appear, however long you wait. The counter starts from 0 again only when the board restarts, for example after you press its reset button or unplug it.
Additional Knowledge
Rocker Module, Button Module or Bare Switch?
All three are inputs for the Arduino Nano 33 IoT, but they do not behave the same:
| Rocker Switch Module | Button Module | Bare ON/OFF Switch | |
|---|---|---|---|
| After you let go | stays ON or OFF | springs back (released) | stays ON or OFF |
| Pins | SIG, VCC, GND (labeled) | VCC, OUT, GND (labeled) | 2 legs, no labels |
| Extra resistor | none (10 kΩ pull-down on the board) | none (pull-down on the board) | none, but use INPUT_PULLUP |
| pinMode() | INPUT | INPUT | INPUT_PULLUP |
| Level when ON or pressed | HIGH | HIGH | LOW (inverted) |
| What the code looks for | the state and its changes | a short press | the state and its changes |
It is evident that the rocker module is the easiest way to give a Nano 33 IoT project a setting that stays put: the pins are labeled, nothing needs soldering, and ON reads as HIGH. The bare switch from the Arduino Nano 33 IoT - Switch tutorial behaves the same way but reads upside down. The button module is the right pick for a key that you press and release.
Why Not Count With delay(1000)?
It looks simpler to write delay(1000) and add one to the counter. But during that delay, the Arduino Nano 33 IoT does nothing else. A flip to "O" could wait up to one second before the sketch sees it, and the 50 ms bounce filter could not work at all. Each step would also take a little more than one second, because printing takes time too, so the count would slowly fall behind the clock. With millis(), loop() runs thousands of times per second: the sketch sees every flip at once, and each second is counted from the real clock of the board.