Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

fluctuating LM35 values

temp sensor LM35 AnalogInput.Reading

  • Please log in to reply
3 replies to this topic

#1 donnmo

donnmo

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationSpokane area

Posted 29 October 2013 - 10:15 PM

I've attached an LM35 to both a Netduino and a Netduino Plus. The readings fluctuate unexpectedly on both boards.

 

The attached screenshot shows three columns of data: The first is the value retrieved from the AnalogInput.Reading method; the second is the temperature in degrees Celsius; the third is the temperature in degrees Fahrenheit.

 

These readings were taken when the LM35 was sitting on my desk in a room that's showing 75 degrees Fahrenheit on a digital thermometer in the same room. (The readings are within an acceptable range--but--I don't understand the fluctuations.)

 

Has anyone else observed this with the LM35?

 

Thanks!

--Donn

Attached Files



#2 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 03 November 2013 - 11:40 PM

I've never tried an LM35 but I've had similar fun time with a TMP36.

 

Assuming they work on a similar principle, what your actually seeing is fluctuations in the input or reference voltage. This could be caused by any number of things in your hardware setup. Like what type of power supply you are using.

 

My first guess would be to try decoupling the power fluctuations using small ceramic capacitors. If you had access to a scope you could check just how steady that voltage is at various places. Another thing you can do is take a series of readings and work out the average to take out any freak line fluctuations. I've got a little code i use for getting readings randomly off my analogue pins. I know it's not perfect and it's not fast but it works for me.

class MyAnalogPort    {        private static object Analog_Lock = new Object();        public static int Read(int port, double ratio = 1023, bool invert = true, int sample_size = 5, bool dispose = true)        {            lock (Analog_Lock)            {                SecretLabs.NETMF.Hardware.AnalogInput sample_port = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0);                if (port == 1) { sample_port.Dispose(); sample_port = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A1); }                if (port == 2) { sample_port.Dispose(); sample_port = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A2); }                if (port == 3) { sample_port.Dispose(); sample_port = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A3); }                if (port == 4) { sample_port.Dispose(); sample_port = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A4); }                if (port == 5) { sample_port.Dispose(); sample_port = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A5); }                int sample = 0;                int[] read = new int[sample_size];                for (int Counter = 0; Counter < sample_size; ++Counter)                {                    read[Counter] = sample_port.Read();                    Thread.Sleep(Counter);                }                sample = Convert.ToInt32(AverageElements(read).ToString());                double input = (ratio / 1023) * sample;                if (invert) { input = ratio - input; }                sample = (int)System.Math.Round(input);                sample_port.Dispose();                return sample;            }        }    }public static double AverageElements(int[] arr)        {            lock (Calc_Lock)            {                int sum = 0;                for (int Counter = 0; Counter < arr.Length; Counter++)                {                    sum += arr[Counter];                }                return sum / arr.Length; ;            }        }

It takes 5 readings by default and not at the same time distance apart. Just in case there is a set frequency of interference.

 

Hope that helps.

 

Grant.



#3 donnmo

donnmo

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationSpokane area

Posted 04 November 2013 - 06:47 PM

Grant: Many thanks for the reply. (Appreciate it!)

 

I'll probably implement the software "smoothing" -- similar to what you'd done. (I'd noticed other postings since my original post and it appears that the issue is fairly common and the workaround is to take an average of the readings.)

 

--Donn



#4 dcimma

dcimma

    New Member

  • Members
  • Pip
  • 1 posts

Posted 04 November 2013 - 10:04 PM

Not sure if you solved your problem, but the LM35 can oscillate pretty bad sometimes.  I have a few of them on 30 ft runs around my shop monitoring solar system temps.  Look at the LM35 data sheet, there are a few suggestions like a bypass cap and series resistor if you have long runs and high capacitance.  I ended up using a 10uf cap across the output to solve my erratic readings problem.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.