Arduino MKR WiFi 1010 - Rocker Switch Module
Many machines hide a service switch inside the case. Before a technician opens the box, they flip it, and the machine knows that someone is working on it. On this page, the DIYables ON/OFF rocker switch module becomes that service switch for an Arduino MKR WiFi 1010. In this tutorial, we are going to learn:
- What the "I" and "O" marks on the rocker mean, and what the SIG, VCC and GND pins do
- Why the module must take its power from the 3.3V VCC pin of the MKR, never from the 5V pin
- How to program Arduino MKR WiFi 1010 to print the switch position and the raw level of D2, about three times per second
- How to program Arduino MKR WiFi 1010 to run a maintenance mode: while the switch is ON, the built-in LED blinks slowly and a reminder comes every 3 seconds, with a 50 ms debounce and no delay()

Hardware Preparation
| 1 | × | Arduino MKR WiFi 1010 | |
| 1 | × | Micro USB Cable | |
| 1 | × | ON/OFF Rocker Switch Module | |
| 1 | × | Jumper Wires |
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
Look at a power strip or at the back of a PC power supply, and you will probably find this switch: a black key shaped like a small seesaw, with "I" on one half and "O" on the other. The DIYables module puts that KCD1 rocker on a small blue PCB of about 24 x 24mm, with four screw holes. A right-angle header with three pins comes out of one edge, so the jumper wires plug in from the side. One pack holds five modules.
Press the "I" half down and the switch is ON. Press the "O" half down and it is OFF. Beside the rocker, the board is printed with "ON (H)" and "OFF (L)". The letter in brackets tells you what the MKR will read: H for HIGH, L for LOW.
The rocker is a maintained switch. It keeps its position when you take your finger away, and it still has that position after the power is cut. A push button, like the one in the Arduino MKR WiFi 1010 - Button tutorial, is only down while you hold it. This changes what the code looks for. A button sketch waits for a press. A rocker sketch asks "ON or OFF?" and does something when the answer changes.
| Rocker Switch Module | |
|---|---|
| Switch | KCD1 rocker, two positions (I = ON, O = OFF) |
| Action | maintained, SPST (one contact, open or closed) |
| Supply Voltage (VCC) | 3.3V to 5V |
| Signal (SIG) | HIGH when ON, LOW when OFF |
| Pull-down Resistor | 10 kOhm on the board (marked "103") |
| Header | 3 pins, 2.54mm pitch, right-angle male |
| Size | board about 24 x 24mm, about 24 x 29 x 22mm with the pins |
Pinout

The pin labels are on the back of the board, beside the header. Seen from the top with the header on the right, the pins are SIG, VCC and GND, from top to bottom.
- SIG pin: needs to be connected to a digital pin of Arduino MKR WiFi 1010 (D2 on this page). It goes HIGH, to the same voltage as VCC, while the "I" side is down. It goes LOW (0V) while the "O" side is down.
- VCC pin: needs to be connected to the VCC pin of Arduino MKR WiFi 1010. On this board, the pin named VCC is the 3.3V output.
- GND pin: needs to be connected to a GND pin of Arduino MKR WiFi 1010 (0V).
When the rocker is on "O", the switch is open, and the 10 kOhm resistor on the board pulls SIG down to GND. D2 always sees a clear level, so no extra resistor goes into the circuit. In the code, set the pin as plain INPUT. INPUT_PULLUP is not needed here.
※ NOTE THAT:
SIG carries the same voltage as VCC, so VCC decides how high the signal goes. The SAMD21 chip on the MKR WiFi 1010 takes 3.3V at most on its pins. The 5V and VIN pins are only one or two pins away from VCC on the same header, so read the labels twice before you plug in the red wire. 5V on SIG can damage pin D2.
You may also read "6A 250VAC / 10A 125VAC" on the side of the rocker. These numbers are for the bare rocker as a part. On this module, it only passes a small 3.3V signal into a pin of the MKR. Keep mains wires and motor currents away from the three header pins.
Have you used a bare 2-leg ON/OFF switch before? That one needs INPUT_PULLUP in the code, and it reads LOW when it is ON, which feels upside down. The module reads HIGH when it is ON, has its resistor on the board and has named pins. For another switch that stays where you put it, see Arduino MKR WiFi 1010 - Slide Switch.
Wiring Diagram
Three wires join the module to the MKR, with no resistor in between: SIG to D2, VCC to VCC (3.3V) and GND to GND.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module | Arduino MKR WiFi 1010 |
|---|---|
| SIG | D2 |
| VCC | VCC (3.3V) |
| GND | GND |
The Micro USB cable powers the MKR, and the MKR powers the module through its VCC pin. D2 is only a choice. Another free digital pin also works if you change the number at the top of the code. Skip pin 6, because the built-in LED of the board is on pin 6, and the second sketch blinks it.
How To Program For Rocker Switch Module
- Name the pin of the SIG wire: const int ROCKER_PIN = 2;
- Make it a plain input in setup(): pinMode(ROCKER_PIN, INPUT);. The pull-down on the module holds the OFF level, so the internal pull-up stays off.
- Read the rocker: int level = digitalRead(ROCKER_PIN);. HIGH means the "I" side is down (ON). LOW means the "O" side is down (OFF).
- Catch a flip: keep the raw reading and the accepted state in two variables. Each time the raw reading changes, save millis(). When the raw reading has not moved for 50 ms and it is not the same as the accepted state, it becomes the new state.
Arduino Code - Read the Rocker Switch Module
Start with a simple test of the wiring. Every 300ms, the sketch reads D2 and prints the switch position next to the raw value.
Detailed Instructions
- Plug the Arduino MKR WiFi 1010 into your PC with the Micro USB cable. If this is your first MKR project, follow Getting Started with Arduino MKR WiFi 1010 to add the board to the Arduino IDE.
- Wire the module as the diagram shows. Look at the VCC wire once more: it must end on VCC, not on 5V or VIN.
- Navigate to the Arduino IDE. In the Tools menu, pick the Arduino MKR WiFi 1010 board and the port it uses.
- Copy the above code into a new, empty sketch.
- Click the Upload button and wait until the IDE says the upload is done.

