Yes it does. The compiler is clever enough to work out that you meant A0 instead of D0 after an analogRead call.
But it's indeed better to use A0 to stop confusion, and to use better names and const byte for pin numbers.
const byte tempPin = A0;
An LM35 has an output of 10mV/degreeC, and Arduino's A/D with default Aref is ~5mVper step.
That means you can only have a resolution of 0.5C at best.
A two decimal place readout (0.01C) is wishful thinking.
You can improve resolution by using 1.1volt Aref in setup().
That increases resolution to 0.1C.
Then use Serial.print(celsius, 1); // one decimal place
But don't start improving things if you haven't got it working yet.
The LM35 might need a 100n cap between 5volt and ground, right next to the chip.
And some (fake) chips will never work.
One day you will discover the much easier to use DS18B20.
Leo..
Try this sketch if your have your LM35 working.
Leo..
// LM35_TMP36 temp
// works on 5volt and 3.3volt Arduinos
// connect LM35 to 5volt A0 and ground
// connect TPM36 to 3.3volt A0 and ground
// calibrate temp by changing the last digit(s) of "0.1039"
const byte tempPin = A0;
float calibration = 0.1039;
float tempC; // Celcius
float tempF; // Fahrenheit
void setup() {
analogReference(INTERNAL); // use internal 1.1volt Aref
Serial.begin(9600);
}
void loop() {
tempC = analogRead(tempPin) * calibration; // use this line for an LM35
//tempC = (analogRead(tempPin) * calibration) - 50.0; // use this line for a TMP36
tempF = tempC * 1.8 + 32.0; // C to F
Serial.print("Temperature is ");
Serial.print(tempC, 1); // one decimal place
Serial.print(" Celcius ");
Serial.print(tempF, 1);
Serial.println(" Fahrenheit");
delay(1000); // use a non-blocking delay when combined with other code
}
thanks to all for reply me..
i have also try int inpin = A0; ,int inpin = 0;
now
i am sharing my wiring & reading of LM35 in serial monitor,,
...... please see in attachment..
reading data is not increasing in sequecne here..., it is increasing & decreasing in random...
i think ,in correct result reading should be increasiing low to current (slowly),
now you are requested to tell me , what is wrong in this project
Wawa:
One day you will discover the much easier to use DS18B20.
Leo..
Best advice so far in this thread
I've been struggling a long time to get the analog readings right with LM35 sensors. Use a OneWire device instead. Considering the code size I spent to catch fluctuating reference voltage and/or one-time spikes when switching heavy loads there is not much overhead if you are just using the Onewire library functions
Cap the cap+ to signal wire and cap- to ground. You could have a bad and crappy sensor.
Also you are using sending a calculation of a float value which could come across funky thru usb. Try declaring the value of "(celsius * 9)/ 5 + 32 " in a variable first.
Finally make sure your baud speed on the PC side is set to 9600. The amount and frequency of the zeros make me think data translation issue.
thank to all of you ,
on your advice, i tried capistor. electronic store keeper gave me 10uf instead of 100n because of lack of 100n
in local store. after connecting it in circuit , i saw it is working. but reading is not crossing (8.30 Degree) where my room temp is great than 20 Degree.
i think use of capistor is better than alone LM35.
actually , i want to use this project in a heating theorapy machine. which will auto on/off by relay according to given temperature limit. so....
For correct reading
should i replace 10uf cap with 100nf.????? or any more