zeus2kx
February 28, 2012, 7:45am
1
Hello,
I am using LM335 Temperature sensor. Here is my code:
float celsius = 0, kelvin=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
kelvin = analogRead(0) * 0.004882812 * 100;
celsius = kelvin - 273.15;
Serial.print("Celsius: ");
Serial.println(celsius);
Serial.print("Kelvin: ");
Serial.println(kelvin);
Serial.println();
delay(1000);
}
Output:
Celsius: 41.30
Kelvin: 314.45
Celsius: 41.30
Kelvin: 314.45
Celsius: 41.30
Kelvin: 314.45
Celsius: 41.30
Kelvin: 314.45
41.30 degrees C is unusual. I am testing inside my room where the temperature is 19 degrees C.
Please help me correct readings.
Thanks.
Z
Insert a Serial.print statement to knock out the analogRead(0) result.
zeus2kx
February 28, 2012, 3:46pm
3
runaway_pancake:
Insert a Serial.print statement to knock out the analogRead(0) result.
Thanks for reply.
I added, here is the output.
Celsius: 41.30
Kelvin: 314.45
Analog Read: 644
Celsius: 41.79
Kelvin: 314.94
Analog Read: 644
Celsius: 41.79
Kelvin: 314.94
Analog Read: 645
What can I do to solve this issue?
Thanks.
Z
How do you have it wired up?
Well, your analogRead result means there's about 3.1V (645 * 4.888mV = 3152mV == 310K - 273 = 42C).
Are the wires to the sensor short? They should be as short as possible.
Try a bypass cap at the sensor, 0.1uF from +V to Gnd, too.
5V / 1023 = 4.888mV (per count)
zeus2kx
February 28, 2012, 4:08pm
6
This way
Unlimited space to host images, easy to use image uploader, albums, photo hosting, sharing, dynamic image resizing on web and mobile.
OR
http://img718.imageshack.us/img718/1821/lm355.jpg
zeus2kx
February 28, 2012, 4:15pm
7
runaway_pancake:
Are the wires to the sensor short? They should be as short as possible.
Try a bypass cap at the sensor, 0.1uF from +V to Gnd, too.
5V / 1023 = 4.888mV (per count)
Thanks.
No, wire length is almost like a foot.
zeus2kx
February 28, 2012, 4:25pm
8
Kindly confirm the circuit so that I fix sensor on board itself.
Thanks.
zeus2kx
February 28, 2012, 5:01pm
9
I tried connecting 0.1uF between +V and Gnd but no significant changes. :0
You may be coupling noise into the analogRead with those 1 foot wires.
Better try as short as possible. Your application likely requires remote placement, but try and find out if this helps first.
Your circuit looks like what I've seen recommended.
zeus2kx
February 28, 2012, 6:09pm
11
I soldered on the board but yet no change in readings.
Have you put a voltmeter to the LM335 output (right there on the board)?
If it's "3V" then maybe it's defective.
zeus2kx
February 28, 2012, 6:55pm
13
Nope, I am home, don't have one now but can check tomorrow.
zeus2kx
February 29, 2012, 3:49pm
14
I found the problem that there wasn't any problem just that Arduino was only connected through USB, not with AC adopter.
Thanks all for your support.
Z
But,... I...
Well, OK then.
zeus2kx
February 29, 2012, 8:23pm
16
Please tell what you wanted to add.
Thanks.
You should still get "5V" even using USB.
At least, I do with my "2009".
But, +V_usb has a wide range, too, so that could throw your readings off. Is that it?
zeus2kx
February 29, 2012, 11:30pm
18
Here I add some results:
Only USB - Vcc = 5V
Celsius: 41.79
Kelvin: 314.94
Celsius: 41.79
Kelvin: 314.94
Celsius: 41.79
Kelvin: 314.94
Only USB - Vcc = 3.3V
Celsius: 23.24
Kelvin: 296.39
Celsius: 23.24
Kelvin: 296.39
Celsius: 23.24
Kelvin: 296.39
With adopter - Vcc = 5V
Celsius: 23.24
Kelvin: 296.39
Celsius: 23.24
Kelvin: 296.39
Celsius: 23.24
Kelvin: 296.39
With Adopter - Vcc = 3.3V
Celsius: 3.22
Kelvin: 276.37
Celsius: 3.22
Kelvin: 276.37
Celsius: 3.22
Kelvin: 276.37
Temp reading in case when Arduino was connected through USB only and Vcc = 3.3V is exactly equal to Arduino plugged in with adopter and Vcc = 5 V.
Strange, isn't it?