I am trying to make a battery powered water sensor similar to this project. I have the basic functionality working fine but it is behaving a little odd and I don't have enough knowledge of electronics to know why.
The setup is basically a voltage divider with one of the resistors variable dependent on the water detected. This voltage is read by an analogue pin. The other ends of the divider I have attached to digital pins, I set one high and one low and alternate them.
What I cannot understand is that when I read with one pin high and the other low I get one value but when I switch to the other pin being high after about a second delay then the voltage is a fair bit different, consistently so. However, if I put the Arduino to sleep for a few seconds then switch polarity and read then the readings are very similar. Any ideas on why this could be?
When keepGoing == true, I get the following values for waterLevelRead from A0:
pin set HIGH
Level 0
Level 1
Level 2
wPin
760
680
525
rPin
720
650
500
When keepGoing == false, I get the following values for waterLevelRead from A0:
pin set HIGH
Level 0
Level 1
Level 2
wPin
766
685
510
rPin
760
680
510
The voltages when the Arduino goes to sleep between each read are very close to expected readings. The readings when there is simply a delay between readings are ok when wPin is set HIGH but consistently lower than expected when rPin is set HIGH.