སྒྱུ་རྩལ
མཛེས་སྡུག་དང་བདེ་ཐང
བཟོ་རིག
རིག་གནས་དང་ལོ་རྒྱུས
དགའ་སྟོན
ཁོར་ཡུག
ཟས་དང་བཏུང་རྫས
ཕྱིར་འཕྲུལ་རིག
ཚན་རིག
རྩེད་འགྲན
རིག་རྩལ
གྱོན་རུང
Using a Piezo Buzzer — SIK Circuit 11
Ed

བཟོས་མཁན

Ed

17. སྤྱི་ཟླ་གསུམ་པ 2026FI
༨༣

Using a Piezo Buzzer — SIK Circuit 11

Play a song with a piezo buzzer! Learn about the tone() function, musical frequencies, arrays for storing melodies, and how to create your own tunes.

ལམ་སྟོན

1

Parts & Introduction

A piezo buzzer converts electrical signals into sound. Using Arduino's built-in tone() function, you can play specific musical frequencies. This sketch plays a simple melody using character arrays for notes and integer arrays for timing.

Parts Needed

  • 1x Arduino Uno + USB cable
  • 1x Breadboard
  • 1x Piezo Buzzer
  • 3x Jumper Wires

Note Frequency Reference

NoteFreq
c262 Hz
d294 Hz
e330 Hz
f349 Hz
g392 Hz
a440 Hz
b494 Hz
C523 Hz

གོམ་པ་འདིའི་རྫས་རིགས:

SparkFun Inventor's Kit - V3.2SparkFun Inventor's Kit - V3.21 ཡོ་བྱད་ཚན།

ལག་ཆས་དགོས་མཁོ:

Computer with Arduino IDEComputer with Arduino IDE
2

Hardware Hookup

Wiring Instructions

  1. Place the piezo buzzer in the breadboard. It has two pins — one marked with "+".
  2. Connect the positive pin (+) to Arduino Digital Pin 9 (PWM).
  3. Connect the negative pin to GND.

Tip: If the buzzer doesn't fit easily, try rotating it slightly to align with diagonal breadboard holes.

གོམ་པ་འདིའི་རྫས་རིགས:

Piezo BuzzerPiezo Buzzer1 དུམ་བུ།
BreadboardBreadboard1 དུམ་བུ།
Jumper WiresJumper Wires2 དུམ་བུ།
3

Arduino Code

Open the Arduino IDE and upload the following sketch to your Arduino board.

piezo_buzzer.inoarduino
/*
SparkFun Inventor's Kit
Example sketch 11 — BUZZER

Use the buzzer to play a song!

Hardware connections:
  Buzzer positive pin (+) to digital pin 9 (PWM)
  Buzzer negative pin to GND

This code is completely free for any use.
*/

const int buzzerPin = 9;

const int songLength = 18;

char notes[] = "cdfda ag cdfdg gf ";  // space = rest

int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};

int tempo = 113;

void setup()
{
  pinMode(buzzerPin, OUTPUT);
}

void loop()
{
  int i, duration;

  for (i = 0; i < songLength; i++)
  {
    duration = beats[i] * tempo;

    if (notes[i] == ' ')
    {
      delay(duration);
    }
    else
    {
      tone(buzzerPin, frequency(notes[i]), duration);
      delay(duration);
    }
    delay(tempo/10);
  }

  while(true){}  // Play once, then stop. Remove this line to loop.
}

int frequency(char note)
{
  int i;
  const int numNotes = 8;

  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};

  for (i = 0; i < numNotes; i++)
  {
    if (names[i] == note)
    {
      return(frequencies[i]);
    }
  }
  return(0);
}

གོམ་པ་འདིའི་རྫས་རིགས:

Arduino Uno R3Arduino Uno R31 དུམ་བུ།

ལག་ཆས་དགོས་མཁོ:

Computer with Arduino IDEComputer with Arduino IDE
4

Test & Experiment

What You Should See

You won't see anything — but you'll hear a melody playing from the buzzer! The song plays once and stops.

Troubleshooting

  • No sound: The buzzer pins are easy to misplace on the breadboard. Double-check placement and make sure both pins have good contact.
  • Want it to stop: Pull the buzzer out while working on other things, plug it back in to test.

Experiments to Try

  • Remove the while(true){} line to make the song loop continuously.
  • Write your own melody by changing the notes[] and beats[] arrays.
  • Add more notes by expanding the frequency() function with sharps and flats.
  • Use a button (from Circuit 5) to trigger the melody on demand.

རྫས་རིགས

5
  • SparkFun Inventor's Kit - V3.2ཁེ་ཕོགས 10%
    1 ཡོ་བྱད་ཚན།
    $108.84
  • Breadboardཁེ་ཕོགས 10%
    1 དུམ་བུ།
    Magento Legacy Storeships internationally
    ལས་$9.76
  • Jumper Wiresཁེ་ཕོགས 10%
    2 དུམ་བུ།
    Magento Legacy Storeships internationally
    ལས་$4.27
  • Arduino Uno R3ཁེ་ཕོགས 10%
    1 དུམ་བུ།
    Magento Legacy Storeships internationally
    ལས་$27.80
  • 1 དུམ་བུ།
    ས་ཆ་འཛིན

ལག་ཆས་དགོས་མཁོ

1
ཚོད་དཔག་བསྡོམས
བཟོ་མི་གིས་ཉོ་མི་དེ། གོང་ཚད་མེད་པར་སྟོན་མི་ཅ་ཆས་ཚུ་ཁྱོད་ཀྱིས་ག་ཏེ་ལས་ཉོཝ་ཨིན་ན་དེ་ལས་ཐོབ་ཨིན།
$108.84

CC0 སྤྱི་དབང

བིལུ་པིརིན་ཊི་འདི་CC0 འོག་བཀྲམས་ཡོད། ཁྱེད་རང་གིས་ཆོག་མཆན་མ་བཞེས་པར་ཕབ་ལེན་དང་བཟོ་བཅོས། བགོ་བཤའ། དགོས་མཁོ་གང་ལའང་བཀོལ་སྤྱོད་བྱས་ཆོག

བཟོ་མཁན་ལ་རྒྱབ་སྐྱོར་བྱེད་པའི་ཆེད་ཁོང་ཚོའི་བིལུ་པིརིན་ཊི་བརྒྱུད་ཐོན་སྐྱེད་ཉོ། བཟོ་མཁན་གྱིས བཟོ་མཁན་གྱི་ཁེ་ཕོགས ཚོང་པས་གཏན་འཁེལ་བྱས་པ། ཡང་ན་བིལུ་པིརིན་ཊི་འདིའི་པར་གསར་བཟོས་ཏེ་ཁྱེད་རང་གི་བིལུ་པིརིན་ཊི་ནང་མཐུད་སྦྲེལ་བྱས་ཏེ་ཡོང་སྒོ་བགོ་བཤའ་བྱེད།

གྲོས་བསྡུར

(0)

ནང་འཛུལ གྲོས་བསྡུར་ནང་མཉམ་ཞུགས་ཆེད

བསམ་ཚུལ་ཚུ་ཐོབ་བཞིན...