I am trying to get audio input from an external source.
It's a simple setup, Guitar mono input jack + goes to A0 to read the input and the - to Ground.
I have had this working before but It's been a few iterations back and forth. The end goal is to control a servo based on the audio data.
The serial monitor now only displays values around 200 - 400 and the data is the same when the input is unplugged. IE it's not reading. Any help is appreciated
int sensorPin = A0; // Audio input
void setup() {
// put your setup code here, to run once:
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int noiseLevel = analogRead(sensorPin);
Serial.print("Volume is :");
Serial.println(noiseLevel);
delay(200);
}
You didn't say what the audio input source is.
But if you trying to sense audio directly from the guitar pickup those signals are low. Also they will swing negative to zero which the MCU will not respond to.
I think the arduino reads from 0 to 5 volts. If the output gives millivolts, then you need to amplify that signal.
and if you give more than 5 volts it can be a problem...
Ah, forgot about that. Copy and pasted from another time. Changed to “” instead of ‘’ and same issue. I updated that in the original post due to my error of pasting wrong code.
I also updated with image of wiring and the Serial monitor results
sound is coming from PC speaker 3.5mm jack output to the guitar lead input
I found it a bit difficult to understand this statement. Are you saying A0 is connected directly the loudspeaker? This will destroy the MCU - analogue inputs have clamping diodes the negative input swings will conduct down to zero volts.
At least use a series limiting resistor, 10K or so.
What is the peak signal level going into A0?
It sounds like you are wanting a peek level detector? On the input you just need a series diode and capacitor + resistor to 0V.
Just need to move a puppet mouth (servo) to the input provided..ie Recorded voice mp3 (no music)
This will later get repaced with live input to the PC via microphone (again output via the soundcard into the arduino)
Ensure that the computer isn't muted via hardware. Press any external mute buttons, confirm that the speakers are turned on, and turn the volume all the way up. Test by playing a song or using the Sound control panel (click the Sounds tab, select Asterisk, and click Test). If that doesn't work, check Windows Upsers
thanks, gave that a shot to confirm, even when the output is removed from the pc (confirmed it's making noise) I'm getting the same readings. I would expect them to be 0 when disconnected.
A floating analogue input because of it's high impedance will pickup noise especially mains hum, so you won't see zeros. Disconnect jack plug and connect A0 input to ground, you should see zero readings then.
As another test you could connect a battery, less than 5V, to the input. The readings will be the battery voltage/5 * 1023. So for 1.5V battery readings will be approx 1.5/5 * 1023 = 307.
If that looks OK then the issue is with the input signal. Make sure the + battery terminal connects to the A0, otherwise the MCU will break. As mentioned it's best to connect a series resistor when playing with analogue inputs.
The approach will work, it may need a signal amplifier and a few components on the input. Report back I can send you a simple diagram if you want.
Can't silence the puppets!
Thank you, threw in a 10k resistor between A0 and the input
Testing results
A0 to ground - Volume 0 : Great
Testing with 2.5v on PSU via resistor to A0
Got 327 / 328 seems pretty close with what you said.
So in theory the input / cable is the issue. Problem is I have used multiple cables.
The output jack from the speakers on my pc works fine for headphones, could it seriously be that causing the issues?
If you want to be certain the lead is OK, you could just unplug it from the PC end and repeat the previous two tests by zeroing and connecting the battery (via the 10K) at the 3.5mm jack. See you get the same results.
If that checks out what happens to the readings when you turn the PC volume down - do the readings also go down?
I'm also wondering if there is enough signal coming from the sound card, typical line output levels could be anywhere from 0.5V peak to max of 1.5V or so peak.
Start by checking the lead then turn the PC volume down to zero see if the readings reduce to near zero, if they don't there may be a ground loop between your arduino power supply and the PC. If so try putting a capacitor in series with the input to A0 this will block any DC voltage between your arduino and the PC but pass the audio signal through.
Tested on a laptop headphone out plug, same thing random numbers, same removing the plug.
Good to replicate results on another audio source, bad because it means I still have to troubleshoot.
Tested by putting 1.5v + and - on one end of the 3.5mm jack, 10k resister to A0 and - to earth.
Started giving me the expected 327 / 328 again. So I guess I can rule the lead out.
As for the capacitor, do you know what size etc, im pretty new to the smaller things?
I do have a 2 Channel 3W PAM8403 Audio Super Mini Digital Amplifier I tried earlier to see if the signal was too low and I got the same kind of results.
I have now created the circuit from the thread and using my same original code (below to save the scroll) I am getting 0 with audio input attached or not.
I'm assuming it will be my wiring or the use of incorrect components.