- Open the Serial Monitor and set the baud rate to 9600.
- With the rocker on "O", wait a second. Then press the "I" side, wait about two seconds, and press the "O" side again.
The line repeats for as long as the rocker stays where it is. This sketch does not care about contact bounce: the bounce lasts a few milliseconds, and the next reading comes 300ms later.
If the value stays at 0 even on "I", check that the D2 wire is on SIG and that the VCC wire is on the VCC pin of the MKR.
Arduino Code - Maintenance Mode Switch
Now the rocker gets a real job. Think of an MKR WiFi 1010 inside a weather station on a roof, or inside a vending machine. When a technician comes to work on it, they flip the rocker to "I". The board stops its normal work and shows that it is being serviced. When the work is done, they flip it back to "O". The sketch does this:
- Switch ON: the built-in LED blinks slowly (1 second on, 1 second off), and the Serial Monitor shows "MAINTENANCE MODE" at once, then again every 3 seconds, with the seconds since the switch went ON.
- Switch OFF: the LED goes dark, and "NORMAL MODE" is printed one time.
- At power-up, the sketch reads where the rocker already is. A maintained switch can be left ON while the board is unplugged.
- Debounce: a new level counts only after it stays the same for 50 ms, measured with millis(). Nothing in the sketch uses delay(), so the loop is free for the normal job of your project, for example the WiFi code.
The built-in LED is the small LED on the MKR board, wired to pin 6. The code uses its name, LED_BUILTIN, so no extra part is needed.
There is one more line to know: while (!Serial && millis() < 3000); in setup(). The MKR talks to the PC through the native USB port of its own chip. After a reset, the Serial Monitor needs a short time to connect again. This line waits up to 3 seconds for it, so the first mode line is not lost. Without a PC, the board simply goes on after 3 seconds.
Detailed Instructions
- Keep the same wiring, and put the rocker on "O".
- Replace the first sketch in the Arduino IDE with the code above.
- Click the Upload button.
- Open the Serial Monitor at 9600 baud.
- Flip the rocker to "I" and watch the LED for about 7 seconds. Flip it to "O". Then do a short second round of about 4 seconds.
Each flip gives exactly one mode line, even though the contacts bounce. While the switch stays ON, only the reminder repeats, and the LED keeps its slow blink. If the first "NORMAL MODE" line is missing, the Serial Monitor connected after the 3 seconds. Flip the rocker, or press the RESET button of the MKR one time.
To use it in your own project, put the normal job in the empty else part at the end of loop(). It runs only while the switch is OFF, so it pauses by itself during maintenance. To learn more about contact bounce, see the Arduino MKR WiFi 1010 - Button - Debounce tutorial.