Running a Piezo buzzer different volume levels, any ideas

Im building a project that needs to operate an alarm at two different volume levels.
I have it configured to simply set an individual digital pin to high to activate 2 buzzers via an FOD852 optocoupler, one is a louder buzzer than the other and with both going at the same time kinda gives it a unique alarm sound.

Is there any other way that this could be done with a single buzzer? These buzzers im using have their own oscillator inside them already so dont need to have any extra components to drive them.
I was looking at whether or not PWM via code would be an option to modulate a more simple (and less expensive piezo buzzer)without a built in oscillator.
How would this work through an optocoupler?

Any ideas, is there any code examples out there to experiment with? Ive seen examples of PWM changing pitch of a buzzer, but not too sure about volume.

Or am i still best just to stick with 2 individually controlled buzzers?

You can do that also from multiple sound (tone/PWM) sources with different resistors for reduced loudness. Using digital outputs without optocouplers is preferable with piezos.

Loudness also can be controlled to some degree with the PWM duty cycle. PWM also allows for multiple frequencies at the same time, while only a single tone() can be active at a time.

Thanks, I might give that a look.
regarding optocouplers, I typically use them to avoid voltage spikes damaging the microcontroller, I can see how that might present issues if trying to modulate a piezo though.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.