Pages: [1]   Go Down
Author Topic: Displaying temperature using LM35 sensor  (Read 1458 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have hooked up my LM35 properly. I cant figure out where to go to read the temperature results. Also I need to know how to upload the program i have written properly to the arduino
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2891
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ummm, read the book... maybe like the rest of us did...

Doc
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


it works similar as the lm34 one , there are different algorithms compared in this sketch, have fun

Code:
//
//    FILE: lm34.pde
//  AUTHOR: Rob Tillaart
//    DATE: 2012-01-24
// PURPOSE: showing LM34 fahrenheit temp sensor
// VERSION: 0.1
// HISTORY: 2012-01-24 initial version (2 diff loops
//          quite a difference between 3 sensors
//
float raw = 0;
float t = 0;

void doPrint()
{
  Serial.print(raw);
  Serial.print("\t");
  Serial.print(t, 4);
  Serial.print("\t");
  Serial.println((t-32)*0.555555555555, 4);
}

void setup()
{
  Serial.begin(115200);
  Serial.println("START....");
}

void loop1()
{
  raw = raw * 0.9 + 0.1 * analogRead(A0);
  t = 5 + raw * 500.0/1023.0;
  doPrint();
  delay(10);
}

void loop3()
{
  raw = 0;
  for (int i=0; i<100; i++) raw += analogRead(A0);
  t = 5 + raw*5.0/1023.0;
  doPrint();
  delay(10);
}

void loop2()
{
  raw = 0;
  for (int i=0; i<500; i++) raw += analogRead(A0);
  t = 5 + raw/1023.0;
  doPrint();
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2891
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank You Sir for a most useful sketch, I am a noob here and this is good insight for analog sensors in general and the LM series specifically. I have used them for years as they are accurate out of the box, a check of 200 devices I used in a production run were all within 1 - 2% of correct temp and that error might well be the granularity of the A/D conversion, an 8 bit conversion is +/- 4 MV or +/- 1/2 deg F.  This combined with the stated accuracy of the sensor would make the LM34/5 parts a very good deal and easier to use than the Dallas/Maxim parts. As a side note the temp measurement chips usually described, the DS18B20 are in my opinion much harder to use, even with the library's written for them as the A\/D conversion is direct @ 10 Mv / deg with the standard 10 bit resolution the error is 1 part in 124 or less than 1 Mv unless I am seriously mistaken.


Doc
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2891
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My math is wrong in the above post ii the error is 10MV (1 deg) parts in 1024 = 1/102 about 4.8%, and it is readily possible to have an inaccuracy of 2 or 3 counts due to ground potential differences, a common failing in using any analog device. Still good accuracy though... IMO

Doc
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Although I allways use Celsius I prefer the LM34 which counts degrees Fahrenheit as its step size is ~ 0.56 C  (5/9) which is almost twice the stepsize of LM35.

The math is typical

C = (F -32) * 5 / 9;

times 2 and some reshuffle

C = (F *10 - 320)/18

add rounding  (+9)

int C = (F * 10 - 311)/18; 
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Peoples Republic of Cantabrigia
Offline Offline
God Member
*****
Karma: 6
Posts: 722
Arduino happiness
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This combined with the stated accuracy of the sensor would make the LM34/5 parts a very good deal and easier to use than the Dallas/Maxim parts.
Allow me to disagree. While I use the LM35, TMP36, etc. I would not consider them superior to the 1-Wire temperature devices out there like the DS18B20. Unlike 1-Wire sensors, the LM35 et al produce a analog signal which can easily pick up noise. Additionally, they are very dependent on a stable voltage source. So while they are significantly less expensive than the 1-Wire sensors out there, they come with significant caveats... just scan the boards here for the many HELP! questions relating to LM35's producing erratic readings.

The 1-Wire devices use a digital bus that can be over 100' long, yet suffer no ill effect, and over a hundred 1-wire devices can operate off of one power source. Additionally, 1-wire sensors are available in all sorts of neat packages like waterproof assemblies. The major downsides are the 12-bit resolution (if you need more) and the cost.

Aces in their places and all that. I use the LM35 on PCBs where I can control voltage, minimize noise pickup with careful trace design, etc. while using DS18B20 for off-board applications where noise resistance, convenience, etc. trumps all other considerations. For even better resolution, I skip LM35's and use 2k52 thermistors and a dedicated 16-bit ADC in a bridge circuit to maximize the resolution of the thermistors across the temperature range that is of interest.
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2891
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And you are correct in ALL respects, however it is not too much difficulty to provide a stable 5V source that is noise free and properly bypassed. It is a requirement for stable operation of the Arduino. Power Supply instability is of paramount importance for a well designed device and as to 100" of wire and multi-drop measurements, yes of course the Dallas parts are the only way to go. You forgot to mention the Alarm capabilities. The routines for the digital sensors are a part of the Arduino environment... Native , so to speak. It is best, in my opinion to apply the best part for the job and the job here is education as much as building things to add to ones environment, so I advocate the LM34/5 as an accurate and easy to use part, provided that the total environment is good which means an accurate and well bypassed power supply. Fully half of the issues I see here could be a poor power supply.

Doc
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Pages: [1]   Go Up
Jump to: