Arduino UNO Q - Slide Switch

A slide switch is the small switch you push left or right on a toy, a flashlight or a power bank. You move the handle once, and it stays there. That makes it a simple way to give a project a setting: mode A or mode B, armed or disarmed, sound on or sound off. On the Arduino UNO Q, the STM32 MCU reads where the handle is, and the Linux side can use that position in Python or send it to your phone.

What you will learn here:

Arduino UNO Q slide switch SS12D10 - read the ON/OFF position and send it to Telegram

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×Mini Slide Switch SS12D10
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 Slide Switch

The DIYables Mini Slide Switch SS12D10 is a tiny switch with a sliding handle on top and three legs in a row underneath. Push the handle to one side and it stays there until you push it back. A push button works the other way: it springs back the moment you let go. In switch terms, the SS12D10 is SPDT (single pole, double throw), also written 1P2T.

Item Value
Contact type SPDT (1P2T), 2 positions
Pins 3, with 4.7 mm pitch
Terminal length 6.9 mm
Handle length 5 mm
Body size about 12.8 x 6.7 x 18.2 mm
Mounting Vertical through-hole
Contacts Silver-plated brass
Contact rating AC 125V 2A
Life More than 100,000 switching cycles
Operating temperature -25°C to 80°C

The 125V 2A rating is what the contacts can carry. In this tutorial, only a tiny signal current goes through the switch.

SS12D10 slide switch pinout - COM in the middle, pin 1 and pin 3 on the sides, two handle positions

No names are printed on the legs. The middle one is always COM:

  • Pin 1: an outer leg. In this tutorial it is wired to GND
  • Pin 2 (COM): the middle leg, the common pin. It goes to the input pin of the board
  • Pin 3: the other outer leg. On the Arduino UNO Q it is wired to 3.3V

How it works: inside, a small metal bridge always touches COM. It also touches the outer leg on the side where the handle is:

Handle position Connected Open
Toward pin 1 Pin 1 and COM Pin 3
Toward pin 3 COM and pin 3 Pin 1

So COM always copies one of the outer legs. With pin 1 on GND and pin 3 on 3.3V, the input pin sees LOW or HIGH and never floats. This is why the main wiring below needs no pull-up or pull-down resistor.

Which switch should I pick? A slide switch is small enough for a tiny box or the side of a case. For a big panel switch that you flip with a finger, see Arduino UNO Q - Switch (ON/OFF Toggle). To read several small switches at once, see Arduino UNO Q - DIP Switch. For something that springs back, see Arduino UNO Q - Button Module.

Wiring Diagram

Each leg gets one jumper wire. COM goes to pin 7, and the two outer legs go to GND and 3.3V, the two levels the MCU understands.

The wiring diagram between Arduino UNO Q slide switch

This image is created using Fritzing. Click to enlarge image

Slide Switch Pin Arduino UNO Q Pin
Pin 1 GND
Pin 2 (COM) Pin 7
Pin 3 3.3V

Jumper wires are good for a quick test, but not for a final build. The Arduino UNO Q works with both the Proto Screw Terminal Block Shield and the Screw Shield V2. Both turn the header pins into screw terminals. This is how it looks with the Screw Shield V2:

The wiring diagram between Arduino UNO Q slide switch Screw Shield

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

⚠️ Pin 3 goes to 3.3V, not to 5V or VIN. COM passes the voltage of pin 3 straight to pin 7. The STM32 MCU of the UNO Q works with 3.3V logic, so 3.3V is its normal HIGH level. Most of its digital pins can stand 5V, but A0 and A1 cannot, so 3.3V is the safe habit if you ever move the wire.

⚠️ Keep pin 7 as an input. Never set it to OUTPUT. The switch ties the pin straight to 3.3V or to GND, so an output pin could be shorted.

Pin 7 is only an example. Any digital pin works. If you pick another one, change SLIDE_SWITCH_PIN in every sketch on this page.

How To Program For Slide Switch

The switch drives the pin by itself, so the MCU code stays short:

  1. Set the COM pin as a plain input with pinMode(). No pull-up is needed, because COM is always joined to GND or 3.3V:
pinMode(SLIDE_SWITCH_PIN, INPUT);
  1. Read the level with digitalRead(). With the 3-wire wiring, HIGH means the handle is toward pin 3:
int level = digitalRead(SLIDE_SWITCH_PIN); // HIGH = ON, LOW = OFF
  1. Keep the last confirmed position. When a new reading is different, wait 50 ms and read again. The contacts flicker for a moment while they slide, so only a change that is still there counts:
