Temperature Sensor Readings Off By 10 degrees?

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jdlev
 
Posts: 4
Joined: Sun Aug 03, 2014 2:21 pm

Temperature Sensor Readings Off By 10 degrees?

Post by jdlev »

I'm new to arduino, and have been working on some of the tutorial projects. I tried the 3 pronged tmp36 temperature sensor, and the thing is reading 10-20 degrees low. Simple setup - ground, sensor to A0, and tried the 5v and 3.3v connections. The sensor posts like it should, but it's saying the temp in my house is about 60 degrees. While I would love for that to be the case, it's actually somewhere between 75-80 in here right now.

Any ideas what I could be doing wrong to be so far off with my temp readings, or do I just have a bad sensor?

User avatar
Franklin97355
 
Posts: 23939
Joined: Mon Apr 21, 2008 2:33 pm

Re: Temperature Sensor Readings Off By 10 degrees?

Post by Franklin97355 »

Could you post your code and a description or drawing of your connections between it all?
Please use the code button "</>" when submitting code as shown below.
Could you post clear pictures of your board and the connections to it?
Attachments
Code Button.jpg
Code Button.jpg (4.49 KiB) Viewed 275 times

User avatar
berko
 
Posts: 67
Joined: Sat Aug 04, 2012 6:44 pm

Re: Temperature Sensor Readings Off By 10 degrees?

Post by berko »

i am having a similar issue but mine is running hot. it is saying it is ~90 degrees in here but i can tell you for sure it is not. house's a/c is set to 72 so thinking it should be somewhere between 70 and 74.
i am using a tmp36 that i purchased from adafruit.
simple wiring as described in the first part of the tutorial on learn.adafruit.
3.3 to right most pin (with the rounded part facing me), middle pin to A0, left pin to ground.

code mostly from the tutorial but with spark core code thrown in.:

Code: Select all

double temperature = 0;
char resultstr[64];

void setup()
{
  Spark.variable("temperature", &temperature, DOUBLE);
  Spark.variable("result", &resultstr, STRING); 
  pinMode(A0, INPUT);
}

void loop()
{
    double voltage = analogRead(A0) *  (3300/1024);
     voltage /= 1024; 
 
    double temperatureC = (voltage - 0.5) * 100;
    temperature = (temperatureC * 9.0 / 5.0) + 32.0;
    sprintf(resultstr, "{\"temperature\":%f}", temperature); 
    delay(1000);
}
i have tried changing the line
double voltage = analogRead(A0) * (3300/1024);

to

double voltage = analogRead(A0) * 3.3;
that made things even hotter in here!

ideas?

if you think it is the spark core that is causing the issue i can try it on an uno.
but would to know if it is the code first.

i have also grabbed the value from both the temperature variable and the temperatureC variable and things are equally off.

thanks,
jon

User avatar
egutting
 
Posts: 297
Joined: Wed Nov 14, 2012 12:57 am

Re: Temperature Sensor Readings Off By 10 degrees?

Post by egutting »

Are you using an Uno for your arduino? My understanding is that the ADC on an arduino uses the base voltage as the reference. So if you're using an Uno, it would use 5v, a 3v trinket would use 3.3v, etc....

If you are using an Uno, you may try plugging it into 5V and then changing your math accordingly.

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

Re: Temperature Sensor Readings Off By 10 degrees?

Post by adafruit_support_bill »

The spark uses a 12-bit ADC so the raw range is 4096 counts. The voltage calculation should be

Code: Select all

double voltage = analogRead(A0) *  (3300/4096);

User avatar
berko
 
Posts: 67
Joined: Sat Aug 04, 2012 6:44 pm

Re: Temperature Sensor Readings Off By 10 degrees?

Post by berko »

as always, Bill, you are so helpful!

with this in mind i have made a few changes. Please let me know if i am way off because if i am correct then i think the formula in the tutorial is not correct. there is a greater chance that i am being a doof.

updated code:

Code: Select all

 voltage = analogRead(A0) * 3.26;
    voltage /= 4096.0; 
 
    temperatureC = (100 * voltage) - .5;
    temperature = (temperatureC * 9.0 / 5.0) + 32.0;
things to note:
1) i have change the voltage to 3.26 as that is what is coming off the core's 3.3v pin according to my multimeter
2) i have change the value for adjusting to volts based on Bill's comment
adafruit_support_bill wrote:The spark uses a 12-bit ADC so the raw range is 4096 counts. The voltage calculation should be

Code: Select all

double voltage = analogRead(A0) *  (3300/4096);
and 3) i have changed the formula to convert from volts to C as i was getting freezing cold values. I am now multiplying by 100 first THEN i am subtracting the off set of .5.
i am not sure if this is correct but i am now getting values of ~71 which is in the range i am expecting.
When i use the formula in the tutorial i am getting -18 F or -27 C.

Bill, I'm i missing something here?

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

Re: Temperature Sensor Readings Off By 10 degrees?

Post by adafruit_support_bill »

The first thing to do is verify the voltage calculations. My comment was based on the spark documentation. I do not actually have one here to test.

If you remove the temp sensor and connect A0 to the 3.3v pin, the raw value should be 4095 and the voltage calculation should give you 3.26.

Then re-insert the temp sensor and take a voltage reading from the signal pin with your multimeter. Compare that with the voltage calculated by your sketch.

User avatar
berko
 
Posts: 67
Joined: Sat Aug 04, 2012 6:44 pm

Re: Temperature Sensor Readings Off By 10 degrees?

Post by berko »

thanks, i gave that a try and got 4095 back consistently.

changed the formula back to match the tutorial (plus your change to use 4095).
after converting to C i get 3.259.... as you say.

now, i plug the tmp26 back in and values don't match what i had when i was reading from the multimeter. so something fishy.

i am going to try and see if i can get this working on my uno first and make sure the tmp36 is working correctly. this will help me figure out if the issue is with the core or the tmp36.

also, i came across this thread. http://community.spark.io/t/odd-analog- ... solved/906

if the tmp36 reads correctly on the Uno i will leave you alone and try to read that thread more closely :)

first lunch.

thanks for all your help. i will let you know what i find if anything. maybe tomorrow.

-jon

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

Re: Temperature Sensor Readings Off By 10 degrees?

Post by adafruit_support_bill »

Wow! That's a long and bumpy thread. But the bottom line is, the spark has some issues with measuring high-impedance sources. The Arduino has some difficulty with this too, but not quite as extreme. It can usually be solved by talking two readings and tossing the first one.

User avatar
berko
 
Posts: 67
Joined: Sat Aug 04, 2012 6:44 pm

Re: Temperature Sensor Readings Off By 10 degrees?

Post by berko »

wow, ok, i added a cap to the input pin and Boom. my readings are correct.
adafruit was right. sprinkle those on everything!

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

Return to “General Project help”