Pages: [1]   Go Down
Author Topic: Trouble with analogRead for audio volume level  (Read 825 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

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

Code:
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
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2556
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: