Tuesday 7 July 2015

Temperature sensor LM35



In this project we will be using a LM35 precession temperature sensor to read the current temperature and then output that data via serial to the computer so it can be read.


*LM35 information* 

 

 What is a LM35?


The LM35 is a precession temperature sensor that changed its voltage output depending on the temperature.

We will be using the TO-92 package version as it fits nicely on a breadboard, the others are either larger or are "chip" like which of this project will have draw backs. The TO-92 is the common size but if you happen you have another package it will work exactly the same, just check the pinout!

LM35 pinout:


 

Using it:


We can use the LM35 with a bit of careful coding to work out the temperature. Every one degree Celsius increase the voltage will also go up my 10mv.

NOW FOR SOMETHING DIFFERENT ... MATHS TIME ... below.

The maths:


In my projects you won't normally find a key bit of explanation on how to make a component work using code before the code section but in the case of the LM35 I need to explain how we work out the maths which gives us the temperature reading.

To those who what scrolled down you might have spotted this line;



temp = temp * 0.48828125;

That number "0.48828125" looks a little bit random, where did I get that figure from?

To get a number output in centigrade we needs to times the raw data form the LM35 by the value of the voltage the LM35 will be getting and then times that by 1000 then divide that by the maximum figure that can be output from the LM35 and finally divide that by 10... madness, what the heck dose it all mean


So the supply voltage to the LM35 will be 5 volts so that's the first number we need -> 5

We have to timed the supply voltage by the next number                                       -> *

Then we times that by 1000 the second number                                                    -> 1000

With that figure we need to divide it by the maximum readable from the LM35         -> 1024

And finnally device that by 10                                                                              -> / 10

And the result is 0.48828125

*The Project*

 You will need;

  1.  Arduino Uno
  2. Breadboard (half+ will be fine)
  3. Jumper wires
  4. LM35

 The Diagram; 




 The code:



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
byte temp;                               // Setting the place to store the temperature
int tempPin = A0;                        // Input pin connected to the LM35 called "tempPin"

void setup()

{

Serial.begin(9600);                      // Starting serial so we can use it

}

void loop()

{

temp = analogRead(tempPin);              // Arduino reads the "tempPin" and records in in "temp"

temp = temp * 0.48828125;                // The math part see above

Serial.print("TEMPRATURE = ");           // Show on screen the bit in blue 

Serial.print(temp);                      // Show the current value of "temp"

Serial.print("*C");                      // Show on screen the bit in blue 

Serial.println();                        // "ln" and the end of print makes a new line

delay(1000);                             // Wait a second and do it again

}

Code layout from a website called hilite.me


*Results*

 Straight from the serial monitor from the IDE its showing a temp of 24-25 'C, the room was a little warm to work in on a summers evening... no air conditioning :(.




Now I have pinched the LM35 between my finger and thumb and the temperature has shot up to 32'C.



A few photos of the set up, thoes out there who like to pick stuff apart will notice that its different to the diagram above this is because I used up my longer jumper wires on another prototype so I had to make do with a few smaller ones, nothing that I'm sure you all can't handle.




No comments:

Post a Comment