The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
Analog input varying too much on temp sensor (LM335A)
After a couple hours I finally got a good reading from my photocell, so I moved on to the temperature sensor. Never thought it would be this difficult!
I'm trying to get a temperature reading from an LM335A sensor (http://www.sparkfun.com/products/9438).
One of the problems is that it requires 5 V, but I don't think thats a problem because it OUTPUTS 10mA/Kelvin, so as long as it doesn't get about 140 degrees, it wont go over 3.3V. Is there a problem with this?
thread. http://forums.netdui...ch__1#entry3556
On to the real problem...reading the value in, it seems to fluctuate a lot. Similar to this
These are 1 second samples:
916 912 940 939 927 928 924 936 911 920 933 936 934 936 937
I'm not exactly sure how to "describe" circuits yet, but here is my try of what I have:
Ground -> Left pin
Center pin -> A0, 1k resistor ->5V
I'm powering via USB on a netduino plus. I currently dont have any other way to power it.
Any suggests, or am I not providing enough information? Thanks for the help.
I even went so far as to get an external ADC (MCP3204) and still couldn't get it to work well. I came to the conclusion that something about the netduino is too noisy, or analog circuits are too hard.
I tend to take several measurements and average them together for pretty much all my temperature sensors. I'm still waiting for native one wire to play around with the DS18B20.
WannaFly,
If you take 100 samples in a row, are they all scattered like that?
Also, have you opened up any of the other analog pins as AnalogInputs? What happens if you open them all up and wire the unused ones to GND?
Chris
Bill: I had seen your thread about a similar problem, I might have to switch to the digital / one wire but was trying to use this as a "simple" example.
GDServer: I'd probably do that in a real application but since it is varying so much i'm afraid the sample will be off also. It gets worse (obviously) when I use ainput.SetRange(0, 3300) to mimic the actual voltage output.
Chris: Yes, they are - I've left it running for 5 minutes and the output looks about the same. I was not using any other analog inputs but tried your suggestion and the output seems to be the same.
It's important to note that when I measure the voltage with my MM it is right on - about 2.96V and doesn't change except when the temp changes. I've also done the same with a photocell and the output seems to vary.
Looks like I might have to try a digital sensor, but this was an easier first step.
If it's worth anything, after doing everything under the sun i could think of (caps, resistors, chokes, inductors) to quiet the power supply, the aref, the supply to the thermistor, and showed it to gray beard ( ) who teaches microcontroller programming at Rutgers, using an oscilloscope, he was surprised at how quiet i got the power, but we still could not eliminate the fluctuations.
Even with just a simple voltage divider -- no thermistor involved. The voltage was solid on the oscilloscope, but the analog readings were wild by as many as 4 bits, occasionally more -- even after averaging 100 readings.
Mine was *way* worse using an external power supply -- even a battery.
Do you know how much current the analog sensor is driving? I wonder if there's a minimum mA rating to get a consistent analog reading... Or if we can enhance the AnalogInput object to enable shorter/longer readings...
I'm not sure how much current is is driving, and I'm not sure exactly how to tell. I used my MM and put it between the ground and ground pin and came up with 51mA but that seems like too much. On sparkfun it says it uses from 400ua to 5mA.
As a test i've taken everything out of my breadboard. I've connected aref, 3.3V and A0 in the same line, and here is the output of A0. I tried this on all 5 analog ports and the output was about the same.
1023
1016
1016
1023
1016
1023
1019
1019
1019
1022
1016
1023
1022
1023
1023
1023
1023
1023
1016
1023
1016
1023
1023
1016
1023
1020
1019
Maybe this is the root cause? Shouldn't it always read 1023 (or 1024?) it its connected to 3.3V? my MM reads 3.29 most of the time and sometimes blips to 3.3 (its a VERY cheap MM though).
Shouldn't it always read 1023 (or 1024?) it its connected to 3.3V? my MM reads 3.29 most of the time and sometimes blips to 3.3 (its a VERY cheap MM though).
If you connect both AREF and A0 to the 3.3V header, you should generally get a consistent reading of "1023" on analoginput #0.
Do you have a "Rev A" or "Rev B" board? Netduino or Netduino Plus? When did you buy it?
If you connect A0 directly to GND, do you get a consistent reading of "0"?
Have you plugged AREF into any voltage higher than 3.3V? Or any of the analog references into a voltage higher than 3.3V?
Please note that the analog-digital converter on the Netduino is 10-bit, but it is not uncommon to lose 1- or 2-bits of accuracy with integrated microcontroller ADCs (for a variance of 2-4 on the 0-1023 scale).
If you connect A0 directly to GND, do you get a consistent reading of "0"?
Mostly zeros, but some 1's and 7's are in the data also.
0
0
0
0
0
0
7
7
0
1
7
0
0
0
7
0
0
0
0
7
0
0
7
7
7
5
0
Have you plugged AREF into any voltage higher than 3.3V? Or any of the analog references into a voltage higher than 3.3V?
I do not believe so.
Please note that the analog-digital converter on the Netduino is 10-bit, but it is not uncommon to lose 1- or 2-bits of accuracy with integrated microcontroller ADCs (for a variance of 2-4 on the 0-1023 scale).
Chris
Thanks for the information, that variance wont be that big of a problem, this is mostly an exercise for learning. But, it sounds like this should not be happening?
WannaFly,
I don't think that's typical, although it's not necessarily out-of-spec. I just connected both 3.3V and GND into A0 on my Netduino Plus, and got pretty consistent readings. GND gave values of 0 or 1, and 3.3V gave values of 1022 and 1023 (flipping back and forth a bit).
It almost seems like there's some fluctation in your power supply...which is odd. When you tested "GND", did you wire the 3.3V header directly to AREF and the A0 header directly to one of the GND headers?
Do you have an oscilloscope by any chance? It would be really interesting to see the voltage output on the 3.3V header (and if it varied a bit, the voltage output on the 5V header--USB from the PC).
Chris
I've been following this thread closely because I have been having trouble with thermistor accuracy for about a month and I am still trying to pinpoint the problem. It is still likely to me my own fault somewhere. But, tonight I was heavy into experimenting to find out what is going on and one of the things I found interesting was when I just measured across a 10K resistor (instead of the thermistor) I was seeing fluctuations (see below). But, I am not able to reproduce WannaFly's values when A0 is tied to GND or AREF. I get very consistent 0's or 1023 respectively. I also tried this on a board (rev. A) which I also bought off of Amazon and saw the same, consistent values.
WannaFly, what is your netduino sitting on? Are you using your rubber feet?
Does anyone know how to calculate what value you should see when given a certain resistance on an Analog Input.
-Valkyrie-MT
10K resistor on A0 with 3.3V AREF:
RAW Analog: 519
RAW Analog: 515
RAW Analog: 514
RAW Analog: 512
RAW Analog: 516 RAW Analog: 542
RAW Analog: 543
RAW Analog: 516
RAW Analog: 516
RAW Analog: 516
RAW Analog: 515
RAW Analog: 512
RAW Analog: 514
RAW Analog: 515 RAW Analog: 543
RAW Analog: 516
RAW Analog: 512
RAW Analog: 515 RAW Analog: 543
RAW Analog: 512
RAW Analog: 527
Chris: Yes it was connected directly to the headers. 3V3 -> ARef; GND -> A0.
I do not have an oscilloscope.
Valkyrie-MT: I am using the rubber feet and always have it sitting on top of the black anti static bag it came in.
I think I might've found the source of the problem. If I unplug my network cable, i get VERY consistent 0's and 1023's. Chris: Can you try that? With or without a network cable plugged in?
So, I rebuilt the temperature circuit, without a network cabled plugged in i get very consistent readings. This is good news!
Also, Might be a separate issue: If I plug in a network cable to the device while debugging visual studio seems to lock up.
Those are still pretty stable readings overall, but I wonder if there's a grounding/shielding issue with some network cables (and perhaps bursts of network traffic causing some fluctuation in the ADC/AREF readings)...
Chris
Those are still pretty stable readings overall, but I wonder if there's a grounding/shielding issue with some network cables (and perhaps bursts of network traffic causing some fluctuation in the ADC/AREF readings)...
Chris
So what was the final solution to reducing the analog voltage reading variation? I am using the LM335 temp sensore and do not get a stable reading!
So what was the final solution to reducing the analog voltage reading variation? I am using the LM335 temp sensore and do not get a stable reading!
Question, how are you powering the NetDuino?
If via USB the drive voltage may be varying during your test sequence. I would suggest a repeat of the messurement with feeding 9 volts to the DC Jack.
So what was the final solution to reducing the analog voltage reading variation? I am using the LM335 temp sensore and do not get a stable reading!
I was doing a moving average of 20 points (each point collected every second) before I noticed the variation. But to compensate for this a little better, I switched to a moving Median, so I bubble sort the latest 21 points and just take the middle (aka. median) because I have not seen a case where most of the points in a 21 point span look bad... I hope that makes sense.
If via USB the drive voltage may be varying during your test sequence. I would suggest a repeat of the messurement with feeding 9 volts to the DC Jack.
I am powering by USB for my testing, so I plugged in a 9V DC adapter and the variation is still present with the 9V adapter. I wrote the values to the SD card and here is a sample below... A0 connected to ground (column 1) and A1 connected to 3.3V (column 2):
I'm seeing the same kinds of fluctuation on the TMP36 analog temperature sensor as shown on this post.
The reading fluctuate wildly depending on what power source you're using. If I use the rear USB ports or the AC adapter I get much more stable readings (within ~1 degree). However, I agree with the post above that if I take the median of the last 20-40 readings I get a pretty consistent value between all power sources.