How can i use analogWrite to make a fading sound affect with a buzzer

Hi,
I've been trying to understand passive and active buzzers. I know the main differences between them both that are clear.
I am trying to use the analogWrite() function while doing this as it uses the PWM Features. I know that there is the tone function but this does not use PWM functions.

My main goal is to use the analogWrite function to create a sound that goes up in frequency and back down again. Similar to an LED fading which i have previously tested before.
When i do this with a connected buzzer, the sound is not clear and very quiet, basically not hearable.

Please may someone give me some advice to help me with this.

Drive the buzzer with a transistor.

My main goal is to use the analogWrite function to create a sound that goes up in frequency and back down again.

You should use the tone() function for that.

PWM varies the duty cycle, not frequency. Use the tone() function, as Deva_Rishi suggests, or the Tone library or the toneAC library.

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