Sound Sensor to Drive Servo

Hello,

I want to use a sound sensor to drive a servo motor for the Jaw of an animatronic. So when sound is detected my 3 Pin sound sensor will detect it ad move the servo to 90 degrees, and when there is o sound it will move the servo to 0 degrees. I was wondering how to program this so its accurate and fast as possible?

Thanks.

Classified123: Hello,

I want to use a sound sensor to drive a servo motor for the Jaw of an animatronic. So when sound is detected my 3 Pin sound sensor will detect it ad move the servo to 90 degrees, and when there is o sound it will move the servo to 0 degrees. I was wondering how to program this so its accurate and fast as possible?

Thanks.

Only you can determine if the program is as accurate and as fast as possible. What does it do now?

Paul

The code doesn't do anything right now. I tried a servo driven clap code (when you clap the servo moves) from the internet but it didn't work as expected so I deleted it. I want to now how to program a code that will allow the servo to move to 90 degrees when sound is detected and move back to 0 degrees when no sound is detected.

Perhaps you expect more that the program was written to do. If you did not try to fix the sample program, why do you think you can do better on your own? I suggest you get the sample program back and determine if it works as programmed and then modify it to fit your expectations.

Have you EVER written a program from scratch that worked as you expected?

Paul

Classified123: The code doesn't do anything right now. I tried a servo driven clap code (when you clap the servo moves) from the internet but it didn't work as expected so I deleted it. I want to now how to program a code that will allow the servo to move to 90 degrees when sound is detected and move back to 0 degrees when no sound is detected.

So your device will detect the sound of a clap. When it does it will move the servo to 90. then move it back to 0 and wait for the next clap?

First of all (and take this as a question, not an insult or something, I don't know your exact application), if you want the jaw to move, I assume the sound it moves to comes from the animatronic itself. So why bother using a microphone, just wire the ADC to the Audio-Out, it is HIGH-Z so it wouldn't have any effect on the signal.

Now, to try to answer your actual question: If you have what I would consider a sound-sensor (so effectively a more sensitive clap sensor), you will just have to write a loop polling the sensor-out and writing the corresponding state to the servo:

while( true )
   servo.write( digitalRead( soundSensor ) ? 90 : 0 );

This is, of course, very inefficient and will only work if all you do is move the mouth or you have a relatively fast main loop. However, I don't know how far you are in your journey through Arduino coding, so I just used the simplest example I could think of. If you want to do it properly, look into interrupts.

Also, please try to give more information next time you ask on this forum. The more you tell us, the better we can understand your situation which means faster and better answers for you.

I hope I could help. Happy Making!

Daniel