Newbie - problem reading LM35 sensor - voltage measured differs

Hi,

I just got my spark core and have tried connecting an LM35 sensor to it, but am stumped with the results.
Tinker app gives me a reading of cca 492, and if I convert this to voltage, it should be 0,39 V, right?
If I measure with the voltmeter (measuring between A0 and GND), I get 0,29 V.

I also tried putting 3,3 V to another analog input, and I get 4095 which is fine.

I’ve also added an external LED with the resistor and connected the output of LED to another A input, which gives me 2331, which should be 1,87 V and which corresponds pretty well to voltmeter (1,89V).

What am I doing wrong here?

BTW - the temperature is around 24 Celzius, so maybe my temp sensor is quite off anyway (3 degrees).

I’ve now connected it an arduino clone and it’s weird - the voltmeter shows 0,25, arduino analogread the same.
I take temp sensor to spark core breadboard, voltmeter 0,29, spark core 0,39.

I also tried putting +v to temp sensor from VIN, which shows as 4,78 V at the moment, and got same results.
Stumped. :frowning:

Keep the Spark Core ABOVE the temp sensor or the heat it puts off will cause your temp readings to be high due to it running at 100+ Degrees F.

Not quite sure by what you mean above the sensor, it’s a bit away on the breadboard, however spark core is quite cold to the touch at the moment.

Also, the main problem seems to be with the analogRead measurement which differs from the voltage measured with the voltmeter.

I can’t help with your Analog reading issue but just wanted to warn ya about the warm temp of the Spark Core will throw off your temp readings unless the Spark Core is placed above your temp sensor so all the heat it emits will rise up and not affect your temp readings.

Good luck.

clarity, there were issues with the A/D conversions that are now fixed but I am not sure they have been updated in the Web IDE. I will check and update this post.

UPDATE: Yup, the update has not been pushed to the web IDE yet but is available for users doing local compiling of the code.

Hi @clarity

@peekay123 is right about the ADC code in the webIDE (the “Build” button on the website) being a little bit behind the “master” branch that can try out if you compile your code on your local computer. The “master” branch will move to the webIDE when Spark has fully tested it.

Using the ADC code in the “master” branch, I was able to get analogRead() values that were +/- 1 count from what I calculated, which is all you can ask really.

A few other points worth mentioning:

  • You should use the filtered 3.3V output on the Spark core, which is labelled 3.3V* here

http://docs.spark.io/images/core-power1.jpg

  • You might want to put a bypass capacitor right next to the LM35 from power to ground–they are notorious for picking up power supply noise. Something like 0.1uF to 0.01uF.
  • You 3.3V* might not be exactly 3.3V. It might 3.272 V or 3.354 V and that can throw off your calculations. If you measure it with your voltmeter, you can use that number in your calculations as the full scale (4095) value. It may change if you power the core differently, but to debug everything this is a key step.

bko, regarding the 3.3* pin, I also found that I had problems with some devices whose lower supply tolerance is
3.3v such as a DHT22 temperature/humidity sensor. I had to use a separate 3.3v supply.

@clarity, from the LM35 specs, I noticed that it operates from 4 to 30V so the 3.3v supply will not be adequate. You could use the Vin supply (the USB power) to power the LM35 but you should put a 0.1uf capacitor across the +Vs and GND pins AT the device to act as a noise filter, which is not uncommon from USB power supplies. You will also need to consider that the output of the LM35 may exceed the maximum 3.3v input voltage of the Spark A/D.

Hi, I’m trying run a lm35 but the temperatures are divergents. I’m using this code:
I tried with 1024, 4095 and 5000

tthe pin vs = VIN

for sample now is 25º but the sensor read 35 if I insert it on a freezer the minimum temperature is +22

int analogvalue = 0;
double tempC = 0;

void setup() {
    Serial.begin(9600);// 
  pinMode(A0, INPUT);
  Spark.variable("temperature", &tempC, DOUBLE);
  Spark.variable("analogvalue", &analogvalue, INT);
}

void loop() {
  // Read the analog value of the sensor (LM35)
  analogvalue = analogRead(A0); // 10mV per degree
  ///tempC = (analogvalue * 3.3 / 1024) * 100;
  ///tempC = (analogvalue * 3.3 / 4095) * 100;
     tempC = (analogvalue * 3.3 / 5000) * 100;
  Delay(200);
  Serial.print(tempC);
    delay(2000);
}

@rbbahia, I think you got your answer here already.

Please, don't double post!

1 Like

I am using LM35 and I am getting a bad result.

The temp reading is ok but when I turn on an external LED with Blynk app (or another method) the temp reading increase to 1 or 2 C (10 or 20mV).

What is happening?

Hi @jonamleonel

It sounds like your sensor is too close to your Photon device since when you turn on the LED, more current is needed from the Photon board and it heats up a bit more. Can you try extending the wiring so that the sensor is say 10cm or 4" away from everything else?

I have found that the digital sensors like the Dallas or Bosch ones work better for me.

1 Like

@jonamleonel, do you have a current limiting resistor for the external LED?

1 Like

Yes a 330 ohms, but I notice when a turn on the LED inmediately the temp changes to 2C more. I mean immediately the OUTPUT voltage of the sensor increase to 20mv.

@jonamleonel, can you post a picture of your setup?