make my arduino whistle

hi there,

I'm trying to make my Arduino whistle like in this video.

I have a basic speaker (photo attached).

is there any way to do it? (code will be amazing).

thank you!


The video is a wireless microphone/PA... There is no microcontroller...

If you actually want to make something with the Arduino - The Arduino can drive a piezo transducer, but if you want to drive a 4 or 8-Ohm speaker you need an amplifier. Or, you can use regular powered computer speakers.

A piezo tweeter is essentially a tweeter (high frequencies). Musical greeting cards use piezo transducers if you want an idea what they sound like.

And, the Arduino can only put-out square waves so you can't control the "character" of the sound and you can't play MP3 or WAV files.* A whistle is close to a "pure" sine wave, maybe with some white noise.

If you want to know what square waves sound like, Audacity can generate a square wave file that you can play on your computer. Or, if you have a piezo transducer or powered speakers handy you can try the Tone Melody Example. It shouldn't be too hard to modify that sketch for multiple small-fast frequency changes to "slide" the pitch and get a "wolf whistle" (to the extent you can get a whistle sound with square waves).

If you want to play a WAV or MP3 file you can get an audio shield. An audio shield can give good quality audio and it does all of the "work"... The Arduino just does a little control, like starting/stopping and controlling the volume, etc. Some audio shields have a (small) amplifier built-in so you can directly connect speakers.

  • There is a library called TMRpcm that can play WAV files but it's not true analog (or true PCM) and the sound quality won't be as good as an audio shield with a true analog output. And since it's "full power" digital PWM, unfiltered it can cause havoc with amplifiers and I wouldn't use it with a "good" amplifier that I cared about.

There is a library called TMRpcm that can play WAV files but it's not true analog (or true PCM)

Well it is PWM, not sure what you mean by PCM. Yes I know it stands for pulse code modulation, but not sure what you mean in this context.

A whistle is close to a "pure" sine wave, maybe with some white noise.

Not sure I agree with that but I am thinking of the sort of whistle used by referees in sports matches, they have a quite complex waveform.

I would search the web for a whistle sound you like and down load the WAV version of the file or convert it in Audacity into one. Then use Audacity to top and tail it, that is remove the silence at the start and end of the sample. Finally normalise the sound so that you get a peak amplitude at a value of 255, which corresponds to a byte. That way you get the maximum out of the 8 bit output that TMRpcm can offer.

Then you need a simple program on the computer you use Audacity on to print out all the samples in hex followed by a comer and a space. Copy and paste this output into your Arduino and have it set up an array in the program memory. Use that with TMRpcm. I use the processing language to do this.
This technique is described with software in my book Arduino music and projects

You can get an example of what this sounds like from this video, Arduino yes no without extra hardware

Failing all that then get a cheap MP3 player board.