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

temperature monitoring system using LM35 and 8051

Discussion in '8051/8951' started by Bob Parihar, May 28, 2015.

  1. Bob Parihar

    Bob Parihar Member

    Joined:
    Oct 8, 2014
    Messages:
    87
    Likes:
    0
    i was doing a project of temperature monitoring system using 8051 and LM35 for that i use ADC0804 programming
    my whole setup is going great previously..
    i was getting the correct temperature on LCD..but don't know what happened recently.. on room temperature which should be 25 degree Celsius it is showing 57 degree..
    i rotate the dial of POT on ADC0804 to least and the least temperature i am getting is 57 degree

    how i can overcome this problem
    my hardware circuit and code is as follows
    Code (text):
    //Program to display temperature in Celsius and Farenheit scale.

    #include<reg51.h>
    #define port P3
    #define adc_input P1
    #define dataport P2
    #define sec 100
    sbit rs = port^7;
    sbit rw = port^6;
    sbit e = port^5;
    sbit led = port^0;
    sbit wr= port^3;
    sbit rd= port^2;
    sbit intr= port^4;

    int test_intermediate3=0, test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};

    void delay(unsigned int msec )
    {
        int i ,j ;
        for(i=0;i<msec;i++)
            for(j=0; j<1275; j++);
    }

    void lcd_cmd(unsigned char item)    // Function to send commands to LCD
    {
        dataport = item;
        rs= 0;
        rw=0;
        e=1;
        delay(1);
        e=0;
        return;
    }

    void lcd_data(unsigned char item)    // Function to send data to LCD
    {
        dataport = item;
        rs= 1;
        rw=0;
        e=1;
        delay(1);
        e=0;
        return;
    }

    void lcd_data_string(unsigned char *str)  // Function to string to LCD
    {
        int i=0;
        while(str[i]!='\0')
        {
            lcd_data(str[i]);
            i++;
            delay(10);
        }
        return;
    }

    void shape()        // Function to make the shape of degree symbol
    {
        lcd_cmd(64);
        lcd_data(2);
        lcd_data(5);
        lcd_data(2);
        lcd_data(0);
        lcd_data(0);
        lcd_data(0);
        lcd_data(0);
        lcd_data(0);
    }
         
    void convert()     // Function to convert the values of ADC into numeric value to be sent to LCD
    {
        int    s;
        lcd_cmd(0x81);    
        delay(2);
        lcd_data_string("TEMP:");
        test_final=(((9*test_intermediate3)/5)+32);
        s=test_final/100;
        test_final=test_final%100;
        lcd_cmd(0x88);
        if(s!=0)
        lcd_data(s+48);
        else
        lcd_cmd(0x06);
        s=test_final/10;
        test_final=test_final%10;
        lcd_data(s+48);
        lcd_data(test_final+48);
        lcd_data(0);
        lcd_data('F');
        lcd_data(' ');

        test_final=test_intermediate3;
                    if(test_final>35)
                led=1;
           
               else
                led=0;
        lcd_cmd(0xc1);        //Setting  cursor to first position of first line
        delay(2);
        lcd_data_string("TEMP:");
        s=test_final/100;

        test_final=test_final%100;
        lcd_cmd(0xc8);
        if(s!=0)
        lcd_data(s+48);
        else
        lcd_cmd(0x06);
        s=test_final/10;
        test_final=test_final%10;
        lcd_data(s+48);
        lcd_data(test_final+48);
        lcd_data(0);
        lcd_data('c');
        lcd_data(' ');
        delay(2);
    }

    void main()
    {
        int i,j;
        adc_input=0xff;
        lcd_cmd(0x38);        //2 Line, 5X7 Matrix display
        lcd_cmd(0x0c);        //Display On, Cursor blinking
        delay(2);
        lcd_cmd(0x01);        // clear screen
        delay(2);

        while(1)
        {
            for(j=0;j<3;j++)
            {
                for(i=0;i<10;i++)
                {
                    delay(1);
                    rd=1;
                    wr=0;
                    delay(1);
                    wr=1;
                    while(intr==1);
                    rd=0;
                    lcd_cmd(0x88);
                    test_intermediate1[i]=adc_input/10;
                    delay(1);
                    intr=1;
                }
                       
                for(i=0;i<10;i++)
                test_intermediate2[j]=test_intermediate1[i]+test_intermediate2[j];
            }

            test_intermediate2[0]=test_intermediate2[0]/3;
            test_intermediate2[1]=test_intermediate2[1]/3;
            test_intermediate2[2]=test_intermediate2[2]/3;
            test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2];
            shape();
            convert();
        }
    }
    [​IMG]
     

Share This Page