Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: measuring Temperature LM35

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    12

    measuring Temperature LM35

    Hello there,

    I'm trying to implement LM35CAZ on teensy 3.2.
    i attach the configuration on this thread, and the code i am been using.

    https://imgur.com/a/2itS20M

    The problem is that i don't know why the measuraments are wrong the values are like 30 C and this is
    definitely wrong.

    If you can help me with this issue i'll appreciate it.

    CODE:
    float tempC;
    int pinLM35 = 15; // i have been using pin 15 for measurements

    void setup() {

    Serial.begin(38400);
    analogReference(INTERNAL); // Is The reference 1.2 V?
    }

    void loop() {
    tempC = analogRead(pinLM35);

    // Calculating temperature
    tempC = (1.2 * tempC * 100.0)/1024.0;


    Serial.print(tempC);

    Serial.print("\n");

    delay(1000);
    }

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,000
    Try powering LM35 with 3.3v and get rid of INTERNAL ref and use 3.3 in calculation, and this sketch works for me
    Code:
    float tempC;
    int pinLM35 = 15; // i have been using pin 15 for measurements
    
    void setup() {
    
      Serial.begin(38400);
      //  analogReference(INTERNAL); // Is The reference 1.2 V?
    }
    
    void loop() {
      tempC = analogRead(pinLM35);
    
      // Calculating temperature
      tempC = (3.3 * tempC * 100.0) / 1024.0;
    
    
      Serial.print(tempC);
    
      Serial.print("\n");
    
      delay(1000);
    }
    25.46
    25.46
    25.14
    25.14

    EDIT: also works with analogReference(INTERNAL); and 1.2 in tempC calculation

    I think your wiring is reversed for Vcc and GND. Facing the square face of the LM35, left pin is 3v3, middle analog out, and right is GND. Hopefully, you didn't damage the LM35.

    Click image for larger version. 

Name:	LM35-temperature-sensor-pinout-1.png 
Views:	24 
Size:	31.2 KB 
ID:	13885
    except you should use 3.3v. actually at 25C LM35 voltage output is 0.255 v, so Vcc of 3.3v or 5v should be OK.
    Last edited by manitou; 05-24-2018 at 07:57 PM.

  3. #3
    Junior Member
    Join Date
    May 2018
    Posts
    12
    thank for you help now is working perfectly

  4. #4
    Recommended minimum supply voltage is 4 Volts (http://www.ti.com/lit/ds/symlink/lm35.pdf) and minimum temperature reported with a single supply is 2 C. I hit this problem before and feed the LM35 from the Vin pin. Also the internal reference voltage is specified as 1.195 Volts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •