Moving a Servo to Sound Signals

18,621

48

21

Intro: Moving a Servo to Sound Signals

Hi my name is cenk,

i show you now, how you can make servo`s move to Audio Signals.

See in this video how it looks like :




Parts You Need :
- Any arduino
- a 1K resistor
- a Servo
- 1 LED
- 4 Jumper Wires
- 3,5 audio jack pinout(like that one from your common headphones for exemple)
- optional a soldering iron or a other method to make a good electric connection

step 1:

Cut one of the jumper wire in two parts.
(i used a allready cuttet one, therefore the different colors in the picture)

step 2:

strip the 3,5 audio jack pinout, until you can see the 3 wires inside :
you shud see, one for Left Side, Right Side and Ground.
You only need one of the L & R
now solder one peace of the cuttet wire to the
end of the resitor, then solder at the same point the resistor & wire to the choosen wire L & R
it shud look like this :
(note on the picture i soldered a nother wire, that was a project for stero, in this tutorial you can ignore the second wire without
resistor).




Step 3:

Connect the resitor to Ground on the Ardurino and the Wire end to Analog 0 Pin. By The way the other side can be pluged into any Sound
Source, your Phone, cd player etc.... in my case its my soundcard.
Connect Ardurino with your pc Open the Ardurino software and Open under File > Examples > 01 Basic > The "AnalogReadSerial" Sketch
and Upload that.
Start the Serial Monitor (Tools > Serial Monitor) and be sure that your SoundSorce is outputting Signals.
If you see in Serial Monitor Chaotic Readings or only a not changing Zero, you make a misstake, your readings are wrong,
if you see readings that gets higher with louder soundsignal and gets to lower numbers at not so loud parts you are right.
that looks a little bit like matrix, you only see a numbur but its realy good to see that this is sound even if you dont hear anything.

Step 4:

Allright Time to connect the Servo use the other 3 jumper wires for that,
the servo hase a Red one , Connect that one to +5v at arduino
a black one, this one goes to ground at the arduino
and a white one connect this one to Pin 9 at the arduino(9 is a PWM PIN Thats needed for a Servo)
take now your led and mount it however on that servo, connect the smaler - Pin of the LED also to Ground of Ardurino
and the + Longer LED pin to Pin 12 at your Ardurino.

Step 5:
Some Codeing...
start a new Skatch
add the code below :
Upload & Have FUn, if you like Vote for me & feel free to show me your projects with this method :) 

/*
  Make a Servo Move to Sound.
   This example code is in the public domain.
   2012 by Cenk Özdemir
*/
// for servo stuff we include the servo library
#include <Servo.h>
// creating a servo object
Servo myservo;

// Some Varuables we need
int ServoPin = 9;
int SoundInPin = A0;
int LedPin = 12;
// the setup routine runs once when you press reset:
void setup() {
  // initialize

    myservo.attach(ServoPin);
     pinMode(SoundInPin, INPUT);
     pinMode(LedPin, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(SoundInPin);
// we Maop a nother value of this for LED that can be a integer betwen 0..255 
  int LEDValue = map(sensorValue,0,512,0,255);
  // We Map it here down to the possible range of servo moovment.
  sensorValue = map(sensorValue,0,512,0,180);
  // note normaly the 512 is 1023 becouse of analog reading shud go so far, but i changed that to get better readings.
myservo.write(90);
// setting the servo into standard position
  int MoveDelayValue = map(sensorValue,0,255,0,sensorValue);

  // maping the same reading a little bit more down to calculate the time your servo gets to make the one Move
if (sensorValue > 33) { // to cut off some static readings only if the reading gets higher then 33 it begings to work
   delay(1);  // a static delay to smooth things out...
// now move the servo to our mapped reading
  myservo.write(sensorValue); 
  // turn led on with the calculated value for it
  analogWrite(LedPin, sensorValue); 
         // and do that move in this delay time
  
  delay(MoveDelayValue); 
} // Done. now we close that part.
   // turn off the led again.
      analogWrite(LedPin, 0); 
      // and this repeats all the time.
}

2 People Made This Project!

Recommendations

  • Plastics Contest

    Plastics Contest
  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge
  • Optics Contest

    Optics Contest

21 Discussions

0
None
ErwinM5

Question 4 weeks ago

How is it that my servo is vibrating ( standard servo 6volt), and the servo is not in the middle (90) I want to make a speech machine, so that the waves of speech come on paper

DSC01782.JPG
0
None
DaveR206

10 months ago

works good with a sound sensor!

0
None
SpecialRobotBuilders

11 months ago

I can't seem to get this to work. Anyone have any tips?

0
None
DavidO66

2 years ago

Hi lowtechliving...I found this circuit diagram and have had some success with it, the capacitor is a 1uF electrolitic and the resistor is 200ohms...i found that the volume input must be quite high in order for it to work...good luck

skull_schematics.jpg
0
None
lowtechliving

2 years ago

Not sure about the right and left so I soldered 2 cables. Tried both to no avail

20160313_16490sm1.jpg
0
None
lowtechliving

2 years ago

I wasn't sure which one was the ground so I tried wires...

20160313_16490sm1.jpg
0
None
lowtechliving

2 years ago

First of all thanks for the tutorial. It is a great idea.

a I am encountering a problem though. A David I am stuck on the reading of the signal a well. The resistor is connected to the ground and I connected the right wire to the A0 pin. I get only 0s.

I am sure the source is outputting sound. I can even listen to the sound if I connect the wire to the earphone that I cut do do this project. There is something that must be wrong. I also tried different sources of sound... Has anyone been able to get this done? Cheers

0
None
DavidO66

2 years ago

I would really like to get this to work as it is what i am looking for, for a project i am building, it's simple but not quite straight forward

1 reply
0
None
lowtechlivingDavidO66

Reply 2 years ago

First of all thanks for the tutorial. It is a great idea.

a I am encountering a problem though. A David I am stuck on the reading of the signal a well. The resistor is connected to the ground and I connected the right wire to the A0 pin. I get only 0s.

I am sure the source is outputting sound. I can even listen to the sound if I connect the wire to the earphone that I cut do do this project. There is something that must be wrong. I also tried different sources of sound... Has anyone been able to get this done? Cheers

0
None
DavidO66

2 years ago

I have had difficulty with this and it hasn't worked, I am at a loss as to why only one wire from the input source is connected as shown and described in the text, I have tried to look closely at the pictures but are of poor quality as is the soldering, it is unclear to me...can any one help me with this, I am also getting continuous 0"s in the serial monitor and apparently this is " you make a misstake, your readings are wrong,", so what do i do to get it rite?

0
None
goldenshuttle

2 years ago

good project and tutorial at same time...thumbs up...one question, if i wanna add a spectrum analyzer of 3 Led bars, each having 5 leds.. i would again map the audio...can the arduino handle them together with the servo ...?

0
None
AndresK1

3 years ago

This is absolutely amazin

0
None
lukeford

3 years ago on Introduction

i would double the amount of servos and turn it into a dancing robot

0
None
lgn631

3 years ago on Introduction

Is there any way to add a speaker on the arduino for the audio to play through? Im making something that cant be connected to a computer

0
None
MarcioWilges

3 years ago on Introduction

I was never any good at programming or working with electricals so moving around all the different wires and components is totally out of the question for me. Leave all this stuff to the stores and electricians to handle thank you very much!

0
None

A simple project with so much potential applications. applaud..great subject

0
None
pcmodder1997

4 years ago

One thing that would make that better is if you replaced the led with a laser