if (reading != switch_state) { delay(50); reading = digitalRead(SLIDE_SWITCH_PIN); if (reading != switch_state) switch_state = reading; // the handle really moved }
  1. For the 2-wire wiring, switch on the internal pull-up and swap the meaning of the two levels:
pinMode(SLIDE_SWITCH_PIN, INPUT_PULLUP); // LOW = ON, HIGH = OFF

Arduino UNO Q Code

There are two brains on the UNO Q:

  • The STM32 MCU owns the header pins, so it is the one that reads pin 7
  • The Qualcomm MPU runs Debian Linux with Python and Wi-Fi
  • The two sketches below run on the MCU only. Linux joins in at the Bridge section

Read the Handle Position

At power-on, the sketch prints where the handle is. After that, it stays quiet and prints one line only when the handle moves to the other side.

/* * 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-slide-switch */ // Arduino UNO Q - Slide Switch SS12D10: print the ON/OFF position of the handle // Wiring (3 wires): pin 1 -> GND, pin 2 (COM) -> D7, pin 3 -> 3.3V // COM always touches pin 1 (GND) or pin 3 (3.3V), so D7 never floats and no resistor is needed. // Handle toward pin 3 -> HIGH -> ON. Handle toward pin 1 -> LOW -> OFF. #define SLIDE_SWITCH_PIN 7 // The Arduino UNO Q pin connected to COM (the middle pin) #define DEBOUNCE_DELAY 50 // milliseconds to let the contacts settle after the handle moves int switch_state; // the last confirmed level (HIGH or LOW) void print_position(int level) { if (level == HIGH) Serial.println("The slide switch is ON"); else Serial.println("The slide switch is OFF"); } void setup() { Serial.begin(115200); delay(1500); // Plain INPUT: the switch itself drives the pin to 3.3V or to GND. // Never set this pin to OUTPUT, the switch ties it straight to 3.3V or GND. pinMode(SLIDE_SWITCH_PIN, INPUT); Serial.println("Arduino UNO Q slide switch test started"); switch_state = digitalRead(SLIDE_SWITCH_PIN); // the position at power-on print_position(switch_state); } void loop() { int reading = digitalRead(SLIDE_SWITCH_PIN); if (reading != switch_state) { delay(DEBOUNCE_DELAY); // the contacts bounce for a moment when the handle moves reading = digitalRead(SLIDE_SWITCH_PIN); // read again if (reading != switch_state) { // still different, so the handle really moved switch_state = reading; print_position(switch_state); } } }

Detailed Instructions

Never used the Arduino UNO Q before? Set up Arduino App Lab first with Getting Started with Arduino UNO Q.

  • Wiring: Pin 1 to GND, COM to pin 7, pin 3 to 3.3V. Look at the pin 3 wire one more time. It must be on 3.3V.
  • USB: Connect the Arduino UNO Q to your computer with the USB-C cable.
  • App Lab: Open Arduino App Lab and wait until it finds the board.
  • New App: Click Create New App.
Create New App in Arduino App Lab on Arduino UNO Q
  • Type the name SlideSwitch and click Create.
Arduino App Lab App folders and files on Arduino UNO Q
  • Sketch: Open sketch/sketch.ino and replace everything in it with the code above. The other files stay as they are. No library is needed.
  • Run: Click the Run button.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Slide: Move the handle to the other side, wait a moment, then move it back. Do this a few times and watch the console.

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-11-17 08:31:05] Arduino UNO Q slide switch test started [2026-11-17 08:31:05] The slide switch is OFF [2026-11-17 08:31:09] The slide switch is ON [2026-11-17 08:31:14] The slide switch is OFF [2026-11-17 08:31:16] The slide switch is ON [2026-11-17 08:31:22] The slide switch is OFF

One move gives one line, never two. If you see ON and OFF the wrong way round, the outer wires are swapped: you can swap the GND and 3.3V wires on the switch, or swap the two messages in the code.

Slide Switch with Only Two Wires (INPUT_PULLUP)

Short on wires, or is the 3.3V pin already in use? You can leave pin 3 empty. The MCU has a pull-up resistor inside, and INPUT_PULLUP turns it on, so pin 7 stays HIGH when COM touches nothing. Just remove the pin 3 wire.

The wiring diagram between Arduino UNO Q slide switch INPUT_PULLUP

This image is created using Fritzing. Click to enlarge image

Slide Switch Pin Arduino UNO Q Pin
Pin 1 GND
Pin 2 (COM) Pin 7
Pin 3 Not connected

