RETRO - Can the volume of the piezo be modified in code?

I think the answer is no, but for my project, I want to vary the volume of the tone, not just the frequency.

I could probably hook up an AMP gadgeteer module with an external speaker, but I would really like to use just the on board buzzer.

Any ideas?

Try changing duty cycle of the pwm.

AFAIK, while you can vary volume of a piezo somewhat by modifying duty cycle, it’s pretty limited, since a 50% duty cycle is where the piezo wants to be vibrating/oscillating. Depending on the frequency, you may get more or less ability to control volume by duty cycle, but overall, you probably won’t get the results you want.

To truly control volume, you need to vary voltage, which I don’t think is possible with the onboard piezo. You could certainly rig something up with an external piezo or speaker, though.

A couple links on this topic:

http://forums.parallax.com/showthread.php/75707-How-to-Amplifying-a-Piezo-Speaker-and-Volume-Control

Apparently, if the other pin of the Piezo was connected to another PWM pin instead of GND, I could drive 2 PWM out of phase to create up to twice the volume and vary it. Not gonna mod the board though.

Thanks for the thoughts.

Maybe I will just cup my hand over it to vary volume like playing a harmonica.

Ooh! Good idea. Add a wind sensor, and play the blues on it. You could use the accelerometer for bending. :wink:

Now, don’t go stealing my contest idea! Or, go ahead, why not. :smiley:

@ Blue Hair Bob - Looked at the schematics. Pwm pin controls transistor that piezo is connected to. Out of luck.

solder bodge another transistor on :slight_smile: