Analog Counter

I'm currently working on a project that involves building a sensor to detect eels swimming down a pipe. We chose to detect the conductivity of the fish. So far we have a sine wave oscillator, going into an inverter to produce two AC sources in antiphase. These are fed into two outer electrodes, and we then measure the voltage across the inner electrode. Obviously when they are in antiphase and both are passing through the same volume of water, there will be no voltage. When an eel swims past one of the electrodes there should be a voltage increase that we can detect.

This has worked fine on an oscilloscope when we've tested it. However, I'm having some difficulty with programming an arduino to detect the eels and to count them. This is my first project involving arduino and so I have very little experience to work on. If someone could point me in the right direction it would be really helpful.

This is the sketch I currently have (I'm reasonably sure that it won't work, just not sure what will.):

int val = 0;
int old_val = 0;
int state = 0;
int Eel_Count = 0;

void setup() {
 Serial.begin(9600);
}

void loop() {
 val = analogRead(A0);
 if ((val > 20) && (old_val < 20)){
  state = 1 - state;
 }
 old_val = val;
 if (state == 1) {
  Eel_Count = 1 + Eel_Count;
  Serial.println(Eel_Count);
 }
}

Edit: I forgot to mention that the eels send two pulses when they swim past the sensor.

This has worked fine on an oscilloscope when we've tested it.

But, you are not going to show us that output?

We chose to detect the conductivity of the fish. So far we have a sine wave oscillator, going into an inverter to produce two AC sources in antiphase. These are fed into two outer electrodes, and we then measure the voltage across the inner electrode.

The AC voltage, going from positive some unstated value to negative some unstated value? And, you are feeding this negative unstated into the Arduino?

When you get a new one, don't do that!

I'm reasonably sure that it won't work, just not sure what will.

You have not defined what that sketch does. You have not defined what you expect that sketch to do. You have not defined what you mean by work, or stated what does not work.

 val = analogRead(A0);
 if ((val > 20) && (old_val < 20)){

Are you hoping that the readings are in this range, or do you KNOW? If so, how?

  Eel_Count = 1 + Eel_Count;

Have you taken a C=1+C course? How about a C++ course?

Post two scope traces, one showing a few seconds without the eels and one of an eel passing by.

Mark

In order for the Arduino to deal with it, you need to convert the signal from the center electrode into the range 0 - 5V relative to the Arduino ground. This would probably require some sort of signal conditioning circuit between the electrode and the Arduino.