1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

calibrating lm35 analog value to degree Celsius using 8051

Discussion in '8051/8951' started by Bob Parihar, Dec 8, 2014.

  1. Bob Parihar

    Bob Parihar Member

    Joined:
    Oct 8, 2014
    Messages:
    87
    Likes:
    0
    i am working on a project which objective is to measure the temperature of surroundings..using AT89s52 micro-controller and ADC0804 for A to D conversion.. the temperature meant to be shown on LCD..
    after doing some research i managed to read ADC values coming from the LM35 and displaying it on LCD..

    now... finally the tricky thing which i fails to understand...( may be because i won't get any useful material to study)..
    so i want to know...
    - how to convert the ADC value to corresponding Degree Celsius
    -how the step change get affected by varying the Vref/2 and how this affect my code..

    My circuit Diagram and CODE( iam getting the varying ADC value on LCD as i change the temperature) is given as..


    #include<reg52.h>
    #include"lcd.h"
    void delay1(unsigned int);
    sbit chipsel =P1^4;
    sbit write = P1^5;
    sbit intr = P1^7;
    sbit readAD = P1^6;
    unsigned int val=0,i,j;
    void conv();
    void read();
    void main()
    {
    init();
    while(1)
    {
    conv();
    read();
    cmd(0x01);
    op(val);
    delay(1);
    }
    }
    void conv()
    {
    chipsel = 0; //Make CS low
    write = 0; //Make WR low
    write = 1; //Make WR high
    chipsel = 1; //Make CS high
    while(intr); //Wait for INTR to go low
    }

    void read()
    {
    chipsel = 0; //Make CS low
    readAD = 0; //Make RD low
    val = P3; //Read ADC port
    readAD = 1; //Make RD high
    chipsel = 1; //Make CS high
    }

    void delay1(unsigned int y)
    {
    for(i=0;i<y;i++)

    for(j=0;j<1275;j++);

    }


    the LCD source code is in the attachment with the circuit diagram
     

    Attached Files:

    • prjct.png
      prjct.png
      File size:
      24.5 KB
      Views:
      572
    • temp.c
      File size:
      764 bytes
      Views:
      126
    • lcd.h
      File size:
      650 bytes
      Views:
      119
  2. ronsimpson

    ronsimpson Well-Known Member Most Helpful Member

    Joined:
    Apr 17, 2007
    Messages:
    7,253
    Likes:
    961
    Location:
    Loveland, CO USA
    I see no software person has answered you. I am a hardware person.
    Get the data sheet for the LM35. It has a temperature to voltage graph.
    ADCs in micro controllers do not measure voltage directly. In 8 bit mode they measure from 0 to 255. Where 0=0 volts and 255=vref.

    You need to think; at freezing=some voltage from the LM35 and a certain ADC reading.
    At boiling= a LM35 voltage and a ADC reading. (based on the value of VREF)
    With some math you should be able to connect temperature to ADC reading.
     
  3. Bob Parihar

    Bob Parihar Member

    Joined:
    Oct 8, 2014
    Messages:
    87
    Likes:
    0
    thanks for your help sir!
    i am a noob here and this graph doesn't make me any sense.. its from LM35 Data sheet



    upload_2014-12-10_10-52-12.png
    i did read some tutorials.. but those are not complete tutorial.. they don't explain what should be the voltage at Vref/2 pin of ADC0804 . and how the step change changes by varying that Vref/2 voltage..
    all i get to know that LM35 output voltage changes about 10mV per degree rise in temprature...

    all this Vref thing confusing me
     

    Attached Files:

Share This Page