Arduino UNO Q - Touch Sensor

A touch sensor works like a digital button — it outputs HIGH when touched and LOW when not touched. On Arduino UNO Q, you can monitor touches locally on the MCU, or use Bridge to detect and act on touch events from the Linux side via Telegram.

In this tutorial, you will learn:

Arduino UNO Q Touch Sensor

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×Touch Sensor
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 Touch Sensor

Pinout

The touch sensor has three pins:

  • GND: Connect to GND (0V)
  • VCC: Connect to 3.3V or 5V
  • SIGNAL: Digital output — outputs LOW when not touched, HIGH when touched. Connect to a digital pin on the Arduino UNO Q MCU.
Touch Sensor Pinout

How It Works

  • When the sensor is not touched, the SIGNAL pin is LOW
  • When the sensor is touched, the SIGNAL pin is HIGH

The touch sensor behaves exactly like a momentary push button — it can be read with digitalRead() and requires no library.

Wiring Diagram

The wiring diagram between Arduino UNO Q Touch Sensor

This image is created using Fritzing. Click to enlarge image

Touch Sensor Pin Arduino UNO Q MCU
GND GND
VCC 3.3V
SIGNAL D7

How To Program For Touch Sensor

  • Set up the Arduino UNO Q MCU pin as a digital input:
pinMode(SENSOR_PIN, INPUT);
  • Read the sensor state:
int state = digitalRead(SENSOR_PIN);
  • Check and respond:
if (state == HIGH) Serial.println("Touched"); else Serial.println("Not touched");

Arduino UNO Q Code

The Arduino UNO Q has two processors working together:

  • The STM32 MCU reads the touch sensor directly via a digital pin — all sensing runs on the MCU
  • The Qualcomm MPU runs Debian Linux and handles Wi-Fi, Python, and cloud connectivity
  • In this section, only the MCU is programmed — the Linux side stays idle. A later section shows how both processors work together via Bridge.

The MCU reads the touch sensor every 500ms and prints the state to the Serial Monitor.

/* * 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-touch-sensor */ // COPYRIGHT newbiely.com // AUTHOR: newbiely // This code is made available for public use without restriction. // For complete instructions, tutorials, and further information, visit: // https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-touch-sensor #define SENSOR_PIN 7 void setup() { Serial.begin(9600); pinMode(SENSOR_PIN, INPUT); Serial.println("Arduino UNO Q Touch Sensor ready"); } void loop() { int state = digitalRead(SENSOR_PIN); if (state == HIGH) Serial.println("Touched"); else Serial.println("Not touched"); delay(500); }

Detailed Instructions

First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial before proceeding.

  • Connect: Wire the touch sensor to the Arduino UNO Q MCU as shown in the wiring diagram.
  • Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
  • Create a new App: Click the Create New App button.
Create New App in Arduino App Lab on Arduino UNO Q
  • Give the App a name, for example: TouchSensor
  • Click Create to confirm.
Arduino App Lab App folders and files on Arduino UNO Q
  • Paste the sketch: Copy the MCU code above and paste it into sketch/sketch.ino. Keep other files as default.
  • No library required — the touch sensor uses only the built-in digitalRead() function.
  • Upload: Click the Run button in Arduino App Lab.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Place your finger on the sensor and watch the Serial Monitor.

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-04-29 09:00:01] Arduino UNO Q Touch Sensor ready [2026-04-29 09:00:02] Not touched [2026-04-29 09:00:02] Not touched [2026-04-29 09:00:03] Touched [2026-04-29 09:00:03] Touched [2026-04-29 09:00:04] Not touched

Bridge: Linux + MCU

This section shows how to program both processors of the Arduino UNO Q so the Linux side can detect touch events via Bridge:

  • The touch sensor is connected to the MCU digital pin — the MCU monitors state changes in loop() and sets an event flag when touched
  • The MPU cannot read the digital pin directly — it calls Bridge functions to query the current state or consume the touch event
  • The MPU has Wi-Fi — running full Debian Linux, it can react to touch events and send Telegram notifications
  • Arduino_RouterBridge enables RPC communication between the two processors
  • ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) are RESERVED by the router — never open them in user code

In short: MCU detects touch events in loop() → MPU polls via Bridge → MPU triggers actions over Wi-Fi.

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-touch-sensor */ // COPYRIGHT newbiely.com // AUTHOR: newbiely // This code is made available for public use without restriction. // For complete instructions, tutorials, and further information, visit: // https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-touch-sensor #include "Arduino_RouterBridge.h" #define SENSOR_PIN 7 int last_state = LOW; bool touch_event = false; String get_state(String arg) { return (last_state == HIGH) ? "touched" : "not_touched"; } String get_event(String arg) { if (touch_event) { touch_event = false; return "touched"; } return "none"; } void setup() { Bridge.begin(); Monitor.begin(); pinMode(SENSOR_PIN, INPUT); Bridge.provide("get_state", get_state); Bridge.provide("get_event", get_event); Monitor.println("Arduino UNO Q Touch Sensor Bridge ready"); } void loop() { int state = digitalRead(SENSOR_PIN); if (state != last_state) { last_state = state; if (state == HIGH) { touch_event = true; Monitor.println("Touch detected!"); } else { Monitor.println("Touch released."); } } }

Python 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-touch-sensor */ # COPYRIGHT newbiely.com # AUTHOR: newbiely # This code is made available for public use without restriction. # For complete instructions, tutorials, and further information, visit: # https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-touch-sensor from arduino.app_utils import * import time def loop(): state = Bridge.call("get_state") print(f"Touch state: {state}") time.sleep(0.5) App.run(user_loop=loop)

