How do we vary the output voltage value in a gradual manner instead of the discrete manner?

I wish to customise my buzzer project so I needed to learn about the analogWrite function. But I couldn’t find the relavant matter. I wish to supply voltage to the buzzer in a gradual manner and I wish to control how steeply does the variation occurs, i.e., control the change in voltage as well as the time interval between which it happens.
All in all, I wish to hear that fluctuating sounds of buzzers. Wish to customise it.

Thanks in advance for your response! Any help from your side is appreciated!!!

Hi @aditya198018d

analogWrite() writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses, drive a motor at various speeds, or vary the frequency of buzzer. After a call to analogWrite() , the pin will generate a steady rectangular wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() ) on the same pin.

Hope this helps! :smiley:

Hi @aditya198018d,

Have you gone through the following documentation link?

Also, if you are doing the course available in then there is a chapter for controlling the intensity of an LED available. For controlling the buzzer, the code will be the same, with the difference that you will have to connect a buzzer instead of an LED.

Yes sir, I already have. I mentioned it in the description that details given are insufficient. Using analogWrite command they showed that we can give any value to output voltage ranging from 0 to 255. But the manner in which they do will give results in discrete form. That’s my query. How do I obtain results in analog manner, a continuous wave?


You do realise that the voltage change can be control down to 12mv right?

It does not matter what method you use, if you are using a digital system to generate an analog signal, you will have some level of discretisation.

The best you can achieve with Bolt WiFi module is 12mv. Do you need to step change to be lower than that?

1 Like