Go Down

Topic: Analog reading with an empty pin [SOLVED] (Read 279 times) previous topic - next topic

sapieus

Dec 14, 2018, 12:59 pm Last Edit: Dec 14, 2018, 11:50 pm by sapieus
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...) :
Code: [Select]
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 :
Code: [Select]
-----------------------
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...)

Idahowalker

#1
Dec 14, 2018, 01:50 pm Last Edit: Dec 14, 2018, 01:52 pm by Idahowalker
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.'

sapieus

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

Quote
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.

outsider

#3
Dec 14, 2018, 09:19 pm Last Edit: Dec 14, 2018, 09:29 pm by outsider
Try a 100k pulldown resistor from each analog pin to GND.

sapieus

It works perfectly !!
Thanks a lot !

Solved

wvmarle

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).
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up