Be careful, the logic is now the other way round:

  • Handle toward pin 1: COM joins GND, pin 7 reads LOW, and the sketch prints ON
  • Handle toward pin 3: COM is open, the pull-up holds pin 7 HIGH, and the sketch prints 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-slide-switch */ // Arduino UNO Q - Slide Switch SS12D10 with only 2 wires (INPUT_PULLUP) // Wiring (2 wires): pin 1 -> GND, pin 2 (COM) -> D7, pin 3 -> not connected // Handle toward pin 1 -> COM joins GND -> LOW -> ON. // Handle toward pin 3 -> COM joins nothing, the internal pull-up keeps D7 HIGH -> OFF. // The logic is flipped compared with the 3-wire version: here LOW means ON. #define SLIDE_SWITCH_PIN 7 // The Arduino UNO Q pin connected to COM (the middle pin) #define DEBOUNCE_DELAY 50 // milliseconds to let the contacts settle after the handle moves int switch_state; // the last confirmed level (HIGH or LOW) void print_position(int level) { if (level == LOW) // LOW = COM is joined to GND through pin 1 Serial.println("The slide switch is ON"); else // HIGH = COM is open, so the pull-up wins Serial.println("The slide switch is OFF"); } void setup() { Serial.begin(115200); delay(1500); // INPUT_PULLUP turns on the resistor inside the MCU that pulls D7 up to 3.3V. // Without it, D7 would float when the handle is toward the unused pin 3. pinMode(SLIDE_SWITCH_PIN, INPUT_PULLUP); Serial.println("Arduino UNO Q slide switch (INPUT_PULLUP) test started"); switch_state = digitalRead(SLIDE_SWITCH_PIN); // the position at power-on print_position(switch_state); } void loop() { int reading = digitalRead(SLIDE_SWITCH_PIN); if (reading != switch_state) { delay(DEBOUNCE_DELAY); // wait until the bouncing is over reading = digitalRead(SLIDE_SWITCH_PIN); // read again if (reading != switch_state) { // the change is real switch_state = reading; print_position(switch_state); } } }

Detailed Instructions

  • Take away the wire on pin 3. The other two wires stay where they are.
  • Make a new App called SlideSwitchInputPullup, or reuse the last one, and put this code into sketch/sketch.ino.
  • Click Run and move the handle a few times.

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-11-17 08:47:22] Arduino UNO Q slide switch (INPUT_PULLUP) test started [2026-11-17 08:47:22] The slide switch is ON [2026-11-17 08:47:27] The slide switch is OFF [2026-11-17 08:47:31] The slide switch is ON [2026-11-17 08:47:40] The slide switch is OFF

Bridge: Linux + MCU

A slide switch holds a setting, so Linux mostly wants to know two things: where the handle is now, and when it last moved. Python cannot read pin 7 by itself, so it asks the MCU:

  • The MCU watches pin 7. It debounces with millis() instead of delay(), so loop() never stops and every Bridge call gets a fast answer
  • It shares three read-only values with Bridge.provide():
    • get_switch_position — ON or OFF
    • get_seconds_in_state — how many seconds the handle has stayed in that position
    • get_flip_count — how many times the handle moved since power-on
  • Why a flip counter? Python checks only twice per second. If someone flicks the handle to OFF and back to ON between two checks, the position looks the same as before. The counter still goes up by 2, so Python knows that something happened
  • Python polls with Bridge.call(), prints a line on every move, and prints a short status line every 10 seconds
  • ⚠️ Leave /dev/ttyHS1 (Linux) and Serial1 (MCU) alone. The router reserves them, so your code must never open them

In short: you move the handle → the MCU confirms and counts the move → Python calls the MCU → Python prints the news.

