Arduino UNO Q - Temperature Sensor

Reading temperature accurately in real time is one of the most common Arduino tasks, and the DS18B20 sensor makes it easy on Arduino UNO Q. With its simple 1-Wire interface, it delivers digital temperature readings directly to your code — no analog conversion needed.

In this tutorial, you will learn:

Arduino UNO Q - Temperature Sensor

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×DS18B20 Temperature Sensor (WITH Adapter)
1×DS18B20 Temperature Sensor (WITHOUT Adapter)
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: Many DS18B20 sensors available in the market are unreliable. We strongly recommend buying the sensor from the DIYables brand using the link provided above. We tested it, and it worked reliably.

Overview of the DS18B20 Temperature Sensor

The DS18B20 is a digital temperature sensor that communicates over a single data wire using the 1-Wire protocol.

  • Protocol: 1-Wire digital — one data pin handles both power and communication
  • Range: -55°C to +125°C (-67°F to +257°F) with ±0.5°C accuracy between -10°C and +85°C
  • Output: Digital — no analog-to-digital conversion needed
  • Power: Powered by 3.3V or 5V; supports parasitic power mode (powered from data line)
  • Multiple sensors: Up to 127 DS18B20 sensors can share a single data pin, each with a unique 64-bit address
  • Package types: TO-92 transistor-style package and waterproof stainless steel probe

Pinout

DS18B20 temperature sensor Pinout

The DS18B20 temperature sensor has three pins:

DS18B20 Pin Function Arduino UNO Q Pin
GND Ground GND
VCC Power (3.3V or 5V) 5V
DATA 1-Wire Data Bus 4
  • Pull-up resistor: A 4.7kΩ resistor between the DATA pin and VCC is required for reliable 1-Wire communication
  • Adapter: We recommend buying a DS18B20 sensor with a wiring adapter — it includes the pull-up resistor and a screw terminal block, so no extra components are needed

How to Program for DS18B20 Temperature Sensor

  • Include the libraries:
#include <OneWire.h> #include <DallasTemperature.h>
  • Create a OneWire object and a DallasTemperature object for the pin connected to the sensor's DATA pin:
OneWire oneWire(SENSOR_PIN); // Initialize a new OneWire instance on the sensor pin DallasTemperature DS18B20(&oneWire); // Create a DallasTemperature object linked to the OneWire instance
  • Initialize the sensor in setup():
DS18B20.begin(); // Start the sensor initialization process
  • Request a temperature reading:
DS18B20.requestTemperatures();
  • Read temperature in Celsius:
float temperature_C = DS18B20.getTempCByIndex(0);
  • (Optional) Convert Celsius to Fahrenheit:
float temperature_F = temperature_C * 9.0 / 5.0 + 32.0;

Wiring Diagram

  • Breadboard wiring (with pull-up resistor):
The wiring diagram between Arduino UNO Q Temperature Sensor

This image is created using Fritzing. Click to enlarge image

  • Wiring diagram with adapter (no extra resistor needed):
The wiring diagram between Arduino UNO Q DS18B20 Adapter

This image is created using Fritzing. Click to enlarge image

We recommend buying a DS18B20 sensor with a wiring adapter. This adapter makes it simple to connect because it includes a resistor, so you do not need an extra one.

MCU Code (Direct Arduino Sketch)

Here is the Arduino sketch that runs directly on the STM32 MCU to read temperature from the DS18B20 sensor and output readings to the App Lab console.

  • Initializes the DS18B20 sensor using the DallasTemperature library
  • Requests a temperature reading every 500ms
  • Reads temperature in Celsius and converts to Fahrenheit
  • Outputs both values to the App Lab console
