Beep with volume control

I built a project with a morse key. My arduino drives a buzzer and I can control the pitch with the tone library, but controlling the volume is really hard. I added a potentiometer in series but it is really on or off. Once the voltage drops below a certain level, the buzzer goes off. Above that level it is on.

Is there an alternative to a buzzer? All I need are morse code beeps, nothing fancy, but with a volume control. I'm open to both hardware and software suggestions.

What type of Arduino board do you have? Does it have an analog output? Regardless, you may need a different type of speaker instead of a buzzer.

  • What buzzer are you using ?

  • Try a 500Ω potentiometer outside leads between GPIO and GND, buzzer from wiper to GND.

Arduino Pro Micro. Open for any alternative buzzer/speaker

Tried this, but buzzer is really going on/off. No real volume control. Also tried with a resistor in parallel to reduce 500ohm range to a smaller range to get finer control, but it's really on/off.

What buzzer are you using ?

Connect your buzzer directly to 5volt and ground, and see if it beeps.
If it does, then you have an active buzzer.

Only passive (piezo) buzzers can produce different tones, and can be volume controlled.
The ToneAC (not tone) library has a software volume option.
Leo..

Besides possibly needing a lower resistance pot, because our ears are logarithmic volume controls are normally Audio Taper. A regular linear pot make more-noticeable change at lower volume with very little perceived change past the half-way point.

That's more important for an everyday volume control than for an adjustment that's done less frequently.

A pot won't work at all with an active buzzer...
Leo..

I have found both types in my drawer. The active one cannot be controlled in volume, but it does produce tones with the tone library.

The passive one that I found is always quiet. No markings on it, so perhaps it is a 12V one and my 5V cannot drive it hard enough. Any suggestions on a good passive buzzer from the usual chinese stores?

Will look up that ToneAC library, sounds promising

You shouldn't power a "claxon" with an Arduino pin.

Correct, but toneAC tries to compensate for that by driving it between two Arduino pins.
Leo..

A speaker and audio amp would enable you to control volume.

Maybe a digital potentiometer set to control the volume of an audio amplifier (replacing the embedded trimmer/pot) could do the job?