Arduino UNO Q - Piezo Buzzer

A buzzer produces sounds — from simple beeps to full melodies. In this tutorial, you will learn how to connect a piezo buzzer to Arduino UNO Q, play tones and melodies using the tone() function, and trigger sounds remotely via Telegram.

Arduino UNO Q - Piezo Buzzer

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×3-24V Active Piezo Buzzer
1×Alternatively, Active Piezo Buzzer Module
1×Alternatively, Passive Piezo Buzzer Module
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 .

Overview of Piezo Buzzer

Active vs Passive Buzzer

  • Active Buzzer: Makes continuous sound when voltage is applied — simplest to use
  • Passive Buzzer: Requires a changing frequency signal (square wave) — can produce different tones and melodies

Pinout

A buzzer has two pins:

  • Positive (+) pin: Connect to the Arduino UNO Q output pin
  • Negative (−) pin: Connect to GND
Piezo Buzzer Pinout

How To Program

Arduino's built-in tone() function generates a square wave on any digital pin, driving both active and passive buzzers:

  • tone(pin, frequency, duration) — play a note at a given frequency for a given duration
  • noTone(pin) — stop the tone

Wiring Diagram

  • Wiring with standalone piezo buzzer:
The wiring diagram between Arduino UNO Q Piezo Buzzer

This image is created using Fritzing. Click to enlarge image

  • Wiring with piezo buzzer module:
The wiring diagram between Arduino UNO Q Piezo Buzzer Module

This image is created using Fritzing. Click to enlarge image

