Buzzer tones.

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Billduck1302
Posts: 26
http://meble-kuchenne.info.pl
Joined: Fri Dec 06, 2024 4:41 pm
Has thanked: 1 time
Been thanked: 1 time

Buzzer tones.

Post by Billduck1302 »

I would like to play several notes with the buzzer component. For example, Close Encounters is 393,516,476,361,393 Hz. Sort of!
I see that the buzzer frequency is a property of the component.
So my question is "How can I change the frequency when running a program". The frequency is not available as a variable.
I'm sure it is in there, but I can not find it.

This is a great tone generator, that I can use to play the tune. <https://www.szynalski.com/tone-generator/?
Attachments
Buzzer_V1.fcfx
(15.53 KiB) Downloaded 9 times

mnfisher
Valued Contributor
Posts: 1693
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 146 times
Been thanked: 789 times

Re: Buzzer tones.

Post by mnfisher »

The buzzer component only turns a pin on (or off) to play a tone - which is a feature of the buzzer hardware.... The frequency value is only for simulation.

It might be possible to alter the tone using PWM either with the buzzer device or by outputting directly (via a transistor or amplifier) to a speaker...

There was a couple of example of this in the forums.

Martin

medelec35
Matrix Staff
Posts: 2167
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 662 times
Been thanked: 731 times

Re: Buzzer tones.

Post by medelec35 »

Hi.
The PWM code within UNO is currently not accurate.
I have created a project to give you great accuracy for 4 PWM pins.
you can use that to generate required tones.
This is a screen shot of the notes I added within Main.
PWM notes.jpg
PWM notes.jpg (27.44 KiB) Viewed 156 times
This is how you set pwm to a specified pin frequency and duty.
Uno Accurate PWM.png
Uno Accurate PWM.png (27.67 KiB) Viewed 156 times
Attachments
Uno PWM example v3.fcfx
(22.57 KiB) Downloaded 13 times
Martin

Billduck1302
Posts: 26
Joined: Fri Dec 06, 2024 4:41 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Buzzer tones.

Post by Billduck1302 »

It works, thank you.
How would I go about giving the tone a duration?
Also, Is the PWM C code a component? Obviously I don't get it.

medelec35
Matrix Staff
Posts: 2167
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 662 times
Been thanked: 731 times

Re: Buzzer tones.

Post by medelec35 »

You're welcome.
When you use the PWM function the note will remain on.
you then can use a delay for the duration then to silence you can use a duty of 0 as that will just keep the pin low.
Alternatively after the duration of the first note, just add another PWM call function to set the PWM to the next frequency (note).

I could add another parameter for duration, but wanted to keep the call function a simple as possible.

No the PWM Flowchart is not a component, it's just a PWM generating project that makes PWM on the UNO much better than it currently is.
It is just a test project.
Martin

Billduck1302
Posts: 26
Joined: Fri Dec 06, 2024 4:41 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Buzzer tones.

Post by Billduck1302 »

Thanks again. I will try that.
Oddly enough, with the attached program, when I add 2 Buzzer components,
with different frequencies, and test it, I get the same frequency sound.
Attachments
Buzzer_V1.fcfx
(16.02 KiB) Downloaded 8 times

medelec35
Matrix Staff
Posts: 2167
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 662 times
Been thanked: 731 times

Re: Buzzer tones.

Post by medelec35 »

You can't use the Buzzer component as mnfisher has stated for your application.
you can use my project file to do what you are after.
For example continuously changing from one tone to another, the attached will do that for you.
I have made it as simple as I can.
Attachments
Uno PWM example two tone.fcfx
(22.25 KiB) Downloaded 4 times
Martin

medelec35
Matrix Staff
Posts: 2167
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 662 times
Been thanked: 731 times

Re: Buzzer tones.

Post by medelec35 »

Hello.
The buzzer component does not rapidly switch on and off at the set frequency during the on period to generate a tone for a speaker or piezo.
The frequency is for simulation only.
Martin stated that:
mnfisher wrote:
Tue Oct 28, 2025 10:54 am
The buzzer component only turns a pin on (or off) to play a tone - which is a feature of the buzzer hardware.... The frequency value is only for simulation.
All the buzzer does when on is set a pin high (polarity Active High) or low (Active low), then the pin is reverted to the non active state.
In effect it's like the LED component with a delay and sound simulation.
That means you will need to connect a fixed frequency buzzer i.e. it buzzes when you connect a steady DC supply to it.
This is not your intention, so you will need to go down the PWM route for a loudspeaker and the appropriate buffer component, if the current draw exceeds maximum current draw of the microcontroller.
Martin

Post Reply