Choosing right resistor for speaker

Cause it won't? 20mA*5V is still only 0.1W, audio transformers are ridiculously expensive and huge, the nominal 250:8ohm transformer that you'd want is rare, and it still might not deal with ac/dc issues.
(Digikey has a 250:8 ohm, 700mW audio transformer. It's primary has a DC resistance of 11 ohms and it costs $22.)

note that you won't ever get 3W with a 5V power supply (maybe with a class D amp?)

100 miliwatts is lots of audio. No junk box?
Paul

Cheap op-amp then!

Of course you can use a transistor, a logic-level FET will work for square wave or a BJT for analogue and have the transistor carry higher voltage than the base.

It is the DC that causes the load problem with current. When the sound is off and the pin is high then you basically have an 8 ohm load on a pin that needs about a 120 ohm load or greater to stay on the safe side of the processors maximum current specification.

[quote="westfw, post:32, topic:900268"]P=IIR
[/quote]
Forum "ate" the star symbols. Should be P=I*I*R, looks like P=I/R. Use backslash before the star to prevent this.

Only if its DC.

No - but why not

as a bridge tied load amplifier (section 8.1)

cause it's for beeps and boops is why

Give your supplier (eBay, Amazon, Aliexpress, etc) a search for PAM8403, which is pretty much a 5Vm 3W Class D Stereo amplifier on a chip that shows up in modules that don't cost much more than a transistor.
Available with and without volume controls...

I agree - a simple and economical solution