The MCU sketch is made for the 3-wire wiring. With the 2-wire wiring, change INPUT to INPUT_PULLUP and ON_LEVEL to LOW at the top of the sketch.

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-slide-switch */ // Arduino UNO Q - Slide Switch SS12D10, shared with Linux via Bridge // Wiring (3 wires): pin 1 -> GND, pin 2 (COM) -> D7, pin 3 -> 3.3V // The MCU watches the switch and debounces it without delay(). // Python on Linux only reads the values below. It never touches the pin. #include "Arduino_RouterBridge.h" #define SLIDE_SWITCH_PIN 7 #define ON_LEVEL HIGH // 3 wires: HIGH = ON. For the 2-wire INPUT_PULLUP wiring, use LOW here #define DEBOUNCE_MS 50 // the level must stay the same this long before it counts int stable_level; // the confirmed (debounced) level int last_reading; // the raw level seen in the last loop unsigned long last_bounce_ms = 0; // when the raw level last changed unsigned long since_ms = 0; // when the switch reached its current position unsigned long flip_count = 0; // how many times the handle moved since power-on String position_name() { return stable_level == ON_LEVEL ? "ON" : "OFF"; } // Returns "ON" or "OFF" String get_switch_position(String arg) { return position_name(); } // Returns how many seconds the switch has stayed in its current position String get_seconds_in_state(String arg) { return String((millis() - since_ms) / 1000); } // Returns how many times the handle moved since power-on. // Python compares it with the last value, so even a quick move between two polls is seen. String get_flip_count(String arg) { return String(flip_count); } void setup() { Bridge.begin(); Monitor.begin(); pinMode(SLIDE_SWITCH_PIN, INPUT); // use INPUT_PULLUP for the 2-wire wiring stable_level = digitalRead(SLIDE_SWITCH_PIN); last_reading = stable_level; since_ms = millis(); // Read-only values, so plain provide() is enough Bridge.provide("get_switch_position", get_switch_position); Bridge.provide("get_seconds_in_state", get_seconds_in_state); Bridge.provide("get_flip_count", get_flip_count); Monitor.println("Arduino UNO Q Slide Switch Bridge ready, switch is " + position_name()); } void loop() { int reading = digitalRead(SLIDE_SWITCH_PIN); if (reading != last_reading) { // the level moved or bounced: start timing again last_reading = reading; last_bounce_ms = millis(); } // steady for DEBOUNCE_MS and different from the confirmed level -> a real move if (reading != stable_level && millis() - last_bounce_ms >= DEBOUNCE_MS) { stable_level = reading; since_ms = millis(); flip_count++; Monitor.println("Slide switch moved to " + position_name() + ", flip " + String(flip_count)); } }

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-slide-switch """ from arduino.app_utils import * import time # Linux side: ask the MCU about the slide switch twice per second. # A line is printed each time the handle moves, plus a short status line every 10 seconds. # The flip counter on the MCU shows moves that happen between two polls. STATUS_EVERY_S = 10 last_flips = None last_status_time = 0 def loop(): global last_flips, last_status_time position = str(Bridge.call("get_switch_position")) # "ON" or "OFF" flips = int(str(Bridge.call("get_flip_count"))) # moves since power-on if last_flips is None: print(f"Slide switch starts in the {position} position") elif flips != last_flips: line = f"Slide switch moved to {position}, flip #{flips}" if flips - last_flips > 1: line += f" ({flips - last_flips} flips since the last check)" print(line) last_flips = flips now = time.time() if now - last_status_time >= STATUS_EVERY_S: seconds = Bridge.call("get_seconds_in_state") print(f"Status: {position} for {seconds} s") last_status_time = now time.sleep(0.5) App.run(user_loop=loop)

Detailed Instructions

  • New App: In Arduino App Lab, click Create New App and call it SlideSwitchBridge.
  • MCU part: Put the MCU sketch into sketch/sketch.ino and add the Bridge 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
  • Linux part: Put the Python code into the Python file of the same App.
  • Run: Click the Run button.
  • Try it: Move the handle once and wait a few seconds. Then flick it to the other side and straight back, as fast as you can.
  • Compare the consoles: The MCU Monitor lists every move. The Python console shows what Linux found out from its calls.

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-11-17 09:02:10] Arduino UNO Q Slide Switch Bridge ready, switch is OFF [2026-11-17 09:02:18] Slide switch moved to ON, flip 1 [2026-11-17 09:02:33] Slide switch moved to OFF, flip 2 [2026-11-17 09:02:33] Slide switch moved to ON, flip 3
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-11-17 09:02:11] Slide switch starts in the OFF position [2026-11-17 09:02:11] Status: OFF for 1 s [2026-11-17 09:02:18] Slide switch moved to ON, flip #1 [2026-11-17 09:02:21] Status: ON for 3 s [2026-11-17 09:02:31] Status: ON for 13 s [2026-11-17 09:02:33] Slide switch moved to ON, flip #3 (2 flips since the last check) [2026-11-17 09:02:41] Status: ON for 8 s

Look at 09:02:33. Python never saw the short OFF, because it came and went between two checks. The flip counter jumped from 1 to 3, so Python still reported it. The time in state also started again from 0.

Telegram

Now the slide switch becomes the arm switch of a simple home alarm. Mount it next to the front door. Slide it to ON when you leave: the system is ARMED. Slide it to OFF when you come home: the system is DISARMED. The bot sends a message on every move, so you see at once if someone forgot to arm it or came home early.

Command What it does
/status ARMED or DISARMED, and for how long
/start send me a message each time the switch moves
/stop stop the automatic messages for this chat

Only chats that sent /start get the automatic messages. That way the script needs no chat ID. /status works in any chat. If the handle has not moved since power-on, the time in /status counts from power-on.

Do you want other words than ARMED and DISARMED? Change the MODE line at the top of the script, for example to "ON": "AWAY" and "OFF": "HOME".

MCU sketch: Keep the MCU sketch from the Bridge section. It needs no change.

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-slide-switch """ from arduino.app_utils import * import requests import time # Arm switch bot: the slide switch arms (ON) or disarms (OFF) a simple home alarm. # Each move of the handle sends a message to the chats that sent /start. # /status answers with the position and how long it has been there. # 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}" MODE = {"ON": "ARMED", "OFF": "DISARMED"} # what each position means in this project last_update_id = 0 last_flips = None subscribers = set() # chats that get a message on every move HELP_TEXT = ( "Arduino UNO Q Arm Switch Bot\n" "/status - is the system armed or disarmed?\n" "/start - get a message each time the switch moves\n" "/stop - no more messages" ) 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 nice_time(seconds): minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) if hours: return f"{hours} h {minutes} min" if minutes: return f"{minutes} min {seconds} s" return f"{seconds} s" def status_text(): position = str(Bridge.call("get_switch_position")) seconds = int(str(Bridge.call("get_seconds_in_state"))) mode = MODE.get(position, position) return f"The slide switch is {position}, so the system is {mode} (for {nice_time(seconds)})" def handle(chat_id, text): if text == "/start": subscribers.add(chat_id) return "You will get a message each time the switch moves.\n\n" + HELP_TEXT if text == "/stop": subscribers.discard(chat_id) return "No more switch messages for this chat." if text == "/status": return status_text() return HELP_TEXT def loop(): global last_update_id, last_flips # 1. Automatic message: did the handle move since the last check? flips = int(str(Bridge.call("get_flip_count"))) if last_flips is not None and flips != last_flips: position = str(Bridge.call("get_switch_position")) alert = f"System {MODE.get(position, position)} (switch {position}) at {time.strftime('%H:%M:%S')}" if flips - last_flips > 1: alert += f" - the handle moved {flips - last_flips} times" print(alert) for chat_id in subscribers: send_message(chat_id, alert) last_flips = flips # 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

  • Token: Create a bot with @BotFather and paste its token into TELEGRAM_BOT_TOKEN. Not sure how? Read How to Create a Telegram Bot.
  • Swap the Python file: Open the SlideSwitchBridge App and replace its Python code with this bot script. Leave the sketch alone.
  • Run: Click the Run button.
  • Say hello: In Telegram, open your bot and send /start, then /status.
  • Arm it: Slide the handle to ON. The message should reach your phone within a second or two.
  • Note: The bot keeps the /start list in memory only. After a restart of the App, send /start again.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-11-17 07:55:02] Received: /start [2026-11-17 07:55:20] Received: /status [2026-11-17 08:12:40] System ARMED (switch ON) at 08:12:40 [2026-11-17 17:48:05] System DISARMED (switch OFF) at 17:48:05 [2026-11-17 17:50:31] Received: /status
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 ✓✓
You will get a message each time the switch moves.
10:16 AM
/status
10:17 AM ✓✓
The slide switch is OFF, so the system is DISARMED (for 12 min 41 s)
10:18 AM
System ARMED (switch ON) at 08:12:40
10:19 AM
System DISARMED (switch OFF) at 17:48:05
10:20 AM
/status
10:21 AM ✓✓
The slide switch is OFF, so the system is DISARMED (for 2 min 26 s)
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 remembers its position is a natural "settings" input:

  • Data Logger On/Off: While the switch is ON, Python on Linux writes sensor readings to a CSV file. Slide it to OFF and the logging stops.
  • Quiet Mode: A buzzer or alarm project beeps only when the switch is ON. Slide it to OFF at night.
  • Unit Selector: One position shows the temperature in °C, the other in °F, on a display or in a Telegram reply.
  • Do Not Disturb Sign: A switch on your desk tells the family chat "busy" or "free" when you move it.
  • Test or Live: In the OFF position, a Python script only prints what it would do. In the ON position, it really sends messages or switches a relay.

Challenge Yourself

Try these on your own:

  • Easy: Change the messages in the first sketch so the console prints Mode A and Mode B instead of ON and OFF.
  • Medium: In the Bridge sketch, add up the total time the switch spent in the ON position, and share it with Python as get_total_on_seconds.
  • Advanced: Add a 30-second exit delay to the Telegram bot: after the switch moves to ON, wait 30 seconds before you send ARMED. If the switch goes back to OFF during that time, send nothing.

※ 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!