Detailed Instructions

  • Connect: Wire the touch sensor to the Arduino UNO Q as shown in the wiring diagram.
  • Open Arduino App Lab: Launch Arduino App Lab and wait for the board to be detected.
  • Create a new App: Click Create New App, name it TouchSensorBridge, then click Create.
  • Paste the MCU sketch: Copy the MCU Bridge code above and paste it into sketch/sketch.ino.
  • Paste the Python code: Copy the Python Bridge code above and paste it into the Python file in the App.
  • 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
  • Upload: Click the Run button in Arduino App Lab.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Touch the sensor and watch the Python console report the state change.

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-04-29 09:00:01] Arduino UNO Q Touch Sensor Bridge ready [2026-04-29 09:00:03] Touch detected! [2026-04-29 09:00:04] Touch released.
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-04-29 09:00:02] Touch state: not_touched [2026-04-29 09:00:02] Touch state: not_touched [2026-04-29 09:00:03] Touch state: touched [2026-04-29 09:00:04] Touch state: not_touched

Telegram

Get instant Telegram notifications when the touch sensor is activated.

MCU sketch: Keep the same MCU sketch from the previous Bridge section.

Python Code (Telegram)

/* * 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-touch-sensor */ # COPYRIGHT newbiely.com # AUTHOR: newbiely # This code is made available for public use without restriction. # For complete instructions, tutorials, and further information, visit: # https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-touch-sensor from arduino.app_utils import * import requests import time TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" CHAT_ID = "YOUR_CHAT_ID" last_update_id = 0 last_notified_state = "not_touched" def get_updates(): global last_update_id url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates" params = {"offset": last_update_id + 1, "timeout": 5} try: response = requests.get(url, params=params, timeout=10) data = response.json() if data["ok"]: return data["result"] except Exception as e: print(f"Error getting updates: {e}") return [] def send_message(chat_id, text): url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage" payload = {"chat_id": chat_id, "text": text} try: requests.post(url, data=payload, timeout=10) except Exception as e: print(f"Error sending message: {e}") def loop(): global last_notified_state # Auto-notify on touch event event = Bridge.call("get_event") if event == "touched" and last_notified_state != "touched": last_notified_state = "touched" msg = "👆 Touch sensor touched!" print(msg) send_message(CHAT_ID, msg) elif event == "none": state = Bridge.call("get_state") if state == "not_touched": last_notified_state = "not_touched" # Handle Telegram commands updates = get_updates() for update in updates: last_update_id = update["update_id"] if "message" not in update: continue message = update["message"] chat_id = message["chat"]["id"] text = message.get("text", "").strip() print(f"Received: {text}") if text == "/start": send_message(chat_id, "Arduino UNO Q Touch Sensor Bot\n" "/state - Read current touch sensor state\n" "/event - Check if a touch event occurred") elif text == "/state": result = Bridge.call("get_state") send_message(chat_id, f"Touch state: {result}") elif text == "/event": result = Bridge.call("get_event") send_message(chat_id, f"Touch event: {result}") else: send_message(chat_id, "Unknown command. Send /start for help.") time.sleep(0.5) App.run(user_loop=loop)

Detailed Instructions

  • Replace YOUR_TELEGRAM_BOT_TOKEN with your actual bot token from BotFather.
  • Replace YOUR_CHAT_ID with your Telegram chat ID.
  • Paste this Python code into your App's Python file (keep the same MCU sketch).
  • Click the Run button. Touch the sensor and check Telegram for the notification.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-04-29 09:10:00] Waiting for Telegram messages... [2026-04-29 09:10:05] 👆 Touch sensor touched! [2026-04-29 09:10:22] Received: /state
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
/state
10:15 AM ✓✓
Touch state: not_touched
10:16 AM
/event
10:17 AM ✓✓
Touch event: none
10:18 AM
👆 Touch sensor touched!
10:19 AM

OpenClaw

...OPENCLAW

OpenClaw support for Arduino UNO Q Touch Sensor is coming soon.

...OPENCLAW

Project Ideas

You can build many useful projects with the touch sensor and Arduino UNO Q:

  • Touchable Smart Lamp: Touch the sensor to toggle an LED or relay via Bridge — the MPU handles the toggle logic and logs each touch event with a timestamp
  • Door Chime: Place the touch sensor near a doorframe — when touched, the MPU plays a sound file or sends a Telegram notification to alert you of a visitor
  • Secret Knock Counter: Count consecutive touches within 3 seconds via Python-side logic — if the count matches a preset pattern, Bridge triggers an unlock relay
  • Presence-Activated Display: Touch the sensor to wake up an OLED display — the MCU turns on the display via Bridge on the first touch and turns it off after 10 seconds of inactivity
  • Lab Safety Confirmation: Require a touch confirmation before a Bridge command activates a high-power relay — the Python side checks get_event() before sending the control signal

Challenge Yourself

Ready to go further with the touch sensor on Arduino UNO Q? Try these challenges:

  • Easy: Count the number of touches since startup and expose the count via a get_count(String) Bridge function — the Python side prints the count each time it increases.
  • Medium: Implement a double-tap detector: the MCU records touch timestamps and sets a double_tap flag when two touches occur within 500ms — the Python side retrieves this via get_event() and sends a Telegram alert.
  • Advanced: Build a touch-based Morse code input: the MCU distinguishes short touches (dot) and long touches (>500ms, dash) — the Python side decodes the sequence and sends the decoded letter to Telegram.

Learn More

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