I have a small metallic needle that is connected to a box that is moving towards a liquid container. The box is halfway inside the liquid so the needle is connected to the upper part that is slowly submerging in the liquid.
I need to know exactly when the tip of the needle touches the liquid.
I used an arduino nano with this code:
I connected pin D2 to the needle and the ground was in the liquid, that way when the needle would touch the liquid the circuit would close and i would get a voltage reading.
The problem is that because the box is submerged, i cant have a reliable enough reading in the analog pin.
I was thinking of maybe trying to calculate resistance instead of voltage but im not sure this will work.
I hope i explained myself well enough, if not let me know
Thank you
EDIT: Pictures and a better explanation further down
OK so reading the analogue port quickly like you are doing in your code by firstly using it in serial print and the by assigning it to a variable will give spurious results due to the settling time of the ADC.
if the box is like a jar mouth down (needle upper side, in the bottom of the jar) then when you submerge it, it will trap an air bubble and the needle will remain dry even when box is submerged. It needs an air escape hole in the bottom
you say you use D2 as needle pin, yet you print only analogRead(A0) which is another pin.
if A0 is the input pin, then is better to set its mode to INPUT_PULLUP too in setup()
no need to analogRead() to sensorValue twice, read it first in sensorValue, then println the sensorValue
Use delay(200) in loop for the eye being able to read the serial output.
I realise I didnt explain myself well enough so ill try to remedy that.
arduarn:
A picture (or drawing) speaks a thousand words...
This is true so first of all ill upload pictures that will better explain what i mean.
In the first picture you can see a model of what im designing. The "box" in question is the shaft that is in the liquid (blue line), and the needle is the arrow connected to the shaft.
In the second picture you can see a schematic of the arduino connections that im using.
Paul_KD7HB:
I guess the liquid is conductive. You didn't disclose that part. Is it liquid mercury? Or salt water or what?
Paul
The liquid is a plastic solution, it is conductive but barely. i checked the resistance and it gave me around 2-3 mega ohm. good enough to sense 5v
blimpyway:
if the box is like a jar mouth down (needle upper side, in the bottom of the jar) then when you submerge it, it will trap an air bubble and the needle will remain dry even when box is submerged. It needs an air escape hole in the bottom
this isnt the case so no bubble unfortunately
blimpyway:
you say you use D2 as needle pin, yet you print only analogRead(A0) which is another pin.
if A0 is the input pin, then is better to set its mode to INPUT_PULLUP too in setup()
no need to analogRead() to sensorValue twice, read it first in sensorValue, then println the sensorValue
Use delay(200) in loop for the eye being able to read the serial output.
I did this to get a better reading on the voltage, as you can see in the schematic im connecting D2 to A0 to read the voltage from 0-1023 and not 1-0.
So the problem that I am having is that instead of getting a reading from when the needle touches the liquid I constantly get a reading of voltage because the "box" is conductive and grounded, which means the current goes through the "box" instead of through the needle so i cant get a reliable reading.
This will influence the reading. If you have the D2 as either an input with some sort of pull up or down or as an output set to HIGH or LOW. In your code you are setting the D2 as an input with the pull up resister enabled. this will pull the D2 input (and the A0 input since they are connected) to Vcc. this will cause your constant reading.
What you need it to have NOTHING else except the needle connected to the A0 input. pass a voltage through the liquid and test for that.
So from your drawing the liquid needs to be connected to +voltage (5)
The Needle needs to be connected to A0 AND NOTHING ELSE
The D2 pin is not needed
Plastic solution? That's interesting. Plastics are not exactly soluble, most of them have only one or two good solvents. What's the composition of your solution?
shayvasa:
So the problem that I am having is that instead of getting a reading from when the needle touches the liquid I constantly get a reading of voltage because the "box" is conductive and grounded, which means the current goes through the "box" instead of through the needle so i cant get a reliable reading.
The simple solution to this is to not make electric contact between the needle and the box. This though is so darned obvious that I must wonder what is stopping you from doing just that.
The larger problem that I see is the conductivity itself. You say "2-3 MΩ". Normally conductivity of a liquid is expressed in S/m, the reciprocal of resistance. This resistance is of course highly dependent on the distance the current has to flow.
But lets assume it's 2MΩ indeed. The container is grounded, you'd need a pull-up resistor of some 200k between needle and Vcc to have a good reading. Preferably larger; but you may get problem with noise. If that's an issue, add a small cap (1 nF or so) in parallel to that pull-up resistor. Larger makes for better noise immunity; smaller gives faster response when the needle touches the surface.