Audio cable as an input on arduino

Hello guys, I'm looking at the options of the problem I am dealing with. I've got a few objects devices from the market that when touched change colour and give out a sound. I do plan to add a led strip that is always one colour unless the object it touched and when the sound goes off I want the led strips to change a colour till the sound stops.
On the back of the object I have an aux output for the speaker. If I would add a 3.5mm splitter there and add an audio cable with one of the ends cut off. Use the red wire as an input to arduino or a pcb board + black to common ground and then use red as an input value. So let say when the object is touched I have a signal coming in and if its = 1 ( sound is on) the arduino code changes the led strip colour, but when the sound stops ( value goes back to 0) led strip changes to standard colour. Driving the led strip is not a problem. The problem is how to get the state of touch as a value to my arduino. So my question is, would this idea work. If not what can you suggest in this situation to achieve what I want.

Thank you very much, I appreciate every response.

Audio is not digital. So you should consider working with the analog inputs, not digital inputs. Look up the analogRead() function.

You want this sort of circuit to connect the Audio output to your Arduino analog input. It is called an envelope follower and will give you the peak voltage of any sound signal.

Envelope follower.jpg

Envelope follower.jpg

Grumpy_Mike:
You want this sort of circuit to connect the Audio output to your Arduino analog input. It is called an envelope follower and will give you the peak voltage of any sound signal.

Envelope follower.jpg

So you have a 100k resistor + a cap connected to the red wire here and a comon ground with arduino, but my question is about the symbol after cap. Is that ground? Should I run the current through the cap and the resistor and then to arduino. Or should I have a red wire runing straight to arduino while taking a separate connection from it running it through the resistor and cap and then getting it back to the same red line? Sorry not sure how to read the circuit here.

The audio signal first sees a diode, which only allows current one way. The voltage on the RC
acts as a store of charge that drains away at a given rate when not being replenished from pulses
from the audio input. Thus the voltage seen by the arduino sort of follows the envelope of the audio
signal. It might be wise to add 10 resistor between Arduino pin and the RC/diode circuit to protect
against very strong signals (this will not affect function at all as the Arduino input only measures
voltage).

Is that ground?

Yes.
All grounds should be common, Arduino, audio and that symbol. The order does not matter.

So I have built this circuit, but whenever I play something from my loptop via the jack, nothing shows up on the simple voltage code to read the voltage. Tho when I touch the jack with 3v the voltage read showd about 2.9. Any suggestions? Only thing I want to do is to know is sound is there.

Have you got all the grounds connected together?
The circuit requires that your audio signal is greater than 0.7V peak in order for the diode to conduct. Do you know what audio signal you have?

Grumpy_Mike:
Have you got all the grounds connected together?
The circuit requires that your audio signal is greater than 0.7V peak in order for the diode to conduct. Do you know what audio signal you have?

Yes I have a common ground from my jack, arduino and cap. I don't know my audio signal. Is dont have a tester on me now.
Here is the picture of the circuit with audio jack and a test with a battery. When Im using battery Voltage is being there. But when Im doing the same with jack - not. So I suppose the problem here is with audio signal.

I don't think you want an LED here. Yes, it is a diode. Note above it was said your audio signal needed to be greater than 0.7V? That's assuming a different kind of diode. LEDs will probably be a couple of volts.

Is that resistor 100K? I am surprised the LED is so bright if it is. The current has to go through your LED resistor and that 100K to make the circuit.

You could try this circuit, it is not as good but might work on smaller signals. With no audio you will get a reading of around 512, with audio you will get a reading above and below this.
Audio Bias.jpg

@ outofoptions - I think you are right - I don’t see a diode in the circuit. An LED will not cut it here as you will need an audio signal in excess of 2.3V for that to work.

outofoptions:
I don't think you want an LED here. Yes, it is a diode. Note above it was said your audio signal needed to be greater than 0.7V? That's assuming a different kind of diode. LEDs will probably be a couple of volts.

Would a 1N4001G (glass passivated rectifier..)or 1N4001S (silicon rectifier) do the job? Did not think that audio signal is so weak.

Yes those would be better.

Did not think that audio signal is so weak.

A standard audio signal is about 1V peak to peak.

Envelope follower.jpg

Grumpy_Mike:
Yes those would be better.
A standard audio signal is about 1V peak to peak.

Grumpy_Mike:
Yes those would be better.
A standard audio signal is about 1V peak to peak.

So yea, I have this circuit connected.
Envelope follower.jpg

Blue - input from the jack. Orange - analog input. Black - grounds, grey - ground of the jack. 100k resistor and 0.22 uf cap. And a small diode.

The thing is that I do get anlog read of 0 most of the time, sometimes it does jump to 1 - 4, but comes back to 0 really quickly. Volume is at max. Any ideas how to fix this?

Well I think you need an operational amplifier between your audio source and the diode to boost the signal. I would go for a times 50 gain.

Have a look at this link to see how they work. How does an op amp work? How do I use an op amp? — Part 1

Grumpy_Mike:
Well I think you need an operational amplifier between your audio source and the diode to boost the signal. I would go for a times 50 gain.

Have a look at this link to see how they work. http://chrisgammell.com/how-does-an-op-amp-work-part-1/

Ok, so as far as I understand I would need an inverted op amp circuit before the diode. Idid looked up some sample circuits, and as far as I understand this would give me about 10 times of gain. Am I on the right way?

Yes on the right track. Only do not use a 741, these are very very old devices and they need a large voltage power supply. Use something more modern that can run off a single rail 5V that you can get from your Arduino. Also you need a rail to rail op-amp, that is one who's output can range close to the power supply voltages.

The gain is set by the ratio of those two resistors, so make R2 47K to start with. Also pin 3 must be connected to the mid point voltage, so connect a 10K from that pin to +5V and another one from that pin to ground. Finally connect Vin to your audio output through a capacitor, same sort of value as you have in the envelope follower.

Grumpy_Mike:
Yes on the right track. Only do not use a 741, these are very very old devices and they need a large voltage power supply. Use something more modern that can run off a single rail 5V that you can get from your Arduino. Also you need a rail to rail op-amp, that is one who's output can range close to the power supply voltages.

The gain is set by the ratio of those two resistors, so make R2 47K to start with. Also pin 3 must be connected to the mid point voltage, so connect a 10K from that pin to +5V and another one from that pin to ground. Finally connect Vin to your audio output through a capacitor, same sort of value as you have in the envelope follower.

So I think LM358 would do the job, its a rail to rail and can run on psu from 3v to 32v, am I correct?

Yes that looks good. :slight_smile:

Grumpy_Mike:
Yes that looks good. :slight_smile:

Once again I’m facing problems with values, with this circuit I get values of about ~600 even when no sound played, when the sound is played I dont get any changes. (Still goes about 600)

I do add fritzing for easier debuging, and other details.

LM358 pinout

Real world picture…

Any suggestions on the situation?