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.
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.
// 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());
}
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.
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:
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?