Go Down

Topic: Trouble with analogRead for audio volume level (Read 882 times) previous topic - next topic

Raythe54

Hello,

Apologies, newbie here. I'm having trouble implementing analogRead. Here's a chunk of code:

Code: [Select]
playfile(name);
  while (wave.isplaying) {
     volume = 0;
      for (i=0; i<8; i++)
      {
        v2 = analogRead(1);
        delay(5);
      }

   if (v2 > 440)    //440
        {
           pulseWidth = 1800;  //1800
           mouthchange = 1;
        }
           else
        {
           pulseWidth = 800;  //800
           mouthchange = 1;
        } 

 
  digitalWrite(servoPin, HIGH);   // start the pulse
  delayMicroseconds(pulseWidth);  // pulse width
  digitalWrite(servoPin, LOW);    // stop the pulse
  }


I've soldered a link of wire from R7 to Analog In 1 to (hopefully) read the volume in as a voltage change. I'm attempting to follow the following instructable:http://www.instructables.com/id/Talking-Arduino-Halloween-Skeleton/?ALLSTEPS

Any ideas what I'm doing wrong? I've isolated that all the hardware is good - uploaded the sample servo sweep sketch and the servo moves as expected.

Thanks, in advance, for your time.

-Ray

Magician

It's hard to say, have you measure a voltage at analog pin1 with DMM?
If don't have one, you can insert in the code a couple debug lines, Serial.Print(xxx), and print out v2 value just after "for" loop.

Raythe54

Thanks for the reply.

I have metered it at approx. 1.2vdc steady, which is not at all what I would expect for this work. The tutorial implies this voltage would change with the audio level. Perhaps another forum is appropriate.

Thanks for this suggestion.

-Ray

Go Up