Connect with us

Problem with LM35

Discussion in 'General Electronics Discussion' started by bigone5500, Aug 14, 2015.

Scroll to continue with content
  1. bigone5500

    bigone5500

    712
    121
    Apr 9, 2014
    I have an UNO with a temperature sketch which displays the current temp in F. I'm using an LM35CAZ. When the display reaches 87.8 degrees, it starts showing negative readings.

    Any ideas?

    Here's the sketch:

    Code:
    #include <Wire.h>                  // Include the Wire library.
    
    #include <LiquidCrystal_I2C.h>     // Include the Liquid Crystal I2C library.
    
    #define sensor 0                   // Define the A0 pin as “sensor”. This can be changed as needed.
    
    int   Vin;                         // Variable to read the value from the Arduino’s pin
    
    float Temperature;                 // Variable that receives the converted voltage value to temperature
    
    float TF;                          // Variable to receive the converted value from  ºC to ºF
    
    LiquidCrystal_I2C lcd(0x27, 16, 2); // Sets the I2C address of the LCD and declares 16 columns, 2 rows.
    
    void  setup()
    
    {
    
      lcd.begin();
     
      lcd.setBacklight(1);            // Turns on the backlight of the LCD. Probably not needed but here anyway.
    
      lcd.setCursor(2, 0);            // Sets the cursor to column 2, row 0.
     
      lcd.print("Temp: ");            //  Send the text 'Temp:' to the screen of the display.
     
      Serial.begin(9600);             // Sets the baud rate for the serial monitor.
    
    }
    
    void  loop()
    
    {
    
      Vin = analogRead (sensor);      // Tells the Arduino to read the pin and stores the value in “Vin”.
    
      Temperature=(500*Vin)/1023;     // Converts the voltage value into temperature and stores it into the “Temperature”  variable  (in  ºC)
    
      TF = ((9*Temperature)/5)+32;    // Converts  ºC to ºF and stores the result in the variable 'TF'.
    
      lcd.setCursor(4, 1);            // Sets the cursor to column 4, row 1.
    
      lcd.print(TF);                  // Exhibits the value of the temperature on the display.
      lcd.print(" F");                // Writes “F” to indicate that it is in Fahrenheit scale.
    
      Serial.print(TF);               // Prints the value 'TF' to the serial monitor
      Serial.println(" F");           // Prints the 'F' designation and inserts a space after 'TF'. 'println' causes a new line carriage return.
    
      delay(1000);                    //  Waits for 1 second to read the pin again.
    
    }
     

    Attached Files:

    Last edited: Aug 15, 2015
  2. davenn

    davenn Moderator

    13,984
    2,015
    Sep 5, 2009
    @bigone5500 can you please upload the unzipped files to the forum so people can view them


    Dave
     
  3. bigone5500

    bigone5500

    712
    121
    Apr 9, 2014
    I would but .ino files are not allowed. Maybe an Admin can change that?

    Most current operating systems have native zip support so I didn't think it would be a problem.

    I have edited the original post to include the code but the 'code' tags have caused part of the sketch to delete. Line 27 should read: lcd.print("Temp: "); // Send the text 'Temp:' to the screen of the display.
     
  4. davenn

    davenn Moderator

    13,984
    2,015
    Sep 5, 2009
    no they don't, WinZip or WinRAR needs to be downloaded and installed, but that's not the point ;)
    its better to make it as easy as possible for the reader/potential helper to view files :)

    what is an .ino file ?

    cheers
    Dave
     
  5. bigone5500

    bigone5500

    712
    121
    Apr 9, 2014
    I can use windows vista, 7, 8, or 8.1 to unzip. Rar files are another beast though. You can create a compressed folder which results in a zip file.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-