Skip to main content
Visitor
August 15, 2026
Question

How can I play a simple melody using a piezo buzzer on STM32?

  • August 15, 2026
  • 1 reply
  • 12 views

Hi everyone,

I’m working on a small STM32 project using a piezo buzzer and would like to generate a simple melody from different frequency tones.

I can already generate individual tones by changing the timer frequency, but I’m not sure what the best approach is for playing a sequence of notes with different durations.

For example, I would like to create a short melody such as:

  • Note A → short duration
  • Note B → short duration
  • Note C → longer duration
  • Pause → short duration
  • Repeat

Would it be better to use a timer with PWM and change the frequency for each note, or is there another recommended approach for generating melodies on STM32?

I’m mainly looking for guidance on the structure of the code and how to handle the note frequency and duration cleanly.

Thanks in advance for any suggestions!

1 reply

AScha.3
Super User
August 15, 2026

Hi,

is this some kind of spam , to get clicks on mama link ?

-or just funny, because choosing H7 for generating tones ??

Ask google or Gemini , how to do kiddie project.

If you feel a post has answered your question, please click on " Best Answer ".