Netduino home hardware projects downloads community

Jump to content


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.
Photo

how do measure temperature(with a temperature sensor) via netduino...Please help me with the code


Best Answer JerseyTechGuy, 27 February 2013 - 12:48 PM

Hello(Dave)--sorry to disturb you again...but I couldnt find the attached project

 

Hmm, this is the second post in 2 days that the Attachment got lost.  I reattached it to the previous post.

Go to the full post


  • Please log in to reply
16 replies to this topic

#1 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 15 February 2013 - 11:56 AM

Thanks for helping me out__

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 15 February 2013 - 12:19 PM

Hi and welcome to the netduino forums!

 

Do you already have parts? The way of measurement depends on the parts. And the parts depend on what you want to measure.


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 15 February 2013 - 12:29 PM

Hello, thanks for taking your time in replying to my post.............abt the parts , i do have them,but sadly im currently struggling with the code



#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 15 February 2013 - 12:46 PM

Which parts do you have? Not all temperature sensors work the same.


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#5 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 15 February 2013 - 01:02 PM

Oh that...I'm using LM35 temperature sensor

#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 15 February 2013 - 03:58 PM

[color=#ff0000;]EDIT: I made a correction to the code and the description.  I mixed up the LM34 and L35.  Let me explain.  The LM34 measures in Fahrenheit whereas the LM35 measures in Celsius. When using the LM34 you would need to subtract the 10mv * 25c (which is zero Fahrenheit) from the millivolt reading to show the reading correctly.  With the LM35 this is not necessary.  You may however still want to subtract some amount of mv from the reading if you decide to calibrate it as it may vary +-1.0c at room temperature.[/color]

 

On the off chance you don't have the documentation, I have attached it.  First you need to look at the documentation.  As Stefan pointed out all sensors are different.  There are many temperature sensors out there and all of them work differently.  The LM35 using a basic Analog Input on the Netduino.  So what you need to know is that the LM35 provides a 250mV output at 25C. This give you a scale to work with.
 
Using the Scale you determined you can create a class with the following code.  You definite an analog input and set the range from 0v to 3.3v (max range of the analog input) in millivolts thus the 3300.  Next you create a method to read the temp in centigrade.  Performing the sensor.Read returns a reading of 0 - 3300 milli-volts.  Since we know 250mv is 25c, we subtract the 250 to zero it out.  Finally you take the milli-volts and divide by 10 since we know we get a 10mV change per degree Centigrade going by the specs.

public class LM35{    protected AnalogInput sensor;     public LM35(Cpu.Pin pin)    {        sensor = new AnalogInput(pin);         sensor.SetRange(0, 3300);     }    public float GetTemperatureInC()    {        // gain = 10 mV/Deg C         int mv = sensor.Read() - 250; // 250 = 0c        int mv = sensor.Read();         return mv / 10f;     }}

To get the reading you'll need to instantiate the class and call the GetTemperatureInC method.  You can use this type of code in your main loop.

public static void Main(){    LM35 sensor = new LM35((Cpu.Pin)AnalogIn.Pin.A0);    while (true)    {        Debug.Print("Temperature: " + sensor.GetTemperatureInC() + "c");        Thread.Sleep(1000);    }}

If you want your reading in Farenheit also you can easily at a new method to the class called GetTemperatureInF and have it call the GetTemperatureInC method and do the math to convert from C to F.

Attached Files


Edited by Dave VanderWekke, 15 February 2013 - 08:33 PM.


#7 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 15 February 2013 - 04:12 PM

Thank u very much for all your help...You guys are the BesT!! My mentors*peace*

#8 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 15 February 2013 - 08:35 PM

Please see my edits to the post above.  I mistakingly swapped the LM34 and LM35 which one reads Fahrenheit and the other Celsius. :unsure:



#9 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 15 February 2013 - 08:58 PM

I appreciate ur help! Thanks

#10 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 15 February 2013 - 08:59 PM

I appreciate ur help! Thanks very much

#11 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 15 February 2013 - 09:04 PM

Hey Dave,

I really like your explaination. I already knew how to write this code by reading tutorials, but I really like it how people use their time to help others :)

Thanks for this.

But I have some questions: How would I wire this up correctly?

Do I have to use a resistor on the "input"? And do I need one on the "output"? The specs say "Output Current 10 mA" which is too much for the Analog Inputs of the Netduino, isn't it?

EDIT: Ok, there it is -> "Less than 60 A current drain" :D

Sorry, I'm really no hardware guy :P

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#12 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 15 February 2013 - 10:04 PM

 How would I wire this up correctly?

Do I have to use a resistor on the "input"? And do I need one on the "output"?

Greets, Markus

 

HI Markus,

 

The LM35 is really easy to use.

Just wire it up to +5V, Ain, and Gnd.

No need for a resistor.

 

Based on other members' results in the past, the LM35 is not so good if you want to use long leads because the signals get noisy.

 

Paul



#13 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 26 February 2013 - 10:31 AM

Hello

 

Dave, i tried your code on netduino plus 2,but ive been getting errors from the compiler.i tried fixing some of the errors but i dont know whats wrong....im starting to panic.i wanted to tell you soon but i thought i would handle it....Please help me>Thanks for your time



#14 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 26 February 2013 - 11:42 AM

Hello

 

Dave, i tried your code on netduino plus 2,but ive been getting errors from the compiler.i tried fixing some of the errors but i dont know whats wrong....im starting to panic.i wanted to tell you soon but i thought i would handle it....Please help me>Thanks for your time

 

I've attached a project where the issues have been resolved.  This was originally pseudo code based on Netduino not Netduino 2 as I wasn't aware you were using the ND2.

Attached Files



#15 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 27 February 2013 - 09:32 AM

Hello(Dave)--sorry to disturb you again...but I couldnt find the attached project

#16 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 27 February 2013 - 12:48 PM   Best Answer

Hello(Dave)--sorry to disturb you again...but I couldnt find the attached project

 

Hmm, this is the second post in 2 days that the Attachment got lost.  I reattached it to the previous post.



#17 ofentse temo

ofentse temo

    Member

  • Members
  • PipPip
  • 11 posts

Posted 01 March 2013 - 10:13 AM

Thank you DAVE.... It is working :) >All the credit to you..Enjoy your day






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.