element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Calibration of TMP36 sensors on Arduino?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 8 replies
  • Answers 2 answers
  • Subscribers 391 subscribers
  • Views 2027 views
  • Users 0 members are here
  • accuracy
  • temperature
  • tmp36
  • adjust
  • arduino
  • sensor
  • calibration
Related

Calibration of TMP36 sensors on Arduino?

ntewinkel
ntewinkel over 12 years ago

So I had a chance to try this out:

 

I put 3x TMP36 sensors side by side on a breadboard, hooked it up to use the 3.3v reference for better accuracy, set up the code to discard the first reading (to settle the ADC) and then take the average of 8 analogRead's with 20 ms delays between, and this is the result:

Temperatures = 25.04, 24.72, 24.40

Temperatures = 25.37, 24.40, 24.08

Temperatures = 25.04, 24.40, 24.08

 

The list is much more steady than that, but I copied the part that shows the bit of fluctuation that happens every so often - it steps up/down in increments of (reference voltage / 1024), which for my 3.3v reference is about 0.32 degrees. In other words, one point difference in the analogRead result equals 0.3 degrees. Using a 5 volt reference therefore would make that about a 0.5 degree increment.

 

Now, my handheld laser-guided temperature reading doohickey says it's about 24 degrees C in here - I know! it's a warm day today!! (I live on the very temperate West Coast of Canada)

 

So obviously there is a difference between sensors, as the first one is nearly a degree higher than the last one.

 

How would you normally adjust for specific sensors? Or would you adjust?

 

For example, if I trust my handheld reader, I would say that (based on the values of the last line) sensor 3 is perfect, and for sensor 1 I would (in the code) always subtract a degree, and for sensor 2 I'd subtract 0.3 of a degree.

But I'm a software guy and I'm betting there's a very clever hardware solution people would use for this.

 

This is for a one-off project, not sure if that would change the approach.

 

Also, the plan is to use 2 of these sensors to track temperatures inside and outside of my greenhouse. In my area I would not expect temperatures to exceed the -20 to +50 C range. Doing the math, +50 comes to 1 volt. Is there a way (an easy way?) to set the reference voltage to 1 volt so I can get accuracy of 0.1?

 

Thanks!

-Nico

  • Sign in to reply
  • Cancel

