Arduino UNO Q - Rocker Switch Module
Power strips, desk lamps and many tutorial machines share the same black switch with an "I" and an "O" on it: the rocker switch. You press one side, it clicks, and it stays there. The DIYables ON/OFF Rocker Switch Module puts this switch on a small board with three labeled pins, so a microcontroller can read it with no extra parts. With the Arduino UNO Q you get more than a line on a screen: the STM32 MCU checks the switch, and Python on the Linux side can pass the result to your phone. At the end of this page, a Telegram bot tells you if your machine is ON or OFF, and it writes to you the moment someone flips the switch.
Step by step, you will learn:
- What the rocker switch module is, and what "I", "O", "ON (H)" and "OFF (L)" mean
- Why its VCC pin goes to 3.3V on the Arduino UNO Q
- How to connect it with three jumper wires
- How the MCU reads the switch and prints ON or OFF
- How to filter out contact bounce without delay()
- How Python on Linux gets the switch state from the MCU with Bridge.call()
- How to build a Telegram bot that answers /state and alerts you on every flip
- How to use OpenClaw on Arduino UNO Q with the rocker switch module

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 the Rocker Switch Module
The DIYables ON/OFF Rocker Switch Module is a black KCD1 rocker switch, the kind you see on a power strip, soldered onto a small blue board. The board is about 24 x 24 mm and has four mounting holes, so you can screw it to a box or a panel. A 3-pin right-angle header sticks out of one side, ready for jumper wires. The modules come in a pack of five.
The rocker carries two marks. Push the "I" side down and the switch is ON. Push the "O" side down and it is OFF. Next to the switch, the board print says the same in signal words: "ON (H)" and "OFF (L)", where H means HIGH and L means LOW.
This is a maintained switch (SPST, latching). It keeps its position after you take your finger away. A push button is different: it springs back at once. So your program does not wait for a press here. It reads a state, ON or OFF, and it can do something when that state changes.

| Item | Value |
|---|---|
| Switch | KCD1 rocker, SPST, maintained (stays in place) |
| Marks on the rocker | I = ON, O = OFF |
| Supply voltage (VCC) | 3.3V to 5V |
| SIG when ON | HIGH (the VCC voltage) |
| SIG when OFF | LOW (0V) |
| Resistor on the board | 10 kΩ pull-down (marked 103) |
| Header | 3-pin, 2.54 mm, right-angle male |
| Size with the pins | about 24 x 29 x 22 mm |
The pin names are printed on the back of the board, next to the header:
- SIG: the signal output. Wire it to a digital pin of the MCU (pin 7 on this page)
- VCC: power for the module. On the Arduino UNO Q, use 3.3V
- GND: ground. Wire it to a GND pin of the board
※ NOTE THAT:
⚠️ Why 3.3V and not 5V? When the rocker is on "I", SIG passes on whatever voltage is on VCC. The STM32 MCU of the UNO Q works with 3.3V logic, so VCC on 3.3V gives SIG the MCU's own HIGH level. Most MCU pins can stand 5V, but A0 and A1 cannot. If you ever move the SIG wire to one of them, 3.3V keeps it safe. So make 3.3V your habit and keep VCC off the 5V and VIN pins.
About the "6A 250VAC / 10A 125VAC" print: this is what the bare switch can carry. On this module, the switch only passes a tiny logic signal to the UNO Q. Never connect mains power or a motor to the module pins.
Contact bounce: when the rocker clicks over, the metal contacts chatter for a few milliseconds before they settle. A sketch that looks at the pin only twice per second never notices it. A sketch that reacts to each change should wait until the level has been steady for about 50 ms. The Bridge sketch on this page does exactly that.
Module or bare rocker switch? The bare two-leg switch in Arduino UNO Q - Switch needs INPUT_PULLUP and reads LOW when it is ON, so the logic is upside down. The module has named pins and its own pull-down, and ON simply reads HIGH. If you need a switch that springs back instead, the Arduino UNO Q - Button Module uses the same three pins and the same wiring.
Wiring Diagram
Only three wires are needed. There is no breadboard and no resistor to add. Before you power the board, check one thing: VCC must sit on the 3.3V pin.

This image is created using Fritzing. Click to enlarge image
| Rocker Switch Module Pin | Arduino UNO Q Pin |
|---|---|
| SIG | Pin 7 |
| VCC | 3.3V |
| GND | GND |
Jumper wires can come loose when you move the project. Try a Screw Shield V2 or a Proto Screw Terminal Block Shield: it sits on the Arduino UNO Q, 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:
Nothing is special about pin 7. You can use another digital pin, as long as ROCKER_SWITCH_PIN at the top of both sketches has the same number.
How To Program For Rocker Switch Module
Reading this module needs no library and only a few lines. These are the pieces you will meet in the sketches:
- Make the SIG pin an input with pinMode(). Plain INPUT is right, because the pull-down is already on the board. INPUT_PULLUP would work against it:
- To react to a flip, note the time of every raw change with millis(). Accept the new level only when it has stayed the same for 50 ms. loop() never stops this way:
- To share the state with Python on Linux, put it in a function and register it with Bridge.provide():
Arduino UNO Q Code
Only the STM32 MCU of the UNO Q touches the header pins, so the first sketch runs there. The Qualcomm MPU, with Debian Linux and Python, has nothing to do yet. It gets its own job in the Bridge section.
Read the Switch State
This sketch answers one question twice per second: what is the switch doing now? Each line shows the raw value of SIG and the word ON or OFF.
Detailed Instructions
Is this your first Arduino UNO Q project? Prepare Arduino App Lab with Getting Started with Arduino UNO Q first.
- Connect the module: SIG to pin 7, VCC to 3.3V, GND to GND. Look at the VCC wire again before you go on.
- Power and data: One USB-C cable from the board to your computer does both.
- Arduino App Lab: Start it. Your board shows up after a few seconds.
- New App: Click Create New App.

