Hi,
the analog inputs on the arduino only like positive voltages (between 0 volt and 5 Volt / Analog Reference Voltage), see http://www.arduino.cc/en/Reference/AnalogRead.
Filtering out DC will not solve your problem.
It does seem like your amplitude is quite low.
Probably your soundcard is more sensitive.
Although I'm definitely not an electronics expert, I would suggest at the very least checking the average output voltage.
That should be approximately 2.5Volts, giving you a nice average of 512 when using analogRead.
If it is below, you can set the analog reference voltage to something more usefull (your peak voltage), see analogReference() - Arduino Reference for more info.
You could also try to give the signal the proper DC offset and amplitude, but that would require electronics knowledge which I don't have...
If you want to "filter" dc in software, that's also possible.
I used something similair to the code below to deal with a varying offset (not the actual code, and not tested, but this should work without much changes).
What this does is sample the last 4 readings, and check if the current reading deviates from this average by a certain threshold.
The code could also be used with more samples (up to 32 without changing all the integers to longs / unsigned ints).
For me that worked fine, but it depends a lot on the amplitude of your signal.
Hope this helps...
Regards Dennis
const int analogPin = 9;
const int analogThreshold = 40;
bool analogTriggered = false;
void setup() {
pinMode(analogPin, INPUT);
}
void loop () {
analogWorker();
if (analogTriggered) {
// Trigger code
}
}
void analogWorker() {
static int analogAvg = 512;
static int analogValues[] = { 512, 512, 512, 512 }; // Average last 4 values
static int analogCounter = 0;
static int analogTotal = 2048; // Fill with total of analogValues[] (4x512)
static int readOut;
readOut = analogRead(analogPin);
analogTotal -= analogValues[analogCounter];
analogValues[analogCounter] = readOut;
analogTotal += readOut;
analogAvg = analogTotal >> 2; // Fast division by 4
analogTriggered =
((readOut>analogAvg+analogThreshold) ||
(readOut<analogAvg-analogThreshold));
analogCounter = (analogCounter+1) % 4; // Cycle through values
}