Saturday, 9 August 2014

Temperature Sensor LM35 interfacing with GR-Sakura


LM 35 is one of the low cost and easily available temperature sensor used by most of the hobbyists.
Click here for Datasheet.


It has 3 interface pins,

1.      Vs

2.      Vout

3.      Gnd

Vs and Gnd are power supply connections (4 – 30 Volts) and Vout is the output voltage that is linearly proportional to Celsius temperature scaling.

Keep in mind the feature as stated in its datasheet, “Linear + 10.0 mV/°C scale factor”. This is useful in ADC calibrations.

I have used a 12 bit ADC in Sakura board. Hence the possible digital values range from 0 – 4095 (212 = 4096).  The default reference voltage for ADC in GR-Sakura is 3.3 V.

Hence, from the digital value, the voltage can be calculated as,

Voltage = ( (value from ADC) / 4096 ) x 3.3 v

The result is in volts. However, the LM35 corresponds to output in milliVolts(mV). Converting the result in milliVolts,

Voltage = ( (value from ADC) / 4096 ) x 3.3 x 1000 mV

Now consider the ‘+ 10.0 mV/°C scale factor’. This means that, every additional 10mV from LM35 corresponds to an increase in 1 degree. Since the scale factor is 10mV, dividing the result by 10 mV/C will give us the result in degrees

Voltage =[ ( (value from ADC) / 4096 ) x (1000 mV/10mV) x 3.3 ] degree Centigrade

Voltage = [ ( (value from ADC) / 4096 ) x (100) x 3.3 ] degree Centigrade

You can change the above formula for various resolution ADC’s (for 10 bit ADC, 210 = 1024) and various reference voltage as

Voltage = [ ( (Value from ADC)/resolution) x 100 x reference voltage ]

The above formula is valid only for LM35 sensor.

 
A simple demo,

Code:


#include<rxduino.h>
#include<liquidcrystal.h>

LiquidCrystal lcd(12,11,10,5,4,3,2);
double T;

int main()
{
                                                  lcd.begin(16,2);

                                                  analogReference(RAW12BIT);
                                                  lcd.print("Temperature is ");

                                                  while(1)

                                                  {
                                                  int val=0;

                                                  int T;

                                                  val = analogRead(2);       // read from analog pin 2 (AN002)
                                                  T = (val * 0.08056640625); // calculation given above

                                                  lcd.setCursor(2,1);

                                                  lcd.print(T);  // print temperature value
                                                  lcd.setCursor(5,1);

                                                  lcd.print("degree C");
                                                  delay(500); // refresh rate

                                                  }
}
 

2 comments:

  1. the same logic we tried for mbed board,but we are not getting anything

    ReplyDelete
    Replies
    1. Just check with the ADC resolution, whether you used the correct ADC channel pin and your board's reference voltage.

      Delete