Arduino Forum

Using Arduino => Programming Questions => Topic started by: venturejordi on Jan 11, 2014, 01:33 am

Title: LM335
Post by: venturejordi on Jan 11, 2014, 01:33 am
okay I cant figure this out. I know i had this sensor working with the arduino at one point.

I have my circuit set up just like this:
https://lh6.googleusercontent.com/-RsfzgB4YwGk/TXoz9VYShII/AAAAAAAAAFk/KQ5fouPUASA/s1600/Untitled%2BSketch_bb2.png (https://lh6.googleusercontent.com/-RsfzgB4YwGk/TXoz9VYShII/AAAAAAAAAFk/KQ5fouPUASA/s1600/Untitled%2BSketch_bb2.png)

My code is
Code: [Select]

//initializes/defines the output pin of the LM335 temperature sensor
int outputpin= 0;
//this sets the ground pin to LOW and the input voltage pin to high
void setup()
{
Serial.begin(9600);
}

//main loop
void loop()
{
int rawvoltage= analogRead(outputpin);
float millivolts= (rawvoltage/1024.0) * 5000;
float kelvin= (millivolts/10);
Serial.print(kelvin);
Serial.println(" degrees Kelvin");

float celsius= kelvin - 273.15;
Serial.print(celsius);
Serial.println(" degrees Celsius");

float fahrenheit= ((celsius * 9)/5 +32);
Serial.print(fahrenheit);
Serial.println(" degrees Fahrenheit");

delay(3000);
}


output:
Code: [Select]

43.46 degrees Kelvin
-229.69 degrees Celsius
-381.45 degrees Fahrenheit


I dont know why this isn't working. I've tried many programs none of them seem to work. I dont know what im doing wrong.
Title: Re: LM335
Post by: venturejordi on Jan 11, 2014, 01:34 am
Im trying to get it to read the temperature and its a LM335 temp sensor.
Title: Re: LM335
Post by: Jiggy-Ninja on Jan 11, 2014, 01:47 am
Hold your finger on the sensor. Does the measured temperature increase, or stay the same?

BTW, it's good form to post a datasheet when you're asking about a specific part.
Title: Re: LM335
Post by: venturejordi on Jan 11, 2014, 01:54 am
it seems to -232 to -233 when i hold the sensor.
Title: Re: LM335
Post by: venturejordi on Jan 11, 2014, 02:12 am
k will i give up this is too much work.
Title: Re: LM335
Post by: Honduras on Jan 11, 2014, 07:55 am


Code: [Select]

//initializes/defines the output pin of the LM335 temperature sensor
int outputpin= 0;
//this sets the ground pin to LOW and the input voltage pin to high


I'm glad you put in the comments. They give me a starting point.

As I understand it, this statement creates a variable name 'outputpin' and assigns the value of 0 to it. It does not assign the variable name 'outputpin' to the microprocessor's analog 0 pin, which is what I assume you want to do.

Also, although I haven't got to Analog pins yet, digital need to be assigned a data flow direction in the Setup Function, with the pinMode Function, or am I mistaken about this?

Anyway, you have to let Arduino that it is a pin, what pin it is, and whether it is a data source or data sink before you can use it for anything. With my limited knowledge, it looks like what you have actually done is:
1. Create an address of a block of memory large enough to hold an Integer.
2. When you create it you put a 0 in it.
3. You then attempt to read data from it (even though the variable name suggests it is for output) using the analogRead Function. I'm surprised you don't get an error from that.
4. Then you assign the 'returned' value to an integer.
5. Then you perform several analog data conversions on it.

I would suggest your results would be a lot like Forrest Gump's box of chocolates. It probably wouldn't take more than a few minutes to fix those issues. The rest of the sketch looks pretty good to me.
Title: Re: LM335
Post by: Robin2 on Jan 11, 2014, 09:12 am
Can you describe your wiring. It's too much trouble to look up the datasheet and try to figure out whether you have things connected properly.

I'm using an LM335 with no trouble to control my fridge so you must have something wired incorrectly.

@Honduras, I think the OP's code is OK. He is creating a global variable with a value of 0 and using that to identify which analog pin to read.

...R