Howto make sound with DC motors
| Attachment | Size |
|---|---|
| ardubotl293d.pdf | 46.69 KB |
| Sound.zip | 175.26 KB |
Description:
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);
delayMicroseconds(period_usec/2);
motorDirection (DIR_REVERSE, DIR_REVERSE);
delayMicroseconds(period_usec/2);
}
motorSpeed (0, 0);
}
Here is the schematic:





@ Sat, 2010-03-20 13:41
Works 100% on my Ardweeny bot 2
Firstly Congrates RobotFreak on "Making it" - yeah.
My son was curious and puzzled by it, so he ask me to duplicate it........(OMG i hope this works crossed my cortex)
...... it so happend that there in front of me was a new bot i had freshly built with an ardweeny and two GM motors.......
.... i zapped the code in and hey presto it worked ....... full marks for a speaker-less bot.......
@ Sat, 2010-03-20 13:44
Trend setting........Also works on my "Mooo" set up
@ Thu, 2010-03-18 12:42
Oh, I just got to think of
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!
@ Thu, 2010-03-18 20:38
I don't know if this will
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.@ Fri, 2010-03-19 00:51
Another alternative is to
@ Fri, 2010-03-19 11:00
Nice tip. With the PWM
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.
@ Wed, 2010-03-17 21:13
Made!
@ Wed, 2010-03-17 00:00
I remember that someone
@ Wed, 2010-03-17 10:56
Oh yes, the good old