/* * 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-temperature-sensor */ #include <OneWire.h> #include <DallasTemperature.h> #define SENSOR_PIN 4 // The Arduino UNO Q pin connected to DS18B20 sensor's DQ pin OneWire oneWire(SENSOR_PIN); // setup a oneWire instance DallasTemperature DS18B20(&oneWire); // pass oneWire to DallasTemperature library void setup() { DS18B20.begin(); // initialize the sensor } void loop() { DS18B20.requestTemperatures(); // send the command to get temperatures float temperature_C = DS18B20.getTempCByIndex(0); // read temperature in Celsius float temperature_F = temperature_C * 9.0 / 5.0 + 32.0; // convert Celsius to Fahrenheit delay(500); }

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 sensor: Connect the DS18B20 to Arduino UNO Q pin 4 according to the wiring diagram above. If using the adapter, follow the adapter 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 — this can take several minutes on first launch.
  • 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_DS18B20
  • 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 that 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 DallasTemperature created by Miles Burton , Tim Newsome , Guil Barros , Rob Tillaart 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
    DallasTemperature Miles Burton , Tim Newsome , Guil Barros , Rob Tillaart

    Supports DS18B20, DS18S20, DS1822, DS1820

    3.9.0
    Install
    More Info
    • Search for OneWire created by Jim Studt, Tom Pollard, Robin James, Glenn Trewitt, Jason Dangel, Guillermo Lovato, Paul Stoffregen, Scott Roberts, Bertrik Sikken, Mark Tillotson, Ken Butcher, Roger Clark, Love Nystrom 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
    OneWire Jim Studt, Tom Pollard, Robin James, Glenn Trewitt, Jason Dangel, Guillermo Lovato, Paul Stoffregen, Scott Roberts, Bertrik Sikken, Mark Tillotson, Ken Butcher, Roger Clark, Love Nystrom

    2.3.8
    Install
    More Info
    • 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
    • Check readings: Open the Console tab → Serial Monitor subtab to see live temperature output.
    • Test: Hold the sensor in your hand or place it in warm water and watch the temperature rise.
    • Pro Tip: The DS18B20 takes about 750ms to complete a conversion — if readings seem frozen, increase the delay() value to at least 800ms.

    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
    Temperature: 22.31°C ~ 72.16°F Temperature: 22.44°C ~ 72.39°F Temperature: 22.50°C ~ 72.50°F Temperature: 24.37°C ~ 75.87°F Temperature: 26.00°C ~ 78.80°F Temperature: 28.12°C ~ 82.62°F

    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.

    • DS18B20 is connected to the MCU (STM32) — the sensor is wired to a digital pin on the STM32, not to the MPU. The MCU reads raw 1-Wire data from the sensor directly.
    • MPU cannot read the sensor directly — to get the temperature, the MPU must send a request to the MCU via Bridge.call(). The MCU executes the corresponding Bridge.provide() function and returns the result.
    • MPU has Wi-Fi — because the MPU runs full Debian Linux with Wi-Fi support, it can connect to the Internet and do things the MCU cannot: send Telegram messages, call REST APIs, upload data to cloud services, and more.
    • 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: MCU reads the sensor → MPU requests the value → MPU uses it over the Internet.

    MCU sketch — exposes temperature reading to the Linux 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-temperature-sensor */ #include "Arduino_RouterBridge.h" #include <OneWire.h> #include <DallasTemperature.h> #define SENSOR_PIN 4 // The Arduino UNO Q pin connected to DS18B20 sensor's DQ pin OneWire oneWire(SENSOR_PIN); DallasTemperature DS18B20(&oneWire); void setup() { DS18B20.begin(); Bridge.begin(); Monitor.begin(); Bridge.provide("read_temperature_c", read_temperature_c); Bridge.provide("read_temperature_f", read_temperature_f); Monitor.println("MCU Bridge ready."); } void loop() {} float read_temperature_c() { DS18B20.requestTemperatures(); return DS18B20.getTempCByIndex(0); } float read_temperature_f() { float c = DS18B20.getTempCByIndex(0); return c * 9.0 / 5.0 + 32.0; }

    Python script (Arduino App Lab) — read temperature 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-temperature-sensor */ from arduino.app_utils import * import time def loop(): temp_c = Bridge.call("read_temperature_c") temp_f = Bridge.call("read_temperature_f") print(f"Temperature: {temp_c:.2f}°C ~ {temp_f:.2f}°F") 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 DallasTemperature and OneWire libraries, 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 Linux side will start requesting temperature readings every second.
    • Check the console: Open the Console tab → Python Console subtab to see live temperature output from the Linux side.
    • Pro Tip: Adjust the time.sleep(1) value to control how often temperature is polled — increase it to reduce CPU usage on the Linux side.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    Temperature: 22.31°C ~ 72.16°F Temperature: 22.44°C ~ 72.39°F Temperature: 24.37°C ~ 75.87°F Temperature: 26.00°C ~ 78.80°F

    Telegram Integration

    You can read the temperature from your DS18B20 sensor remotely over Telegram — send a command from anywhere and get the current temperature reading back instantly.

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

    This section covers:

    • Running a Python script on the Linux side of Arduino UNO Q to listen for Telegram messages
    • Forwarding the temperature request to the MCU side via Bridge.call()
    • Sending the temperature reading back as a Telegram reply

    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 DS18B20 temperature sensor:

    /* * 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-temperature-sensor */ 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 == "/temperature": temp_c = Bridge.call("read_temperature_c") temp_f = Bridge.call("read_temperature_f") send_message(chat_id, f"Temperature: {temp_c:.2f}°C ~ {temp_f:.2f}°F") else: send_message(chat_id, "Commands:\n/temperature — get current temperature reading") time.sleep(1) App.run(user_loop=loop)
    • Note: Replace YOUR_BOT_TOKEN with the token obtained from @BotFather on Telegram.
    • Send /temperature to your bot to get the current temperature reading from the DS18B20 sensor.

    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 immediately.
    • Test it: Send /temperature to your bot and get the current reading back.
    • Pro Tip: Schedule /temperature polls from your phone's Telegram to monitor temperature trends throughout the day.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 09:12:01] Telegram: /temperature [2026-04-29 09:12:01] Temperature: 22.50°C ~ 72.50°F [2026-04-29 09:15:34] Telegram: /temperature [2026-04-29 09:15:34] Temperature: 25.12°C ~ 77.22°F [2026-04-29 09:20:07] Telegram: /temperature [2026-04-29 09:20:07] Temperature: 28.37°C ~ 83.07°F
    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
    /temperature
    10:15 AM ✓✓
    Temperature: 22.50°C ~ 72.50°F
    10:16 AM
    /temperature
    10:17 AM ✓✓
    Temperature: 28.37°C ~ 83.07°F
    10:18 AM

    OpenClaw Integration

    OpenClaw integration for Arduino UNO Q with the DS18B20 temperature sensor is coming soon.

    • Coming Soon: OpenClaw support for reading temperature from the DS18B20 sensor on Arduino UNO Q will be covered in a future update.

    Application/Project Ideas

    Here are some project ideas you can build with the DS18B20 temperature sensor and Arduino UNO Q:

    • Room temperature monitor: Log temperature readings every minute and display trends on the Linux side
    • Temperature alert system: Send a Telegram alert when temperature exceeds a set threshold
    • Smart thermostat: Read DS18B20 temperature from the Linux side and control a relay or fan via Bridge.call() based on the reading
    • Data logger: Have the Python side save temperature readings to a CSV file on the Linux filesystem every few seconds
    • Multi-sensor network: Connect multiple DS18B20 sensors to a single pin (each has a unique ID) and read all of them from the Linux side
    • Plant protection system: Monitor outdoor temperature and send a Telegram warning when frost conditions are detected

    Need more DS18B20 details? Check out the Arduino DS18B20 tutorial for more ideas.

    Challenge Yourself

    Try these challenges with the DS18B20 temperature sensor and Arduino UNO Q to level up your skills:

    • Easy: Modify the MCU sketch to also read and display the sensor's unique 64-bit address alongside the temperature reading
    • Medium: Add a second DS18B20 sensor on the same data pin and have the Python side read both sensors independently using their unique addresses
    • Advanced: Build a Telegram-controlled temperature logger that saves readings to a file on the Linux side and sends a summary report (min/max/average) when requested via Telegram

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