- Enter RockerSwitchModule as the name and click Create.

- Code: In the new App, sketch/sketch.ino holds an empty sketch. Swap it for the code above. This sketch uses no library, and the other files need no change.
- Run: Click the Run button.

- Flip it: Press the "I" side, count to two, then press the "O" side.
App Lab Console Output
While the switch rests, the lines repeat the same thing. They change as soon as you flip it. Two quick checks if something looks wrong:
- Never a 1? The SIG wire is not on pin 7, or VCC is not connected.
- Random 0s and 1s while it is OFF? The GND wire is loose. The pull-down on the module needs GND to hold SIG at LOW.
Bridge: Linux + MCU
Pin 7 is wired to the MCU, not to Linux. So when Python wants the switch state, it sends a request over Bridge:
- The MCU keeps the answer ready. It reads SIG all the time and accepts a flip only after 50 ms of steady signal, so the answer is never a bounce
- It shares one read-only value with Bridge.provide(): get_switch_state returns 1 for ON and 0 for OFF
- Python asks once per second with Bridge.call("get_switch_state"). It prints the answer and marks the line when the value is different from the last one
- A limit to know: a flip to OFF and straight back to ON within the same second can fall between two calls. For a switch that stays in place for minutes or hours, this does not matter
- ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) belong to the router. Your code must never open them
In short: you flip the rocker → the MCU waits 50 ms and stores ON or OFF → Python calls get_switch_state → Python prints 1 or 0.
MCU Code (Bridge)
Python Code (Bridge)
Detailed Instructions
- Another App: Click Create New App once more. This time the name is RockerSwitchBridge.
- Sketch: Paste the MCU code into sketch/sketch.ino. It needs one library:
- Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.

- Search for Arduino_RouterBridge created by Arduino and click the Install button.
- Python: The same App also has a Python file. Paste the Python code there.
- Run: Click the Run button.
- Test: Flip the rocker to "I", wait a few seconds, then flip it back to "O".
- Watch both consoles: The MCU Monitor writes one line per flip. The Python console writes one line every second.
App Lab Console Output
The MCU only speaks when something happens. Python asks every second and gets the same answer again and again, until you flip the rocker.
Telegram
Now picture the rocker as the main switch on the control panel of a machine: a 3D printer, a dust collector, a fan in the tutorial. You are at work or on the bus, and you start to wonder: did I leave it on? The bot answers in two ways:
- When you ask: send /state and the bot replies ON or OFF, with the time of the last flip
- By itself: every flip sends an alert, such as "Machine switched ON at 14:32". When the switch goes OFF, the alert also says how long the machine was ON
There is no limit or threshold to set. The flip itself is the event.
| Command | What it does |
|---|---|
| /state | ON or OFF right now, and the time of the last flip |
| /start | send this chat an alert on every flip |
| /stop | stop the alerts for this chat (/state still works) |
The first time you open a bot, Telegram shows a START button. Tapping it sends /start, so you get the alerts right away and you never need your chat ID. Want the real name of your machine in the messages? Change MACHINE_NAME at the top of the script, for example to "3D printer".
※ NOTE THAT:
In this project, the module only stands in for the machine's switch. It gives a logic signal to the UNO Q. The power of the machine must never go through the module.
MCU side: Nothing new. The Bridge sketch already gives the bot all it needs.
Python Code (Telegram)
Detailed Instructions
- Get a token: Ask @BotFather for a new bot and paste its token into TELEGRAM_BOT_TOKEN. The steps are in How to Create a Telegram Bot.
- Replace the Python file: In the RockerSwitchBridge App, swap the Python code for the bot script. The sketch stays as it is.
- Run: Click the Run button.
- Subscribe: Open your bot in Telegram, tap START (or send /start), then send /state.
- Flip it: Press the "I" side of the rocker. A moment later, the ON alert pops up on your phone.
- Restarted the App? The chat list and the last flip time live only in memory, so they are gone. Send /start once more.
App Lab Console Output
ArduinoBot
OpenClaw
You can adapt the OpenClaw to this tutorial by refering the instruction on Arduino Uno Q - OpenClaw Tutorial
Project Ideas
A switch that stays where you put it is a good way to tell a computer about a machine or a mode:
- Machine Hour Log: Python writes every ON and OFF with the time into a CSV file, so you can see how many hours a machine ran this week.
- Service Reminder: Add up the ON time on the Linux side. After 50 hours of use, the bot reminds you to clean or oil the machine.
- Lab Door Sign: Mount the module next to the door. ON means "experiment running, please wait", and the team chat gets the news.
- Program Switch Panel: Put a row of rocker modules on a small panel. Each one starts or stops a different program on Linux, like a camera stream or a small web server.
- Night Mode: With the rocker on "O", a project keeps its buzzer and its Telegram alerts quiet. Flip it to "I" in the morning and everything is back.
Challenge Yourself
Ready for more? Pick one:
- Easy: Change the first sketch so it prints a line only when the state is different from the last line, not every half second.
- Medium: In the Bridge sketch, count how many times the rocker went to ON and share the number with Python as get_on_count. Print it in the Python console.
- Advanced: Add a /today command to the bot. It answers how long the machine has been ON since midnight.