Top Replies

  • mcb1
    mcb1 over 12 years ago in reply to ntewinkel +1 suggested
    Nico My calculation is that you are somewhere in the (750mV) A0=232 at 25degC, which is less than quarter of the fullscale (assuming 3v3 supply) Using a 3v3 supply I calculate each step is 0.0032258mV…
  • neilk
    neilk over 12 years ago +1 verified
    Hi Nico Yes I have been quiet for a long time and no, sadly, I haven't completed my Greenhouse temperature control project yet. Most aspects of it are designed and in most case tested and proven. I haven…
  • mcb1
    mcb1 over 12 years ago in reply to neilk +1 suggested
    Neil/Nico I did something you describe for 'The Shed' magazine as part of our 101 series. The article and software is here (part 4 included the LCD in both normal and I2C version) http://www.theshedmag…
  • ntewinkel
    0 ntewinkel over 12 years ago

    Ok, I knew this already and just realized it - to get near one volt, all I have to do set up a voltage divider off the 3.3v with a 1meg and a 470k resistor. :)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to ntewinkel

    Nico

     

    My calculation is that you are somewhere in the (750mV) A0=232 at 25degC, which is less than quarter of the fullscale (assuming 3v3 supply)

    Using a 3v3 supply I calculate each step is 0.0032258mV

     

    Another method is to change the analogue reference to 1.1v

    http://arduino.cc/en/Reference/AnalogReference

     

     

    My calculations are that you could read up to 60deg C using the 1.1v internal reference available on a 328 and the adafruit formula.

    Temp in °C = [(Vout in mV) - 500] / 10

     

    Mark

     

    I also answered your other post.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • neilk
    0 neilk over 12 years ago

    Hi Nico

     

    Yes I have been quiet for a long time and no, sadly, I haven't completed my Greenhouse temperature control project yet. Most aspects of it are designed and in most case tested and proven. I haven't yet integrated the whole system! I too gave up on the idea of Gobetwino for this particular project and am attracted to the idea of of using a WiFi shield with the Arduino - maybe!

     

    You asked a number of questions about error, accuracy and calibration.

     

    Measurement error is normally divided into Systematic and Random:

    1. Systematic error is like a constant offset, eg a 50g weight that has had achunk filed off it so it only weighs 49.5g
    2. Random error is the fluctuation you get between readings that you hoped would be the same value.

     

    Accuracy is around making measurements which are appropriate to the measuring device AND to the reason for taking the measurement in the first place.

    So, if, at the ADC level, 1 point in 1024 represents 0.3 degrees, that suggests to me that quoting the temperature more accurately than the nearest degree is pretty optimistic.

     

    Then we come to why are we measuring in the first place? To control my Greenhouse, I want to switch on a heater when the temperature falls below about 5 degrees and back off again when it rises to about 10 degrees. I also want to switch on a cooling fan when the temperature rises above about 25 degrees and back off again when the temperature falls below about 20 degrees. So an accuracy of + or - 1 degree is more than adequate (for my application).

     

    Applying my crude approach to your readings, above, would give:

     

    Temperatures = 25, 25, 24

    Temperatures = 25, 24. 24

    Temperatures = 25, 24, 24

     

    In otherwords,  within + or - 1 degree for a device and even between devices.

     

    As for calibration, my memory of School Physics (which was a very long time ago!) tells me that:            

    • 0 degrees  C is pure water containing ice made from pure water, well stirred, of course.
    • 100 degrees C is steam over boiling water.

     

    Both are assumed to be at 1 standard atomsphere ie 760mm Hg. I guess anywhere close to sea level is near enough!

     

    See here to become a temperature calibration expert:  http://en.wikipedia.org/wiki/Thermometer#Calibration

     

    And finally, if I was happy that my old fashioned thermometer (double checked, as above) was accurate, or, if it had a systematic error then I knew what that error was and could correct for it ( I have one that consistently over reads by 2 degrees C), then I would compare my sensors with the thermometer at a series of temperatures in the range I was expecting them to work.

     

    If I found that a sensor regularly disagreed with the thermometer by a significant amount, then I could correct for that in my software.........however, that would complicate the software and require different segments of code, which would need to line up with the correct Arduino pins and sensors.....could get a bit messy; might be easier to get hold of some more sensors and select a group which all have the same systematic error, which could be zero if you are lucky.

     

    Oh dear, I have just read this through again and it sounds really pedantic and maybe a little patronisisng - it's not meant to! Again, many years ago, measurement error and appropriate accuracy was part of my life!

     

    Nico, I hope you find some use in this

     

    Best wishes

     

    Neil

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to neilk

    Neil/Nico

     

    I did something you describe for 'The Shed' magazine as part of our 101 series.

    The article and software is here (part 4 included the LCD in both normal and I2C version)

     

    http://www.theshedmag.co.nz/online/arduino

     

    I used Dallas temp chips to ovecome most of the calibration issues

    There are some around that are already encapsulated and have a lead on them, to make it easier.

     

    The other option is to solder leads and insulate the wires, then apply heat transfer compound that is used for transistors, and fit them into a piece of metal tubing.

    The tube is sealed at one end and the other end fits into a compression gland commonly used in the electrical industry to hold a cable as it passes through an enclosure.

    The tubing should be close to the size of the device, but as long as its making contact it will take on the temperature of the metal tube.

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • neilk
    0 neilk over 12 years ago in reply to mcb1

    Mark

     

    Thanks for the link to "The Shed" magazine - the projects are beautifully laid out and so clearly described.......why have I never come across these articles before?

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to neilk

    Neil

    They are well laid out.

     

    The magazine is a NZ hobbyist magazine and the publisher has included the Arduino and now RaspberryPi into it.

    The articles are put together to allow the reader to make them, rather than showcase what they built.

     

     

    There are electronic subscriptions, but paper is always good.

     

    I'll pass your comment back to the editor.

     

     

    Cheers

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • ntewinkel
    0 ntewinkel over 12 years ago in reply to mcb1

    Thanks Mark and Neil!

     

    The reason I want the temperature sensors is just for data logging, and the accuracy is only important once we get near the freezing point - which hopefully won't be an issue for quite a while image

    And I agree, 0.1 degree accuracy doesn't mean much if the sensors fluctuate more than that, and in actual use I think just knowing that the temperature is close to 0 is enough.

     

    Thanks, Mark, for pointing out the built-in 1.1v reference! I had actually looked at that documentation earlier and saw it, and then promptly forgot image

     

    I've been debating on whether to just use the 3.3v instead because of the other sensors running the full 0-1024 range, but I could probably just add a resistor to the other sensors to bring the range down to where 1.1v is fine as a reference.

     

    For now, I think the 3.3volt reference will be the easiest and quickest way to go. I think my 5volt source was too noisy, so the 3.3v source immediately gives a much more stable voltage, plus hooking it to the ARef helps the sensors be a bit more stable.

     

    Mark, I checked out those one-wire sensors you pointed out. I should have bought those to begin with, as they cost about the same as the TMP36's I bought, plus they are already waterproof and include something like 3 meters of wire! I think I'll buy one for the outside sensor.

     

    So it looks like I need to do some more soldering to get things connected up image

     

    Thanks,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to ntewinkel

    Nico

     

    There are varying prices for the DS18B20's and the encapsulated ones save a lot of time and effort.

     

    One thing I have yet to see done well, is to differentiate between the various sensors.

    Each has a unique number, and while you can target that, it doesn't translate to someone else using you sketch or replacing a sensor.

     

    I did think of a calibrate mode where you apply heat to raise one and then mark that as 'inside1', 'outside3' or whatever.

    You could automate it where it tells you to heat 'inside1', then 'inside2'  ..

     

    In the meantime most people just code each sensor or put them on seperate inputs.

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube