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:

Arduino UNO Q rocker switch module - read ON/OFF and get a Telegram alert on every flip

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×ON/OFF Rocker Switch Module
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
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.

Rocker switch module pinout with the SIG, VCC and GND labels and the I/O marks
image source: diyables.io
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.

The wiring diagram between Arduino UNO Q rocker switch module

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.

The wiring diagram between Arduino UNO Q rocker switch module Screw Shield

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:

  1. 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:
pinMode(ROCKER_SWITCH_PIN, INPUT);
  1. Read the state with digitalRead(). HIGH means the rocker is on "I", LOW means it is on "O":
int sig = digitalRead(ROCKER_SWITCH_PIN); // 1 = ON, 0 = OFF
  1. 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:
if (level != last_level) { // flip or bounce: start timing again last_level = level; level_changed_ms = millis(); } if (level != switch_state && millis() - level_changed_ms >= 50) { switch_state = level; // the rocker really moved }
  1. To share the state with Python on Linux, put it in a function and register it with Bridge.provide():
int get_switch_state() { return switch_state == HIGH ? 1 : 0; } Bridge.provide("get_switch_state", get_switch_state); // in setup()

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.

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rocker-switch-module */ // Arduino UNO Q - Rocker Switch Module: print the switch state, ON or OFF // Wiring: VCC -> 3.3V, SIG -> D7, GND -> GND // A pull-down resistor sits on the module, so SIG is never floating: // rocker on "I" -> SIG HIGH -> ON, rocker on "O" -> SIG LOW -> OFF. #define ROCKER_SWITCH_PIN 7 // the Arduino UNO Q pin wired to SIG void setup() { Serial.begin(115200); delay(1500); // give the console a moment to connect // Plain INPUT. Do not use INPUT_PULLUP: the module already pulls SIG down. pinMode(ROCKER_SWITCH_PIN, INPUT); Serial.println("Arduino UNO Q rocker switch module check"); } void loop() { int sig = digitalRead(ROCKER_SWITCH_PIN); // 1 = HIGH, 0 = LOW Serial.print("SIG = "); Serial.print(sig); if (sig == HIGH) Serial.println(" -> ON (I)"); else Serial.println(" -> OFF (O)"); // Two lines per second. The switch stays where you put it, // so a slow read like this does not need a debounce. delay(500); }

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.
Create New App in Arduino App Lab on Arduino UNO Q
  • Enter RockerSwitchModule as the name and click Create.
Arduino App Lab App folders and files on Arduino UNO Q
  • 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.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Flip it: Press the "I" side, count to two, then press the "O" side.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-12-04 15:06:39] Arduino UNO Q rocker switch module check [2026-12-04 15:06:39] SIG = 0 -> OFF (O) [2026-12-04 15:06:40] SIG = 0 -> OFF (O) [2026-12-04 15:06:40] SIG = 1 -> ON (I) [2026-12-04 15:06:41] SIG = 1 -> ON (I) [2026-12-04 15:06:41] SIG = 1 -> ON (I) [2026-12-04 15:06:42] SIG = 1 -> ON (I) [2026-12-04 15:06:42] SIG = 0 -> OFF (O) [2026-12-04 15:06:43] SIG = 0 -> OFF (O)

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)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rocker-switch-module */ // Arduino UNO Q - Rocker Switch Module, state shared with Linux via Bridge // Wiring: VCC -> 3.3V, SIG -> D7, GND -> GND // The MCU reads SIG and filters out the contact bounce with millis(). // Python on Linux only asks for the result. It never reads the pin itself. #include "Arduino_RouterBridge.h" #define ROCKER_SWITCH_PIN 7 #define SETTLE_MS 50 // a new level counts only after it stayed the same this long int switch_state; // the accepted level: HIGH = ON, LOW = OFF int last_level; // the raw level seen in the last loop unsigned long level_changed_ms = 0; // when the raw level last changed // Read-only value for Python: 1 = ON, 0 = OFF int get_switch_state() { return switch_state == HIGH ? 1 : 0; } void setup() { Bridge.begin(); Monitor.begin(); pinMode(ROCKER_SWITCH_PIN, INPUT); // the pull-down is on the module switch_state = digitalRead(ROCKER_SWITCH_PIN); last_level = switch_state; // Python only reads this value, so plain provide() is enough Bridge.provide("get_switch_state", get_switch_state); Monitor.println(String("Rocker switch Bridge ready, the switch is ") + (switch_state == HIGH ? "ON" : "OFF")); } void loop() { int level = digitalRead(ROCKER_SWITCH_PIN); if (level != last_level) { // a flip or a bounce: start timing again last_level = level; level_changed_ms = millis(); } // the new level stayed for SETTLE_MS -> the rocker really moved if (level != switch_state && millis() - level_changed_ms >= SETTLE_MS) { switch_state = level; Monitor.println(switch_state == HIGH ? "Rocker flipped to I (ON)" : "Rocker flipped to O (OFF)"); } }

Python Code (Bridge)

""" This Arduino UNO Q script was developed by newbiely.com This Arduino UNO Q script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rocker-switch-module """ from arduino.app_utils import * import time # Linux side: ask the MCU for the rocker switch state once per second. # Each line shows the raw value from Bridge (1 or 0) and its meaning. # When the value is not the same as last time, a CHANGED note is added. last_state = None # 1 = ON, 0 = OFF, None = nothing read yet def loop(): global last_state state = int(Bridge.call("get_switch_state")) # 1 or 0 name = "ON" if state == 1 else "OFF" line = f"get_switch_state -> {state} ({name})" if last_state is not None and state != last_state: line += f" <- CHANGED, the switch is now {name}" print(line) last_state = state time.sleep(1) App.run(user_loop=loop)

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.
Add sketch library in Arduino App Lab on Arduino UNO Q
  • Search for Arduino_RouterBridge created by Arduino and click the Install button.
