LM35 Temperature Sensor

I have read all the threads on here about this sensor, I have tried all the code.

In the end I still am left with this sensor reading about 2 degrees off of what it should be. I have noticed no one in any thread has actually got the correct reading out of this thing with a photon, literally works perfect with my ardruino.

Is this a failure on the photons part that it cant read a simple sensor properly or some thing else I am missing here?. I love the photon but this is at least the third sensor it can read properly that my arduino reads with out a hitch

I am wired to the 5 volt pin, powered by usb, one ground, one to A0 of my photon. My code is below:

 int analogvalue = 0;
double tempC = 0;
char *message = "my name is particle";
String aString;

void setup()
{
  // variable name max length is 12 characters long
  Particle.variable("analogvalue", analogvalue);
  Particle.variable("temp", tempC);
  if (Particle.variable("mess", message)==false)
  {
      // variable not registered!
  }
  Particle.variable("mess2", aString);

  pinMode(A0, INPUT);
}

void loop()
{
  // Read the analog value of the sensor (TMP36)
  analogvalue = analogRead(A0);
  //Convert the reading into degree celcius
  tempC = ((analogvalue * 3.3)/4095) * 100;
   Serial.print(tempC );
   Serial.print("\n");
  delay(2000);
}

I notice some codes have a -500mv option in them which turns my reading into the same temperature only negative (-25.3), still off by around 2.

Any ideas/help is appreciated.

I have used LM35 sensors and they work great with an op-amp configured as a voltage follower to drive the ADC input. Using a separate or filtered power supply to temp sensor also helps a bit since the WiFi module can be electrically noisy.

The problem is really that the ST-Micro ARM used on Particle products is not setup to read a high-impedance output like that of the LM35. The Arduino (Uno at least) has an op-amp built-in in front of its ADC.

1 Like

ahhh ok thanks for the info bko, so the long and the short of it is that the photon is not as well built (not a shot at particle) in that particular area as far as ADC is concerned, so if I use the digital version of this sensor it will probably work a lot better?

I have the UNO as my arduino, does the Electron Suffer from this same shortcoming? I have that unit as well.

I believe that all the ST-Micro processors in the Particle devices has essentially the same ADC performance. The op-amp is a low-cost part (around $1.00) and a good fix if you want to try it.

I have also had good results with the Dallas/Maxim DS18B20 one-wire series.

One other thing to note is that the Core (before the Photon) was a fairly warm chip and raised the temp of its breadboard a few degrees above ambient. So physical isolation on a couple inches of wire might be a good thing to try. The Photon runs cooler but it still could be warming things up a bit.

I’ll try that out, thanks for the tips.

My sensor is far away from the chip for the reason you mentioned above.

On a side note, being that this part is so cheap any idea why they wouldn’t have just put this function/hardware in there.

Maybe not enough room or something.

Thanks again for the help

Just some thoughts

  1. you'd need to have that for each A pin
  2. since not everybody needs it and may not want to pay for that
  3. it would make the device bigger and not everyone might like that either
  4. adds power consuption
  5. might interefere with OUTPUT functionality
    ...

All fair points, arduino just did it so perfect I was kind of like “Seems rather silly not to have this 20cent part put in”. Now I know for the future about this little snafu and how to fix it though. Help was great.

1 Like

@Keaner, just to add some clarification:

  • Arduino uses Atmel micro-processors and the Uno uses the ATMega328 which runs at 16MHz.
  • The ATMega328 has 10-bit A/D converters with, as mentioned earlier, an op-amp at the input of the A/D stage. The ST Micro STM32F205 used in the Photon and Electron runs at 120MHz and has 12-bit A/D converters without said op-amp.
  • ST Micro chose to leave the A/D signal conditioning up to the designer. The “great” feature on the Atmel part may not be desirable in many situations.

The Atmel processors are very good but more expensive than ST processors. ST processors are used extensively in embedded products, including the Pebble watch! Your specific use-case can be resolved with a different sensor, typically digital. These allow more flexibility in pin selection and device configuration options not available on analog devices like the LM35. :wink:

2 Likes

Thanks for some more info. My biggest thing for this particular situation was more “How the heck am I supposed to know that as a noob”. I did read documentation on both for a long time before I asked, checked all the threads and I found maybe 1 that mentioned something about the op amp lol

I really like the photon and it’s capabilities, the webhooks are great. I’m a web dev so that side of the house is what I really appreciate.

With your guys help on this sensor I was able to rig up a nice little demo of cloud connected neopixels that vary color based on temperature localy as well as sending this to my own DB to store the values for visualization later.

Thanks for all the info and help. Cant wait to build some more awesome projects with this and the electron

3 Likes

@Keaner The LM35 Temp sensor is very dependant on the voltage supply it has. In your formula I see that you are using a value of 3.3V - have you measured this accurately? Being off by 0.1V will cause the reported temperature to change by almost 1.5°C.
I have also founf that the LM35 sensors behave better when the supply voltage is higher - you could try measuring and connecting it to the Vin pin (pin 1) which should be at around 4.8V.
Anyway, the more accurate you are with values in your calculation, the better result you will get.