3
\$\begingroup\$

I need to connect a 3.5-mm stereo jack to atmega8 microcontroller, and to lit an led if any music is played in the stereo device. Could anyone tell me about how to connect the 3.5-mm jack to the microcontroller?

I dont have any idea on electronics. So any help on the circuit will be appreciated.

\$\endgroup\$
5
\$\begingroup\$

Here is a video of exactly what you want (I think,) Arduino Tutorial: Led Audio Meter via HeadhPhones

If you just want to know when sound is there, not actually process the sound, then all you need to do is use an ADC pin.

ADC is just an analog to digital converter, you can learn more about that here. The resistors in the picture below are used as a voltage divider to prevent >5volts from getting to the MCU. You may not need them at all since according to this the voltage shouldn't get that high.

You could wire it up like this, except the input voltage would be the stereo wire + and ground (if it's stereo you will have a left + and right +, you can hook them together if you don't care about the sound, if you do care about the sound then use one pin for left and one for right.) enter image description here

Here is a link to the whole setup: http://arduino.cc/forum/index.php/topic,27223.0.html

\$\endgroup\$
  • 2
    \$\begingroup\$ You should not "hook [left and right] together" since they are independently driven and you will be shorting the output drivers when L/R signals differ. If you want to mix them, use some series resistance to measure the common mode signal. \$\endgroup\$ – shuckc Nov 27 '12 at 12:37
2
\$\begingroup\$

Since you don't have an idea on electronic, this may be overkill. Just use a simple LM3915 chip for a easier VU meter.

Here is a simple code for an arduino VU meter. You can use any amount of LED's, just trim the code (lastLED)

int sound[4];
int soundav;
const int inputPIN =8; //audio input pin, gnd other end of 3.5mm jack
const int firstLED= 34; //first output pin for leds
const int lastLED = 53; //last output pin for leds
int leds;
int x;
int y;

void setup ()
{
pinMode (inputPIN, INPUT); // put input pin in input state
for (int a=firstLED; a <=lastLED; a++){ // loop output state
pinMode(a, OUTPUT);
}
leds = (firstLED + lastLED) +1; //total leds + 1 for off
}

void loop ()
{
for (int num=0; num < 4; num++) {
sound[num]= analogRead (inputPIN);
if(num==3) {
soundav=(sound[0]+sound[1]+sound[2]+sound[3])/4; // average level
x = map(soundav, 1, 255, 0,leds); // 0 to 20 sound levels
y = firstLED + x; //correct pin required
for (int b= firstLED; b < y; b++) { //loops all leds from firstLED to sound level
digitalWrite(b,HIGH);ll
}
for (int c = y; c <= lastLED ; c++) { //loops all leds from lastLED to sound level
digitalWrite(c,LOW);
}

Good luck.

\$\endgroup\$
  • \$\begingroup\$ How about a schematic associated with that code? \$\endgroup\$ – m.Alin Nov 27 '12 at 7:42
  • \$\begingroup\$ I'm not that much troubled with coding. My problem is with connecting the intput pin with the 3.5 jack. \$\endgroup\$ – inventive Nov 27 '12 at 10:37
  • \$\begingroup\$ Among 3 pins of stereo jack, what all connections should be made with uC \$\endgroup\$ – inventive Nov 27 '12 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.