Analog reading with an empty pin [SOLVED]

Hi there !

I have a problem with an Arduino Nano clone from Elegoo.

My project is a simple water level alarm that goes off when the level gets 10cm above or below the normal.
For that I simply use metal sticks that are wired that way :

  • Voltage input, always in the water
  • Voltage output for low level detection, supposed to be always in the water (current is supposed to pass)
  • Voltage output for high level detection, supposed to not be in the water (current is not supposed to pass)

The problem is, the current can't be more than 0.5mV between the sticks (alive animals in the water...)

So I have to plug the outputs to the analog pins of my arduino.
The problem is, those plugs seem to be always receiving an information ! Even when nothing is plugged, the function analogRead() always read a value around 245 so ~ 1.25V.

Here is my code (in french, sorry...) :

const int SONDE_BAS = 0;
const int SONDE_HAUT = 1;

int alarme = 0;
int niveau_haut = 0;
int niveau_bas = 1;

void setup()
{
  pinMode(SONDE_BAS, INPUT);
  pinMode(SONDE_HAUT, INPUT);
  Serial.begin(115200);
}

void loop()
{
  niveau_haut = analogRead(SONDE_HAUT);
  niveau_bas = analogRead(SONDE_BAS);

  if(niveau_haut != 0)
  {
    alarme = 1;
  }
  if(niveau_bas == 0)
  {
    alarme = 1;
  }

  if(niveau_haut == 0 && niveau_bas != 0)
  {
    alarme = 0;
  }

  Serial.print(F("niveau_haut : "));
  Serial.println(niveau_haut);
  Serial.print(F("niveau_bas : "));
  Serial.println(niveau_bas);
  Serial.print(F("Alarme : "));
  Serial.println(alarme);
  Serial.println("-----------------------");

  delay(150);
}

And the return from the serial :

-----------------------
niveau_haut : 248
niveau_bas : 245
Alarme : 1
-----------------------

Evan though nothing is plugged to the pins...

I tried all the pins and they give approximately the same result...
I don't get it !

Somebody have a solution ?

Thanks in advance !
Nico

(Sorry if I'm not always very clear, English is not my first language...)

Are the pins floating? Did you ground the pins to see if they read 0?

When I use the Analog pins for A:D conversion. I read 2 pins. Say A1 and A2 ( this pin grounded). I then, before doing any math do (A1-A2) to get rid of any 'noise.'

Thanks ! Yes, when the pins are grounded they read 0 !

A1 and A2 ( this pin grounded). I then, before doing any math do (A1-A2) to get rid of any 'noise.'

I don't quite understand what you mean here... if A2 is grounded then it's equal to 0. So A1-A2 = A1. Tell me if I misunderstand.

Try a 100k pulldown resistor from each analog pin to GND.

It works perfectly !!
Thanks a lot !

Solved

sapieus:
The problem is, the current can't be more than 0.5mV between the sticks (alive animals in the water...)

Don't stick electrodes in the water, they WILL corrode and lose their function. Use a proper level switch (float switch) instead, and you not only have a sensor that lasts, there's also no electrical connection to the water.

Your exposed electrodes will also cause problems with sensors such as EC and pH probes, which are common for water quality monitoring (due to ground loops).