Go Down

Topic: Library for LM335A Temperature Sensor (Read 3429 times) previous topic - next topic

GreenRobotics

Here's a class I wrote for use with the LM335A temperature sensor. I think the class makes it easy read temperatures without needing to do more than tell the software what pin to use, when to read the temperature, and what units are desired.

LM335A Libraryhttp://greenrobotics.net/files/LM335A.zip

I'm new to the Arduino and really enjoy the community of creators and what they have done with their Arduinos. Many thanks to all the folks that discussed the LM335A, especially Jonathan Smith on how to hook it up properly, and convert the temperature. Thanks to David A. Mellis for writing the tutorial "Writing a Library for Arduino".

Here is the sample program. I look forward to any feedback.

Code: [Select]
// Example using the LM335A library for reading temperatures
// Created by Jonathan Merrill, February 20, 2010.
// http://www.greenrobotics.net
//  Released into the public domain.

#include <LM335A.h>

LM335A InsideTemp(0); //pass the analog input pin number
void setup() {
Serial.begin(57600);
Serial.println("starting");

}

void loop() {
 delay(3000);
 //user must call ReadTemp before any valid temp data is available
 InsideTemp.ReadTemp();  
 Serial.print("Fahrenheit: ");
 //functions to get the temperature in various unitsfs
 Serial.println(InsideTemp.Fahrenheit());
 Serial.print("Celsius: ");
 Serial.println(InsideTemp.Celsius());
 Serial.print("Kelvin: ");
 Serial.println(InsideTemp.Kelvin());

}


KenH

Good work Green - I'm at work so have not downloaded and looked at the files - I'll do that when I get home.

Is your "Class" (is this handled same as library?) written for a specific wiring schematic?  OR the way the basic sensor is wired?

You use Serial.print() in your example, does it work with lcd.print() also?

Will it work for any temperature sensor with 10mV/ºK?

I'll be looking forward to playing with it some.

Ken H.

AlphaBeta

#2
Mar 01, 2010, 11:01 pm Last Edit: Mar 01, 2010, 11:24 pm by AlphaBeta Reason: 1
Hello!

Great work. Warms my heart to see those const in there!

You might want to concider following the arduino naming convention and change the 'getters' to

     void readTemp();
     float fahrenheit() const;
     float celsius() const;
     float kelvin() const;


:)

GreenRobotics

Thanks guys.
I think I found a problem after all the testing I did with conversion to F! I didn't look at it too much, but I think the 9/5 in the routine did not equate to 1.8 for some reason.

I will review the naming convention and see about updating the 'getters' with the update (where can I find more advanced creating classes for Arduino tutorial/template?) Thanks for the feedback! I will update the other classes I am working on.

The class is written for the LM355A sensor. I *finally* discovered Fritzing which allows you to creating a breadboard design. I may *eventually* create the LM335 sensor in it, and include that as part of the zip. I cannot say what other temperature sensors the library will work for, but if several sensors have 10mv/K then I would say yes it should work. Let me know what else it works for and I will add in any extra info and part numbers of the other sensors it can work with. The sensor is current limited with a resistor (around 2k). I do not yet have a trim pot on mine for accuracy.

The class gets the current temperature in the units that the users asks for. As long as the Serial.print() and the LCD.print() functions can handle both handle a float I don't see why it wouldn't work. You might want to format the float to a certain number of digits for string output to an LCD.  Please let us know how it works for you. Feel free to send me your tested LCD routine with your information and I will put it in the example folder.

patrickokeeffe

Hello! Nice work on this class GreenRobotics - I was trying to do the same thing when I came across your example. I do suggest adding Rankine units for completeness. I also wondered two things:

1) it is a good idea to use a for-loop to achieve an integrated reading? For example, I pass a value of 250 into ReadTemp() and it finds the average of 250*X readings taken 1/X ms apart. How quickly then can the Arduino sample? A test of this gave better resolution but I couldn't tell how artificial the noise was.

2 ) I don't quite understand why the pinmode is set if the reading is done through an analog pin. Is it necessary to set the modes on both D&A pins?

Thanks!

Go Up