Controlling a speaker with motor shield?

Is it possible to play some tune in speaker with a motor shield like l293d?
Can I use the same code used to control piezo buzzer?

This is a XY problem. You have a proposed solution to a problem and you are asking if your solution will work without stating the problem.

What do you mean by "control my speaker"?

groundFungus:
This is a XY problem. You have a proposed solution to a problem and you are asking if your solution will work without stating the problem.

Does this mean I can control my speaker with the motor shield or not? Can I use the code of piezo Please tell :frowning: :frowning: :frowning:

Yes you can drive a speaker with a motor controller (square/rectangle waves/pulses only, no "high quality" music).

But no, you can't control a speaker connected to your stereo system.

You'll need two out-of-phase outputs from the Arduino so you can't use tone() unless you add an inverter to one of the inputs.

To drive a speaker with decent audio quality, consider a class D amplifier.

To drive a speaker with decent audio quality, consider a class D amplifier.

But if you're driving the amplifier with the Arduino, you still have only square/rectangular waves. An amplifier does allow the option of a volume control.

The H-bridge motor driver (or a bridge amplifier) can give you 4 times the power (+6dB) with the same power supply voltage. The amplifier jremington linked to is a bridge amplifier. You'll generally get a little more voltage-swing with a motor driver.

For sound quality, the "class" of the amplifier doesn't matter (as long as the amplifier is properly designed & constructed).