It seems, from the jumping values, that the chip is oscillating.
Is the LM35 near the Arduino, or connected with long wires.
Did you try a 100n ceramic decoupling cap (VCC to ground), close to the LM35.
If it works, use better code that uses 1.1volt Aref and averaging.
Here's an example I wrote.
Leo..
// LM35 temp sensor output connected to analogue input A0
unsigned int total = 0; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit
void setup() {
analogReference(INTERNAL); // use the internal ~1.1volt reference | change to (INTERNAL1V1) for a Mega
Serial.begin(9600);
}
void loop() {
// read the sensor
for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
total = total + analogRead(A0); // add each value
}
// temp conversion
tempC = total * 0.001632; // value to tempC >>> change last two or three digits slightly to calibrate temp <<<
tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit
Serial.print("The temperature is ");
Serial.print(tempC, 1); // one decimal place
Serial.print(" Celcius ");
Serial.print(tempF, 0); // no decimal places
Serial.println(" Fahrenheit");
total = 0; // reset total
delay(500); // slows readings
}
Thanks for the reply. It's encouraging to know it may be my ebay sensors. Not yet familiar with INTERNAL. Do I still wire the LM35 to the 5v when using the INTERNAL?
LM35 only inches away from Arduino. Are you suggesting I move it further away?
I'm assuming the component you suggested is a cap.
BillByrd:
Not yet familiar with INTERNAL. Do I still wire the LM35 to the 5v when using the INTERNAL?
LM35 only inches away from Arduino. Are you suggesting I move it further away?
I'm assuming the component you suggested is a cap.
Could you provide a schematic? Thank you.
Tried your code. Values still all over the place.
Yes. power and output is the same.
That sensor outputs 0-1volt with temps from 0-100°C.
If you measure that with default Aref (~5volt), then 1volt gives an A/D value of 1024/~5 = ~205.
That's ~2 A/D values per °C, so a resolution of ~0.5°C.
If you lower Aref (the ruler that measures) to ~1.1volt, then the max A/D value of 1023 is reached at ~1.1volt.
1024 A/D values spread over a temp range of 0-100°C, or ~10 A/D values per °C. About five times better.
No. Close should be fine.
100n ceramic capacitors are essential parts.
You provide the diagram, the code, and a real picture. We check for mistakes.
If there is something wrong with the sensor or the wiring/breadboard, then code won't fix it.
An LM36 has a different temp range and needs different code.
If it's a TMP36, you can supply it from the more stable 3.3volt pin.
Example code below. Temp range of this is about -40C to +55C.
Leo..
// TMP36 temp sensor output connected to analogue input A0
unsigned int total = 0; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit
void setup() {
analogReference(INTERNAL); // use the internal ~1.1volt reference | change to (INTERNAL1V1) for a Mega
Serial.begin(9600);
}
void loop() {
// read the sensor
for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
total = total + analogRead(A0); // add each value
}
// temp conversion
tempC = total * 0.001632 - 50.0; // value to tempC >>> change last two or three digits slightly to calibrate temp <<<
tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit
Serial.print("The temperature is ");
Serial.print(tempC, 1); // one decimal place
Serial.print(" Celcius ");
Serial.print(tempF, 0); // no decimal places
Serial.println(" Fahrenheit");
total = 0; // reset total
delay(500); // slows readings
}
The LM36s arrived a few minutes ago and I popped them into the breadboard immediately. Several of you pointed out that the 36 is not the same as the 35. Yes, I knew that. I was trying to stay with one of the popular retail/hobbyist sources thinking that quality would be more important to them.
And the 36 was the only offering in the LM family from SparkFun or Adafruit. I never cared in the first place about the scale. I didn't matter to me if it was Fahrenheit or Celsius or kelvin or Scoville.
The only thing that mattered to me was some legitimate measure of heat that was stable and affected by finger touch or hair dryer or whatever. I'm glad to say that the SparkFun LM36s did just that. So clearly, the ebay LM35s were crap.
You can save a lot of money on ebay. I'll continue to shop for my goodies there. One just needs to sort out the good vendors from the bad. Thanks for all the help from everyone.
One little thing-- multimetering the pinout with 5v and ground on the other 2 pins is suppose to meter out about 0.75v. The best I can do is about 0.63v with accompanying unrealistic room temp readings. I can work with that. Just glad to have something that consistently reports values.