Arduino UNO Q - Potentiometer fade LED

This tutorial shows how to use a potentiometer to control the brightness of an LED with Arduino UNO Q. Turning the potentiometer knob changes the LED brightness in real time.

※ NOTE THAT:

Arduino UNO Q ADC difference: The STM32 MCU on Arduino UNO Q has a 12-bit ADC (values 0–4095), not 10-bit (0–1023). Map ADC values from 0–4095 to brightness 0–255 when using analogWrite().

Arduino UNO Q - Potentiometer controls LED brightness

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×Potentiometer
1×Alternatively, 10k Ohm Trimmer Potentiometer
1×Alternatively, Potentiometer Kit
1×Alternatively, Potentiometer Module with Knob
1×LED Kit
1×LED (red)
1×LED Module
1×220 ohm Resistor
1×Breadboard
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 .

Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.

Overview of the Potentiometer and LED

If you are new to the potentiometer or LED, check these tutorials first:

Wiring Diagram

The wiring diagram between Arduino UNO Q Potentiometer LED

This image is created using Fritzing. Click to enlarge image

How To Program

  • Read ADC value from pin A0 (12-bit on Arduino UNO Q, 0–4095):
int adc_value = analogRead(A0);
  • Map ADC value to PWM brightness (0–255):
int brightness = map(adc_value, 0, 4095, 0, 255);
  • Write brightness to the LED pin using PWM:
analogWrite(LED_PIN, brightness);

MCU Code — Potentiometer controls LED brightness

The Arduino UNO Q has two processors: the STM32 MCU (handles real-time hardware control) and the Qualcomm MPU (runs Debian Linux). In this section, only the STM32 MCU is programmed — the Linux side stays idle. A later section will show how both processors work together.

/* * 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-potentiometer-fade-led */ #define LED_PIN 3 // pin connected to LED #define POTENTIOMETER_PIN A0 // pin connected to potentiometer void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { // Read ADC value from potentiometer (12-bit: 0-4095 on Arduino UNO Q) int adc_value = analogRead(POTENTIOMETER_PIN); // Map ADC value to brightness (0-255 for PWM) int brightness = map(adc_value, 0, 4095, 0, 255); // Set LED brightness analogWrite(LED_PIN, brightness); delay(100); }

Detailed Instructions

  • First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial to get your development environment ready before proceeding.
  • Wire the components: Connect the potentiometer output to A0, GND to GND, VCC to 3.3V. Connect the LED (with 220 Ω resistor) to pin 3 according to the wiring diagram.
  • Connect: Plug the Arduino UNO Q into your computer with a USB-C cable.
  • 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: DIYables_PotLED
  • Click Create to confirm.
  • You will see a set of folders and files generated inside your new App.
