5 Replies Latest reply on May 2, 2016 1:26 PM by Intel Corporation

    Temperature Measurement using LM35 Sensor

    hegedus@alum.mit.edu

      Hi,

       

      I have a Galileo Gen 2 and I have connected an LM35 based temperature sensor from DFRobot.  Here is the link to the sensor.

       

      I have connected it to A5 on an I/O Expansion shield also from DFRobot and I am using an external power supply to power the Galileo.  I checked the power at pins with a dvm and get 4.95-4.96V and it is very steady.

       

      I have a very simple sketch to read the values and send them to the serial monitor.  I try this in 10 bit and 12 bit resolution.  The values and the range seem quite large and the noise signal is not a normal distribution, more random.  The values scale exactly as anticipated in going from 10 bit to 12 bit.

       

      the temperature conversion is 0.010mV/C so these ranges are quite large (70-35=35).  35/1024*5V = 0.17V which translates to 17 degrees.  The sensor was just sitting in air next to me.

       

      Does any one have data to compare?  When I look online most discussion refers to uncontrolled Vcc but I measured it and it seems stable.

      Temperature Readings.png

       

      // the setup routine runs once when you press reset:

      void setup() {

        // initialize serial communication at 9600 bits per second:

        Serial.begin(9600);

        analogReadResolution(12);

      }

       

       

      // the loop routine runs over and over again forever:

      void loop() {

        // read the input on analog pin 5:

        int sensorValue = analogRead(A5);

        // print out the value you read:

        Serial.println(sensorValue);

        delay(200);        // delay in between reads for stability

      }

        • 1. Re: Temperature Measurement using LM35 Sensor
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi hegedus@alum.mit.edu,

           

          Unfortunately, I don't have the same temperature sensor that you are using, the one I have is the LM358. I did a similar test using 10 bits and 12 bits resolution and I got the values attached at the end of this post. I know you are using a different sensor but I attached the values just in case you want to check them. You will notice that I got similar values in each test.

           

          My recommendation for you is to check the sensor output by converting the value obtained into voltage units. It might be that the ADC resolution is not appropriate for the sensor. For example, if the sensor provides an output from 0V to 1V while the ADC range is from 0V to 5V, you won't get accurate results.

           

          According to your results, you are getting values from 0.17V to 0.34V. That is a very small range that can vary a lot and consequently you won't get accurate results. If the ADC range is from 0V to 5V, ideally you should have a signal that varies in that range. I recommend you to use a signal conditioner to interface the sensor with the Galileo board: https://en.wikipedia.org/wiki/Signal_conditioning

           

          Regards,
          Diego

          • 2. Re: Temperature Measurement using LM35 Sensor
            RGee

            There are a couple of things going on here.

             

            Yes, I have some data to share in a post here Easy temperature measurement with the LM35 . My experience is that the chip works well with 10 bit A2D (and better with 12 bit A2D which the original Galileo has).

             

            You have a very small pause in your loop of 200 milliseconds. I would change that to 2 seconds or more. Change delay(200) to delay(2000) and see what you get.

             

            For this chip, the long conversion formula that I like is:

            TemperatureC=LM35DZout * ((GalVout * ConMV / A2Dsteps) / Voltsteps);

            These should be defined as type float

             

            LM35DZout is the analog pin reading.

            GalVout is the Galileo voltage (you measured yours at 4.95)

            ConMV is 1000 and is a constant to convert to millivolts.

            Voltsteps is10 - the number of millivolts for 1 degree (C) **Note that the chip is calibrated for 10 millivolts/degree C (not  0.010mV/C) which you had written.

            A2Dsteps=1024;  // Gen 2 is 10 bits or 1024 steps (0-1023)

             

            This is sometimes shortened to Temp=(500 * AnRead) /1024; For 5.0 volts as a reference and a 10 bit A2D it works (but I still like my way better

             

            So, I agree that you should collect and plot the data as Temp C.

             

            Also, there is something that bothers me about the board. The schematic shows only the chip and a capacitor. The capacitor is fine and I probably should have used one. That's not the problem. What I see from looking at the board is the LM35 and TWO surface mount chips - likely a capacitor and a resistor. That potential resistor bothers me as it is typically used to give the full range of the chip. See the data sheet. You would then get output of 1500 millivolts at 150 C and -550 millivolts at -55 C - that is the full range: 150 C to -55 C. But the resistor is tied to a negative voltage. You are using ground (0v) only and no analog reference voltage. Maybe it does not make any difference for the range of 2 C to 250 C which is the range without the resistor. Nevertheless, keep it in mind.

             

            Finally, The Galileo Gen 2 has only a 10 bit A2D. Using the statement analogReadResolution(12) on the Gen 2 does NOT give you 12 bit A2D. It gives you the 10 bit A2D value shifted with zero padding for the two LSBs.  I and others have written about this before. You can't gain resolution that way. You will get a larger number but only by shifting the value and adding zero LSBs. It's not a bad command because it allows for compatibility, but a 10Bit value/1024 will yield the same number as the forced 12 bit value/4096.

             

            Hope this helps and please let us know how it works out.

             

            Cheers.

            • 3. Re: Temperature Measurement using LM35 Sensor
              hegedus@alum.mit.edu

              Hi,

               

              Thank you very much for you detailed response.  Per your suggestions I put together this sketch

               

              */

                float ConMV=1000.0;   //Conversion constant from Volt to mV

                float GalVout =4.95;  //Measured Vcc

                int A2Dsteps = 1024;  //resolution of ADC

                float Voltsteps =10; // 10 mV/C

               

               

               

              // the setup routine runs once when you press reset:

              void setup() {

                // initialize serial communication at 9600 bits per second:

                Serial.begin(9600);

              }

               

               

              // the loop routine runs over and over again forever:

              void loop() {

                // read the input on analog pin 0:

                int LM35DZout = analogRead(A5);

              float TemperatureC=LM35DZout * ((GalVout * ConMV / A2Dsteps) / Voltsteps);

                // print out the value you read:

                Serial.print(LM35DZout);

                Serial.print(",");

                Serial.println(TemperatureC);

                delay(2000);        // delay in between reads for stability

              }

               

              temperature.png

               

              and the corresponding LM35DZout values

              a2d values.png

               

              Now I replace the temperature sensor with a light sensor and record the A2D values with the same sketch.

              light sensor.png

               

              The readings are very stable.  Note the scales for the A2D readings both have ranges of 100. The Galieo and power supply are working fine. I believe the temperature sensor is defective or it's design with the resistor as you pointed out is faulty.

              • 4. Re: Temperature Measurement using LM35 Sensor
                hegedus@alum.mit.edu

                Hi,

                 

                An update.  I just got a standard Arduino Uno R3 and tried the temperature sensor.  The sensor Arduino Uno R3 works completely as expected.  Readings are stable and when I put heat to the sensor (just put a thumb on it), the readings climb as expected and decrease when I release.

                 

                I also go a second sensor and the readings on the Galileo are still unstable.  So is the Galileo malfunctioning?

                 

                Andy

                • 5. Re: Temperature Measurement using LM35 Sensor
                  Intel Corporation
                  This message was posted on behalf of Intel Corporation

                  Hi hegedus@alum.mit.edu,

                  Have you had any other issues with the board? I don't think the board is malfunctioning. The ADC is different and that might be causing this. Was the second sensor you tested another LM35? 

                  According to the test you did with the light sensor, you got stable values, but the voltage range was higher than the range of the temperature sensor. I recommend you to check the range of the analog output of the sensor. If the range is too low, the values read won't be very stable.

                  Regards,
                  Diego