My Apps / DIYables Apps
Run
Bricks
No bricks added...
Sketch Libraries
No sketch libra...
Files
python
sketch
.gitignore
README.md
app.yaml
sketch.ino
Add sketch library
Arduino_RouterBridge Arduino

This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

0.4.1
Install
More Info
  • 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

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-12-04 15:21:07] Rocker switch Bridge ready, the switch is OFF [2026-12-04 15:21:12] Rocker flipped to I (ON) [2026-12-04 15:21:17] Rocker flipped to O (OFF)
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-12-04 15:21:08] get_switch_state -> 0 (OFF) [2026-12-04 15:21:09] get_switch_state -> 0 (OFF) [2026-12-04 15:21:10] get_switch_state -> 0 (OFF) [2026-12-04 15:21:11] get_switch_state -> 0 (OFF) [2026-12-04 15:21:12] get_switch_state -> 1 (ON) <- CHANGED, the switch is now ON [2026-12-04 15:21:13] get_switch_state -> 1 (ON) [2026-12-04 15:21:14] get_switch_state -> 1 (ON) [2026-12-04 15:21:15] get_switch_state -> 1 (ON) [2026-12-04 15:21:16] get_switch_state -> 1 (ON) [2026-12-04 15:21:17] get_switch_state -> 0 (OFF) <- CHANGED, the switch is now OFF [2026-12-04 15:21:18] get_switch_state -> 0 (OFF)

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)

""" This Arduino UNO Q script was developed by newbiely.com This Arduino UNO Q script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rocker-switch-module """ from arduino.app_utils import * import requests import time # "Is the machine on?" bot: the rocker switch module is the power switch of a machine. # /state answers ON or OFF. Each flip of the switch sends an alert by itself, # for example "Machine switched ON at 14:32". # Keep the MCU sketch from the Bridge section. TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" API_URL = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}" MACHINE_NAME = "Machine" # the word used in the messages, e.g. "3D printer" or "Compressor" last_update_id = 0 last_state = None # 1 = ON, 0 = OFF, None = nothing read yet flipped_at = None # clock time ("14:32") of the last flip the bot saw on_since = None # time.monotonic() of the last flip to ON, to show the run time watchers = set() # chats that sent /start and get the flip alerts HELP_TEXT = ( f"Arduino UNO Q - {MACHINE_NAME} watcher\n" "/state - is it ON or OFF right now?\n" "/start - send me an alert on every flip\n" "/stop - no more alerts" ) def get_updates(): try: resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": 1}, timeout=5) data = resp.json() if data.get("ok"): return data["result"] except Exception as e: print(f"Error getting updates: {e}") return [] def send_message(chat_id, text): try: requests.post(f"{API_URL}/sendMessage", data={"chat_id": chat_id, "text": text}, timeout=10) except Exception as e: print(f"Error sending message: {e}") def run_time(seconds): minutes = int(seconds // 60) hours, minutes = divmod(minutes, 60) if hours: return f"{hours} h {minutes} min" return f"{minutes} min" def watch_switch(): global last_state, flipped_at, on_since state = int(Bridge.call("get_switch_state")) # 1 = ON, 0 = OFF if last_state is None: last_state = state # first reading after the start: nothing to report return if state == last_state: return # no flip last_state = state flipped_at = time.strftime("%H:%M") if state == 1: on_since = time.monotonic() alert = f"{MACHINE_NAME} switched ON at {flipped_at}" else: alert = f"{MACHINE_NAME} switched OFF at {flipped_at}" if on_since is not None: alert += f" (it was ON for {run_time(time.monotonic() - on_since)})" on_since = None print(alert) for chat_id in watchers: send_message(chat_id, alert) def handle(chat_id, text): if text == "/start": watchers.add(chat_id) return "Flip alerts are ON for this chat.\n\n" + HELP_TEXT if text == "/stop": watchers.discard(chat_id) return "Flip alerts are OFF for this chat. /state still works." if text == "/state": name = "ON" if last_state == 1 else "OFF" if flipped_at is None: return f"{MACHINE_NAME} is {name}. No flip since the bot started." return f"{MACHINE_NAME} is {name} (last flip at {flipped_at})" return HELP_TEXT def loop(): global last_update_id # 1. Did the switch flip since the last round? If yes, alert the watchers. watch_switch() # 2. Answer commands (getUpdates waits up to 1 second, which also paces the loop) for update in get_updates(): last_update_id = update["update_id"] if "message" not in update: continue chat_id = update["message"]["chat"]["id"] text = update["message"].get("text", "").strip().lower() print(f"Received: {text}") send_message(chat_id, handle(chat_id, text)) App.run(user_loop=loop)

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

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-12-04 14:20:03] Received: /start [2026-12-04 14:20:11] Received: /state [2026-12-04 14:32:26] Machine switched ON at 14:32 [2026-12-04 16:05:48] Received: /state [2026-12-04 16:47:09] Machine switched OFF at 16:47 (it was ON for 2 h 14 min)
Telegram
Telegram 12:45
Welcome to Telegram!
ArduinoBot 10:19
Chatting with Arduino...
telegram-botfather
BotFather Yesterday
Your bot has been created.

ArduinoBot

bot
Today
/start
10:15 AM ✓✓
Flip alerts are ON for this chat.
10:16 AM
/state
10:17 AM ✓✓
Machine is OFF. No flip since the bot started.
10:18 AM
Machine switched ON at 14:32
10:19 AM
/state
10:20 AM ✓✓
Machine is ON (last flip at 14:32)
10:21 AM
Machine switched OFF at 16:47 (it was ON for 2 h 14 min)
10:22 AM

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.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!