Arduino App Lab App folders and files on Arduino UNO Q
  • Find the sketch/sketch.ino file — this is where you will paste the MCU sketch.
  • Paste the sketch: Copy the MCU code above and paste it into the sketch file. Keep other files as default.
    • 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 to compile and upload to the STM32.
    Click Run button in Arduino App Lab on Arduino UNO Q
    • Turn the potentiometer knob — the LED brightness should change smoothly in real time.

    Linux + MCU Bridge Programming

    The Arduino UNO Q has two processors that work together: the MPU (Qualcomm, runs Debian Linux) and the MCU (STM32, runs Zephyr OS with your Arduino sketch). They communicate using RPC via the Arduino_RouterBridge library — never via raw serial ports.

    • The potentiometer and LED are connected to the MCU (STM32) — the potentiometer output wires to analog pin A0 and the LED to a PWM-capable output pin. The MCU continuously reads ADC values and updates the LED brightness in loop().
    • The MPU cannot read the potentiometer or control the LED directly — it must request the current brightness from the MCU via Bridge.call().
    • The MPU has Wi-Fi — because the MPU runs full Debian Linux with Wi-Fi, it can report the brightness level via Telegram on demand.
    • Communication: Bridge.call() on the Linux side invokes Bridge.provide() functions on the MCU side
    • ⚠️ Reserved: /dev/ttyHS1 (Linux) and Serial1 (MCU) are used by the Arduino Router — never open them directly

    In short: MPU requests brightness → MCU reads ADC and converts → MCU reports ADC and brightness values → MPU logs or forwards it.

    MCU sketch — potentiometer-LED with Bridge and Monitor output:

    /* * 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-potentiometer-fade-led */ #include "Arduino_RouterBridge.h" #define LED_PIN 3 #define POTENTIOMETER_PIN A0 void get_brightness() { int adc_value = analogRead(POTENTIOMETER_PIN); int brightness = map(adc_value, 0, 4095, 0, 255); Monitor.print("ADC: "); Monitor.print(adc_value); Monitor.print(", Brightness: "); Monitor.println(brightness); } void setup() { pinMode(LED_PIN, OUTPUT); Bridge.begin(); Monitor.begin(); Bridge.provide("get_brightness", get_brightness); Monitor.println("Potentiometer-LED Bridge ready"); } void loop() { int adc_value = analogRead(POTENTIOMETER_PIN); int brightness = map(adc_value, 0, 4095, 0, 255); analogWrite(LED_PIN, brightness); delay(50); }

    Python script (Arduino App Lab) — poll brightness from Linux:

    /* * 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-potentiometer-fade-led */ from arduino.app_utils import * import time def loop(): while True: Bridge.call("get_brightness") time.sleep(1) App.run(user_loop=loop)
    • Note: Make sure Bridge.begin() is called in the MCU sketch and the sketch is uploaded before running the Python script on the Linux side.
    • ⚠️ Warning: Never directly open /dev/ttyHS1 (on Linux) or use Serial1 (on MCU) in your code — these are reserved by the Arduino Router and accessing them will break the Bridge.

    Detailed Instructions

    • Upload the MCU sketch: Open Arduino App Lab, create a new App, paste the Bridge MCU sketch above into sketch/sketch.ino, install the Arduino_RouterBridge library, and click Run.
    • Add the Python script: Paste the Python code above into the Python tab of the same App.
    • Run the App: Click Run — the Python side polls the brightness level every second.
    • Turn the potentiometer knob and watch the LED brighten and dim.
    • Check the console: Open the Console tab → MCU Monitor subtab to see ADC and brightness values logged.

    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
    Potentiometer-LED Bridge ready ADC: 0, Brightness: 0 ADC: 820, Brightness: 51 ADC: 2048, Brightness: 127 ADC: 3275, Brightness: 204 ADC: 4095, Brightness: 255

    Telegram Integration

    Check the current brightness level remotely from anywhere via Telegram.

    If you do not have a Telegram bot yet, see How to Create a Telegram Bot to get your bot token before continuing.

    MCU sketch: Keep the same MCU sketch from the previous Bridge section — no changes needed. Make sure it is already uploaded and running on the STM32 before proceeding.

    Python script (Arduino App Lab) — Telegram bot for brightness level:

    /* * 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-potentiometer-fade-led */ from arduino.app_utils import * import requests import time BOT_TOKEN = "YOUR_BOT_TOKEN" API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" last_update_id = 0 def send_message(chat_id, text): requests.post(f"{API_URL}/sendMessage", json={"chat_id": chat_id, "text": text}) def get_updates(): global last_update_id resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": 5}) return resp.json().get("result", []) def loop(): global last_update_id updates = get_updates() for update in updates: last_update_id = update["update_id"] msg = update.get("message", {}) chat_id = msg.get("chat", {}).get("id") text = msg.get("text", "").strip() if text == "/brightness": reading = Bridge.call("get_brightness") send_message(chat_id, reading) else: send_message(chat_id, "Commands:\n/brightness — read current LED brightness level (ADC and PWM value)") time.sleep(1) App.run(user_loop=loop)
    • Note: Replace YOUR_BOT_TOKEN with the token obtained from @BotFather on Telegram.
    • Send /brightness to check the current ADC and brightness values.

    Detailed Instructions

    • Upload the MCU sketch: Use the Bridge MCU sketch from the previous section (upload it first if not already done).
    • Paste the Telegram script: Copy the Python code above into the Python tab of your App in Arduino App Lab.
    • Set your token: Replace YOUR_BOT_TOKEN in the script with your actual bot token.
    • Run the App: Click Run — the bot starts listening for Telegram messages.
    • Test it: Turn the potentiometer, send /brightness — the bot replies with the ADC and PWM brightness value.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 12:00:01] Telegram: /brightness [2026-04-29 12:00:01] ADC: 1234, Brightness: 77 [2026-04-29 12:03:20] Telegram: /brightness [2026-04-29 12:03:20] ADC: 3072, Brightness: 191
    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
    /brightness
    10:15 AM ✓✓
    ADC: 1234, Brightness: 77
    10:16 AM

    OpenClaw Integration

    OpenClaw integration for Arduino UNO Q potentiometer-LED control is coming soon.

    • Coming Soon: OpenClaw support for potentiometer-controlled LED brightness on Arduino UNO Q will be covered in a future update.

    Application/Project Ideas

    • Smart dimmer: Use a potentiometer as a physical brightness control for a light — monitor level via Telegram
    • Volume knob indicator: Display the current "volume level" mapped from the potentiometer on a remote monitor
    • Ambient light controller: Tie potentiometer position to a warm-white LED strip brightness
    • Manual override panel: Use the potentiometer to manually override an automated brightness schedule
    • Visual feedback dial: Map potentiometer to an LED array that shows progress or level

    Challenge Yourself

    • Easy: Add a second LED that fades inversely (when LED 1 is bright, LED 2 is dim)
    • Medium: Expose both ADC value and percentage (0–100) via Bridge callbacks
    • Advanced: Build a Telegram bot that logs brightness readings at a fixed interval and sends a daily summary

    Function References

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