Go Down

Topic: LM335A and arduino (Read 1 time) previous topic - next topic

finarfin

Hi all,

i've tried to use a lm335a themperature sensor with my arduino uno board. But i'm not sure if i'm doing everything correctly. (I'm very new to arduino and electronics).

I connected the sensor to arduino as shown in figure:


And the code that i used is that:
Code: [Select]

int pin = 0; // analog pin

void setup()
{
 Serial.begin(9600); // start serial communication
   pinMode(12, OUTPUT);    
}

void loop()
{
digitalWrite(12,HIGH);
float valRead = analogRead(pin) * 0.004882814;
float  k = ((100*valRead)-273.15);
Serial.println(k);
delay(1000);
}

Now i'm not sure about the results (i did not checked the temperature in my room) are here: http://pastebin.com/uMCEFvGQ
As you can see the temperature seems to be abbout 16-17 degrees.
The fact that i don't understand are why the values change so many times (and sometimes it have very strange values, like 5.66 degrees) Notice that in after the 50th value i put my fingers on the sensors.

My questions are:
1. The sensor is wired correctly?
2. These values can be ok?
3. THere are some errors in my code?

Thanks a Lot!
Ivan
I believe in Fairies :)

MarkT

It seems you are sometimes seeing a few bad values but most are OK - perhaps there is some electrical noise causing the rogue readings?

You can take several readings in succession and average them to help reduce the noise.  Perhaps a small capacitor from the analog pin to ground (say 1nF) could help.

If you have long wires then you might be picking up RFI or switching transients from household appliances - use screened cable for low level signal wires of any length.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy