Problem reading two sensors with analogRead()

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
bswift5528
 
Posts: 15
Joined: Tue Dec 09, 2008 6:00 pm

Re: Problem reading two sensors with analogRead()

Post by bswift5528 »

Yeah, I just finished that up now. Works great! Still don't know why the bandgap reference isn't stable, or why the 1.05 was in the original calculation, artificially bringing down the calibrated temperature (at 80F, that 5% difference there gives temps 7.5F lower, matching what I measured above).

Additionally, I was curious as to whether I have to worry about more noise when I read the sensors more frequently in certain applications. The particular application I have in mind is for monitoring the temperature of wort -- ie, proto-beer -- while cooling 10 gallons of it from boiling to 70F with a copper immersion chiller. The chiller that I made does this in under 8 minutes, so the temperature changes *very* rapidly early on, so it's kind of a pain in the ass to use any kind of thermometer setup where you have to write stuff down. Anyway, I tried it (below), and it doesn't seem to be any noisier for short read times than for long.

Still, Sensor 2 seems to be acting up...this time, reading a few deg higher than the other two, and not just being noisy. Has anyone had problems of this nature with a TMP36 before? Thanks again!
temptest2.png
temptest2.png (79.22 KiB) Viewed 9480 times

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Problem reading two sensors with analogRead()

Post by adafruit »

bswift5528 wrote:Yeah, I just finished that up now. Works great! Still don't know why the bandgap reference isn't stable, or why the 1.05 was in the original calculation,
not sure how else we can say that it wasnt stable because it wasnt stable. maybe they didnt want to spend more money on it? regardless, its not in the tutorial anymore because it didnt work well - which means you should probably stop thinking about it :mrgreen:
Still, Sensor 2 seems to be acting up...this time, reading a few deg higher than the other two, and not just being noisy. Has anyone had problems of this nature with a TMP36 before? Thanks again!
electronic temperature sensors are precise to only about 1 or 2 degrees.

User avatar
bswift5528
 
Posts: 15
Joined: Tue Dec 09, 2008 6:00 pm

Re: Problem reading two sensors with analogRead()

Post by bswift5528 »

adafruit wrote:which means you should probably stop thinking about it
Ok, fine... :P
electronic temperature sensors are precise to only about 1 or 2 degrees.
Yeah, I know, but the one seems to be, at times, less accurate than the other two, and at others, less precise than just the 1 or 2 degrees. I'm just trying to learn whether or not this is an issue with just the TMP36 device, or if it's an effect of the interaction somewhere else between all the hardware and firmware...

Ok, now the data's all in. 30,000 reads, 500 ms apart, for the three TMP35 sensors. Not only is Sensor #2 offset for pretty much the whole 4+ hours this was running, but by different amounts at different times, but the measurements were noisy as all hell for a while there! :P
temptest3.png
temptest3.png (99.43 KiB) Viewed 9471 times

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: Problem reading two sensors with analogRead()

Post by fat16lib »

Did you do two reads for each sensor? Do one read then delay and then do the one you keep.

Analog read has a lot of problems. You can often improve your results with oversampling.
http://www.atmel.com/dyn/resources/prod ... oc8003.pdf

here is an example:
http://forums.adafruit.com/viewtopic.ph ... p36#p76594

David Mellis, the key Arduino developer, seems to know about this and has an analog library with options to fix many of these problems.

http://dam.mellis.org/2010/06/sensor_li ... r_arduino/

User avatar
bswift5528
 
Posts: 15
Joined: Tue Dec 09, 2008 6:00 pm

Re: Problem reading two sensors with analogRead()

Post by bswift5528 »

Thanks for all the good advice, fat16lib! I altered my code to include the multi-read averaging, but I'll have to test it out later. Also, want to try out the sleep() function from Mellis soon too!

User avatar
kfw
 
Posts: 10
Joined: Sun Apr 12, 2009 7:29 pm

Re: Problem reading two sensors with analogRead()

Post by kfw »

I just wanted to thank this Forum (and fat16lib in particular) - the trick of adding a delay and repeating an analog read solved my problems exactly!! It was driving me nuts (and no help found on other forums) /K

User avatar
bswift5528
 
Posts: 15
Joined: Tue Dec 09, 2008 6:00 pm

Re: Problem reading two sensors with analogRead()

Post by bswift5528 »

Hooray! I haven't done anything in a while with this project I was mucking around with and have been thinking more and more about it lately. Maybe this weekend! :)

skylen
 
Posts: 56
Joined: Fri Sep 04, 2009 5:54 pm

Re: Problem reading two sensors with analogRead()

Post by skylen »

If I were you, I would absolutely use a digital-output temperature sensor (I²C or SPI interface) instead of an analog voltage-output temperature sensor.

Because the ADC is integrated into the temperature sensor IC on a digital-output sensor, there are no ADC input impedance issues or analog multiplexing issues, and since analog signals are contained only within the sensor's die, noise should not be an issue in most cases. You can easily get digital-output sensors with ±1.0 °C accuracy and down to better than 0.5 °C accuracy. For instance, the Microchip MCP9804-E/MS, I²C interface with ±0.25 °C accuracy (US$1.82 in single unit qty from Mouser).

With the current price and performance of digital temperature sensors, I can't think of a situation where I would choose to use an analog-output temperature sensor IC over a digital-output sensor.

User avatar
bswift5528
 
Posts: 15
Joined: Tue Dec 09, 2008 6:00 pm

Re: Problem reading two sensors with analogRead()

Post by bswift5528 »

I can't think of a situation where I would choose to use an analog-output temperature sensor IC over a digital-output sensor.
Because we're new at this, we're learning, and there is a nice tutorial on it?

DerekMessina
 
Posts: 1
Joined: Wed Nov 23, 2011 1:36 am

Re: Problem reading two sensors with analogRead()

Post by DerekMessina »

I've been having a problem in using analogRead before, but not anymore. Thanks for the tips! Now I'm not experiencing problems anymore.

anders_malmberg
 
Posts: 7
Joined: Sun Feb 12, 2012 9:43 am

Re: Problem reading two sensors with analogRead()

Post by anders_malmberg »

Hi everyone!
This is my first arduino project and im still a beginner but it has been going quite well so far. However I have ran into some problems with my TMP36 GZ (or maybe TMP38 GZ, cant realy tell from the tiny text) sensors. When im using 1 sensor the readout is very accurate, with 2 sensors its a bit nervous, but still not too bad. With three sensors however its rubbish. I have read all the posts from others that has encounter the same problems but still cant get it right.

My goal is to connect 4 sensors, but have only 3 so far. This is my code atm:

Code: Select all

int sensorPin0 = 0;
int sensorPin1 = 1;
int sensorPin2 = 2;
int sensorPin3 = 3;

void setup()
{
  Serial.begin(9600);
}
 
void loop()                     
{
 analogRead(0);
 delay(10);
 int reading0 = analogRead(sensorPin0);
   float voltage0 = reading0 * 5.0 / 1024;
   float tempC0 = (voltage0 - 0.5) * 100; 
   Serial.print("A"); Serial.print(tempC0,0); Serial.print(";");
 delay(10); 
 
 analogRead(1);
 delay(10);
 int reading1 = analogRead(sensorPin1);
   float voltage1 = reading1 * 5.0 / 1024;
   float tempC1 = (voltage1 - 0.5) * 100;
   Serial.print("B"); Serial.print(tempC1,0); Serial.print(";");
 delay(10);
 
 analogRead(2);
 delay(10);
 int reading2 = analogRead(sensorPin2);
  float voltage2 = reading2 * 5.0 / 1024;
  float tempC2 = (voltage2 - 0.5) * 100;
  Serial.print("C"); Serial.print(tempC2,0); Serial.println(";");
 delay(10); 
 
 //int reading3 = analogRead(sensorPin3);   
  //float voltage3 = reading3 * 5.0 / 1024;  
  //float temperatureC3 = (voltage3 - 0.5) * 100 ; 
  //Serial.print("D"); Serial.print(temperatureC3, 0); Serial.println(";");
//delay(10); 

delay(1000);                                     
}
The results is as follow:

A13;B18;C7;
A12;B18;C4;
A11;B17;C5;
A12;B18;C7;
A13;B18;C7;
A12;B18;C2;
A12;B18;C6;

the "B" sensor is about right, but as you can tell the others isnt. (the sensors is fitted at the same lab-board about 2" away from eachothers. I will use the data in a VisualBasic project, thats why I have the A/B/C and ; characters.

I have connected the sensors to the 5.0V output on the board and using the USB as powersource. I tried to use the 3.3V output and use the AREF to get a better reading, but it got even worse.

What am I doing wrong?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Problem reading two sensors with analogRead()

Post by adafruit_support_bill »

Without changing any wiring, if you just read sensor 0 or sensor 2, do they give you 17/18 like sensor 1?

anders_malmberg
 
Posts: 7
Joined: Sun Feb 12, 2012 9:43 am

Re: Problem reading two sensors with analogRead()

Post by anders_malmberg »

adafruit_support wrote:Without changing any wiring, if you just read sensor 0 or sensor 2, do they give you 17/18 like sensor 1?
Hmm that was strange, I was positive that it should have, but its doesnt!
With only one sensor (tried sensor0) it still gives me rubbish. That worked fine before, but that was before I changed the code and rewired the other sensors though.

This is a picture taken with only 2 sensors connected.

Image

anders_malmberg
 
Posts: 7
Joined: Sun Feb 12, 2012 9:43 am

Re: Problem reading two sensors with analogRead()

Post by anders_malmberg »

do I need some external powersupply?
Im using only the USB port atm. I reconnected the first sensor and thats working like it should, but as soon as I connect another it starts to play up.

this is a readout with 2 sensors and the voltage display

A18;0.68 V B12;0.62 V
A18;0.68 V B13;0.63 V
A18;0.68 V B12;0.62 V
A18;0.68 V B11;0.61 V
A18;0.68 V B12;0.62 V
A18;0.68 V B11;0.61 V
A18;0.68 V B12;0.62 V
A18;0.68 V B12;0.62 V
A18;0.68 V B12;0.62 V

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Problem reading two sensors with analogRead()

Post by adafruit_support_bill »

Hmm that was strange, I was positive that it should have, but its doesnt!
Is it stable at least? (i.e. consistently the same error offset?)

Double check all your wiring & keep all your jumpers short.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”