MCU Code — Play a Melody

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-piezo-buzzer */ #include "pitches.h" #define BUZZER_PIN 6 // pin connected to the buzzer // notes in the melody int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; // note durations: 4 = quarter note, 8 = eighth note, etc. int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; void setup() { int size = sizeof(noteDurations) / sizeof(int); for (int thisNote = 0; thisNote < size; thisNote++) { int noteDuration = 1000 / noteDurations[thisNote]; tone(BUZZER_PIN, melody[thisNote], noteDuration); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); noTone(BUZZER_PIN); } } void loop() { // melody plays once in setup — nothing needed here }

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 buzzer: Connect the positive pin to pin 6 and the negative pin to GND.
  • 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_Buzzer
  • 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 into the sketch file.
  • Add the pitches.h file: Create a new tab in the sketch named pitches.h and paste the standard Arduino pitches header content into it.
    • 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
    • Listen: The buzzer plays the melody once when the board starts.

    Modifying the Melody — Jingle Bells

    To play a different song, update the melody[] and noteDurations[] arrays. Here is the Jingle Bells version:

    /* * 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-piezo-buzzer */ #include "pitches.h" #define BUZZER_PIN 6 // pin connected to the buzzer // Jingle Bells notes int melody[] = { NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_G5 }; int noteDurations[] = { 8, 8, 4, 8, 8, 4, 8, 8, 8, 8, 2, 8, 8, 8, 8, 8, 8, 8, 16, 16, 8, 8, 8, 8, 4, 4 }; void setup() { int size = sizeof(noteDurations) / sizeof(int); for (int thisNote = 0; thisNote < size; thisNote++) { int noteDuration = 1000 / noteDurations[thisNote]; tone(BUZZER_PIN, melody[thisNote], noteDuration); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); noTone(BUZZER_PIN); } } void loop() { // melody plays once in setup — nothing needed here }

    Detailed Instructions

    • Replace the sketch with the Jingle Bells version and click Run.
    • Listen to the buzzer play Jingle Bells on startup.

    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 buzzer is connected to the MCU (STM32) — wired to a digital output pin. The MCU drives the buzzer using tone() and noTone().
    • The MPU cannot control the buzzer directly — it must trigger a sound by calling a function on the MCU via Bridge.call().
    • The MPU has Wi-Fi — because the MPU runs full Debian Linux with Wi-Fi, it can trigger buzzer sounds via Telegram on demand.
    • Communication: Bridge.call() on the Linux side invokes Bridge.provide_safe() functions on the MCU side (since tone()/noTone() are hardware APIs)
    • ⚠️ Reserved: /dev/ttyHS1 (Linux) and Serial1 (MCU) are used by the Arduino Router — never open them directly

    In short: MPU requests beep or melody → MCU drives buzzer via tone() → MCU confirms action → MPU logs or forwards it.

    MCU sketch — buzzer 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-piezo-buzzer */ #include "Arduino_RouterBridge.h" #include "pitches.h" #define BUZZER_PIN 6 void beep() { tone(BUZZER_PIN, NOTE_C5, 200); delay(250); noTone(BUZZER_PIN); Monitor.println("Beep played"); } void play_melody() { int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; int size = sizeof(noteDurations) / sizeof(int); for (int i = 0; i < size; i++) { int noteDuration = 1000 / noteDurations[i]; tone(BUZZER_PIN, melody[i], noteDuration); delay((int)(noteDuration * 1.30)); noTone(BUZZER_PIN); } Monitor.println("Melody played"); } void setup() { Bridge.begin(); Monitor.begin(); Bridge.provide_safe("beep", beep); Bridge.provide_safe("play_melody", play_melody); Monitor.println("Piezo Buzzer Bridge ready"); } void loop() {}

    Python script (Arduino App Lab) — trigger buzzer 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-piezo-buzzer */ from arduino.app_utils import * import time def loop(): print("Playing beep...") Bridge.call("beep") time.sleep(3) print("Playing melody...") Bridge.call("play_melody") time.sleep(5) 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 into sketch/sketch.ino, add pitches.h as a new tab, 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 cycles between beep and melody automatically.
    • Check the console: Open the Console tab → MCU Monitor subtab to see "Beep played" and "Melody played" messages.

    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
    Piezo Buzzer Bridge ready Beep played Melody played Beep played

    Telegram Integration

    Trigger buzzer sounds 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 buzzer control:

    /* * 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-piezo-buzzer */ 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 == "/beep": Bridge.call("beep") send_message(chat_id, "Beep played on the buzzer.") elif text == "/melody": Bridge.call("play_melody") send_message(chat_id, "Melody is playing on the buzzer.") else: send_message(chat_id, "Commands:\n/beep — play a short beep\n/melody — play a melody") time.sleep(1) App.run(user_loop=loop)
    • Note: Replace YOUR_BOT_TOKEN with the token obtained from @BotFather on Telegram.
    • Send /beep to trigger a short beep.
    • Send /melody to play the melody.

    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: Send /beep — hear a short tone from the buzzer. Send /melody — hear the full melody play.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 12:00:01] Telegram: /beep [2026-04-29 12:00:01] Beep played on the buzzer. [2026-04-29 12:03:20] Telegram: /melody [2026-04-29 12:03:20] Melody is playing on the buzzer.
    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
    /beep
    10:15 AM ✓✓
    Beep played on the buzzer.
    10:16 AM
    /melody
    10:17 AM ✓✓
    Melody is playing on the buzzer.
    10:18 AM

    OpenClaw Integration

    OpenClaw integration for Arduino UNO Q piezo buzzer control is coming soon.

    • Coming Soon: OpenClaw support for piezo buzzer control on Arduino UNO Q will be covered in a future update.

    Application/Project Ideas

    • Remote alarm: Trigger a buzzer alarm remotely via Telegram when an event occurs
    • Notification beeper: Beep when a sensor threshold is crossed — triggered from MPU Linux logic
    • Doorbell: Use a button to beep a doorbell tone; notify via Telegram that someone rang
    • Melody jukebox: Build a Telegram bot that lets you pick different melodies to play remotely
    • Timer alert: Use the Linux MPU's clock to play a buzzer alarm at a scheduled time

    Challenge Yourself

    • Easy: Add a second melody (e.g., Happy Birthday) and expose it as /birthday in Telegram
    • Medium: Add a play_n_beeps(n) Bridge callback and expose it in Telegram as /beep <count>
    • Advanced: Build a Telegram bot that plays a countdown melody before triggering an action — use time-based scheduling on the Linux MPU side

    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!