element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Nico teWinkel's Blog FRDM-KL25z and TMP36 sensor
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ntewinkel
  • Date Created: 25 Jun 2013 12:10 AM Date Created
  • Views 492 views
  • Likes 0 likes
  • Comments 2 comments
  • 2.9v
  • frdm-kl25z
  • tmp36
  • arduino
  • 3.3v
Related
Recommended

FRDM-KL25z and TMP36 sensor

ntewinkel
ntewinkel
25 Jun 2013

I've been working on a data logging system for my greenhouse - basically just a way of tracking soil moisture, sunlight, rain barrel water level, and of course temperature inside and outside of the greenhouse.

 

I built most of it for Arduino, as I have several of them, and only one KL25z - and I have other plans for the KL25z board image

 

But I thought I'd try the TMP36 temperature sensor with the KL25z, as the Arduino has a couple of limitations that are bugging me for the project:

* First, to keep things simple I've been saving the data in a plain array in memory, but the Arduino Uno only has 2Kb RAM available, of which much is taken up by my program as it runs. The KL25z has a whopping 16Kb.

* Second, the Uno's ADC is only 10bit where the KL25z has 16bit ADCs. For the TMP36 sensor, which returns a set 10mV per degree, this should give us some extra accuracy.

 

3.3 Volts ?

One of the first things I noticed is that the temperature returned was always much too high. So I checked the actual voltage on the 3.3v pin, and it actually shows as being a steady 2.908 volts. That's kind of odd, but adjusting the code to use that number to find the proper temperature seems to give me the correct results.

 

I don't know why, but the Arduino was returning much steadier results from the TMP36 sensor, even when I decided to take the average of something like 100 readings on the KL25z. Not sure why that would be, but maybe a hardware guru can enlighten us on that image  I'm guessing that the added speed of the KL25z might have something to do with it. From a software perspective, it might be a good idea to take a lot of samples and return the statistical mean - given the extra speed and memory, the KL25z should be able to tackle that quite easily without significant delay.

 

Here is the code I used, if you want to try this at home:

 

#include "mbed.h"


AnalogIn tmp36sensor(PTB0);


float sum;


int main() {
    while(1) {
    
        sum = 0.0;
        
        for(int i=0; i<200; i++) {
            sum = sum + (tmp36sensor.read() * 290.8 - 50.0); // the 3.3v from the KL25Z is really only 2.908 volts
        }
    
        printf("Temperature = %0.1f \n", sum / 200.0);
        wait(2.0);
    }
}

 

The sensor read returns a value between 0 and 1, which is the percentage the input voltage is at, compared to the reference voltage. The 50 is the offset required for the TMP36 (allows for negative temperatures).

 

Cheers,

-Nico

  • Sign in to reply

Top Comments

  • vsluiter
    vsluiter over 11 years ago +1
    Nico, Others have found similar problems: http://mbed.org/forum/mbed/topic/628/?page=1#comment-3178 Maybe you could set the reference voltage to an internal reference to see whether that helps; with no…
  • ntewinkel
    ntewinkel over 11 years ago in reply to vsluiter

    Thanks Victor!

    Maybe that's something they're still working on. I'd rather avoid going to register level to do anything, but I might try the RC filter at some point.

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vsluiter
    vsluiter over 11 years ago

    Nico,

    Others have found similar problems: http://mbed.org/forum/mbed/topic/628/?page=1#comment-3178

    Maybe you could set the reference voltage to an internal reference to see whether that helps; with no  API call for that, it would involve digging into the Freescale registers.

    Otherwise use a RC filter (small R, large C to quickly fill the Sample-and-Hold capacitor) to buffer the output of your sensor. Your temperature won't be changing that fast...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • 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