Let's Make Robots!

Howto make sound with DC motors

Howto make sound without any sound transducer using only the DC motors of your robot.
ardubotl293d.pdf46.69 KB
Sound.zip175.26 KB


I  am just start to play around with the new Arduino Tone library, when I realize that I have no sound transducer laying around here. Than I remember an old hack that someone did with the Asuro robot (many thanks to ArexxHank and stochri). Making sound with the DC motors. So I grab one of my actual robots, the Ardubot and began to port the sound function to my current setup. Mixed together with the examples from the Tone library and here is the result. 

How it works:

The trick is quite simple and should be work with every robot that uses a normal H-Bridge as motor driver. PWM is not needed here, just the direction pins to move the motors forward and backward. If you use PWM for your H-bridge, you can additionally control the amplitude of the generated sound. You need to switch the motors between forward and backward with the desired frequency. The motor will not start running, just begin beeping at this frequency. The frequency range is not as wide than a speaker, but it's ok.

Here is the playSound function:

void playSound(uint16_t freq, uint16_t duration_msec, uint8_t  amplitude)
  uint32_t n,k,period_usec,duration_usec;

  period_usec = 1000000L / freq;
  duration_usec = 1000 * (uint32_t) duration_msec;
  k = duration_usec / period_usec;

  motorSpeed (amplitude, amplitude);

  for (n = 0; n < k; n++)
    motorDirection (DIR_FORWARD, DIR_FORWARD);
    motorDirection (DIR_REVERSE, DIR_REVERSE);
  motorSpeed (0, 0);

Here is the schematic:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
I remember that someone actually made the taperecorder ('s motors) play tunes on the Commodore 64! :)
Oh yes, the good old computer stone age. I think a lot of hacks for this old machines may work with actual robot hardware. Worth to look at it, before these knowledge is lost forever in the deap space of the WWW.

Oh, I just got to think of this; I actually controlled a servo and a motor on same "channel" on bernhard The Cuplifter.

The servo did not mind if the signal was just on or off, and the motor did not mind if it was getting a small pulse. It may have made a sound though, I cannot remember, and they always makes all sorts of noise.

Point is; You might be able to drive AND play, if you just let the state be ON after last PWM. if you do it on both motors it could be stereo and harmonies, while driving around. Awsome!

I don't  know if this will work, to drive AND play. Should give it a try.

Just working on a stereo version, but without success at the moment. I remember another sound effect with the motors of the Asuro. When you hold your hand above it it begins to make sound like a steam locomotive. But I don't have the sourcecode for this, only a hex file.
Another alternative is to drive the motors with PWM, that way you can adjust the PWM frequency to change the pitch of the sound, and change the PWM duty cycle to change the motor's speed. As long as the PWM duty cycle never reaches 0% or 100% the sound will still work. In the special case where you don't want the motors to move at all when a sound is made you can use an alternative routine like the one you already have that alternates the drive direction.

Nice tip. With the PWM signal I could make some kind of DDS to build a signal generator.  The motors won't run as both direction pins are HIGH or LOW.

I've been just begin reading this great Arduino sound tutorials that gives me lot of new inspirations. Interesting stuff anyway.