Inconsistant results of readadc10


Senior Member
I have the following bit of code:

high EnableSensor
pause 60
setfreq M8
pause 400
readadc10 C.0, Value
pause 200
setfreq K250
low EnableSensor

sertxd ("Value: ",#Value,cr,lf)

and I use it to read Value from a DFROBOT capacitive soil moisture sensor.
I run it 10 times and get (average) Value=281. I actually had a situation where I got Value=281 the first time and Value=2 the rest of the times, but that has disappeared without me doing anything to achieve that(!)
The program then proceeds to run it again at 8 minutes interval with the same physical setup (dont touch anything) and each time I get Value=2.
Voltage is 4.5 V.
Does anyone have an idea?
Best regards

PS. The DFROBOT capacitive soil moisture sensor has 3 connections: GND, Enable sensor and analogue value.


Senior Member

Is that with an X2 or M2 ? Does it still happen if you "comment out" the SETFREQs ?
Why increase to 8 MHz (just) to read the ADC ? As written, I would expect the SERTXD to be at 300 baud ? :confused:

Cheers, Alan.


New Member
What is the voltage across the sensor? Are you dropping voltage to or from it because of corrosion or some sort of current leakage?


Senior Member
Hi AllyCat an Aries,
I am using a Picaxe 14M. I am using SetFreq M8 because I saw a description of how to connect the sensor to Ardino and there they said to use freq 9600.
I am dropping voltage in order to save on batteries.

Below are my measurements. It appears that it helps on the 10 consecutive measurements to use SetFreq M8 (but not on the measurement following the 10 measurements):

SetFreq   No    Value     EnableSensor    Analogue value voltage (when readadc10)
                               V                V
   -      1       563          4.2              2.5
   -     2-10     269          4.2              2.5
   -      1        45          4.2              2.5
   +     1-10     560          4.2              2.5
   +      1         3          4.2              2.5

From the above it appears to be a coding problem, but I have a horrible feeling that I have now for 2 days been overlooking something obvious.


Technical Support
Staff member
We havent used this sensor but capacitive sensors in general often don't work particularly well when hooked up to a computer (via download cable). Have you tried when operating standalone, e.g. displaying values on a LCD instead.


Senior Member
Hi AllyCat , Aries and hippy,
It was a coding error. Somebody had introduced a subroutine that flashed a LED. Well, that somebody was of course me, but it looked so absolutely innocent that I overlooked it.
It was hippy's advice about trying something simple that saved the day.
best regards