Main Site Documentation

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


#1

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?


#2

Try changing duty cycle of the pwm.


#3

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.


#4

A couple links on this topic:

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


#5

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.


#6

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


#7

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


#8

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


#9

solder bodge another transistor on :slight_smile: