I am trying to read the value of a LM335 (National Semiconductor) temperature sensor.
The sensor linearly outputs a voltage based on the temperature. You just multiply the voltage by 100, and you get the temperature in kelvin (subtract 273.15 from that and you get celsius).
The LM335 circuit is attached as so,
5V to 1000 ohm resistor to Pin 8 of LM335 with Pin 1 of LM335 to ground. I also run a wire from Pin 8 to the arduino analog pin 1.
I then run the code below, It reads the sensor converts the value to celsius, multiply by 10, and then outputs the value to the computer via serial.print.
It also takes an average, I was trying to minimize the fluctuation.
The problem is that the values printed to the screen fluctuate more than they should. I can test the circuit by attaching a voltmeter to pins 1 and 8 of the LM335. The value coming out does not fluctuate by even 1mV. I get a fluctuation of 3-4 degrees (approx 30-40mV) once the values get into the arduino.
Could somebody help me fix the problem so I get a lot less fluctuations.
here is my code
//We always have to include the library
#include <SoftwareSerial.h>
int InputPin=1; //This is which analog input pin i'm using
void setup(){
// start serial port at 9600 bps:
Serial.begin(9600);
pinMode(InputPin, INPUT); // sets the digital pin as output
}
void loop (){
int Time=2000; //This is the total time between averaged results
float AverTempC=0; //This will have the average temperature
int Aver=10; //The number of readings to average
int var=0; //The iteration variable
float TempK=0; //This will hold the temperature in kelvin
float TempC=0; //This will hold the temperature in celcius
while(var<Aver){
float RawTemp = analogRead(InputPin); // reads the input pin gets the uncoverted temp value
// RawTemp is 0 < RawTemp < 1023
// InputPin is 0 InputPin < 5 Volts
float ConvertConstant = 5.0/1023.0;
TempK = 100*RawTemp*ConvertConstant; //The Temp in Kelvin the 100 comes from the LM335 datasheet the sensor does 10mv/(Degree Kelvin)
TempC = TempK-273.15; //Converts Kelvin to Celcius
Serial.print(TempC*10,DEC); // debug value you need to divide by 10 to get the correct value
Serial.print(" "); // debug value you need to divide by 10 to get the correct value
AverTempC=AverTempC+TempC; //Each time the loop iterates it adds the value
++var;
delay(Time/Aver);
}
AverTempC=AverTempC/Aver; //This gets the average value
TempOutput(AverTempC);
Serial.print(" Average ");
Serial.print(AverTempC*10,DEC); // debug value you need to divide by 10 to get the correct value
Serial.println(" ");
}
The value coming out does not fluctuate by even 1mV.
I assume this is a digital voltmeter, if so it won't be as sensitive to noise as the Arduino because of the longer integration time a DVM uses.
What have you done with the adjust input. I suggest a 0.1uF capacitor to ground to prevent noise being picked up and transferred into the system.
Also keep all the connections short.
Finally a 0.1uF cap across the analogue input will also help but use it as a last resort because that also limits the response time, but not by much.
I found that ADC input fluctuations decreased when arduino was powered by an external power supply. Noises may come from the computers via a USB cable.
To make sure I'm understanding, I should put the capacitor between the ground pin on the timer (Pin 4), and the ground on the arduino?
When I set the DVM to connect to pins 4 and 8 without the capacitor, I can get the temp with no fluctuations, when I attach the capacitor between pin 4 and gnd. I read 5v instead of the 2.94v for the temperature. Am I supposed to attach the cap in parallel with a wire to ground?
I tried to have the arduino average a bunch a values, like in the example that was given above, and it didn't get me the accuracy I wanted.
I will also be trying to power the Arduino externally.
I think you need to read the analog input information from the AVR data sheet ( http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf )
to get an idea of what kind of accuracy you can expect from a AVR 10 bit analog input.
From the data sheet:
? 10-bit Resolution
? 0.5 LSB Integral Non-linearity
? ± 2 LSB Absolute Accuracy
If the range of input voltage is 0-5vdc then the resolution is in 5mv steps, then +/- 2 LSB bits represents +/- 10mv accuracy. There is also the accuracy of the reference voltage used for the A/D conversion to factor into it also.
If you wish better accuracy then that one needs to go with an external A/D chip with say 12 or 14 bits of precision. Also for high accuracy there has to be special attention given to circuit wiring layout and the precision of the voltage reference used by the A/D circuitry.
Define your accuracy and resolution requirements precisely and the best method can be determined.
Lefty
PS: Hanging a bunch of capacitors on the analog input pin my make the number more steady , but doesn't do a thing about the accuracy of the number.
I'm using LM35 which outputs 10mV/degrees C.
The raw output voltage of LM35 is too small for arduino,
I'm amplifying the output tenfold by Op-Amp.
And I'm putting a 470nF capacitor to decrease fluctuations.
My cable between LM35 and arduino is very long, about 50 meter, the fluctuation seems to be relatively-large.
With this configuration, I can be getting stable temperature data.
The capacitor doesn't cause the response time problem for my purpose.
I tried several capacitance, I found the 470nF capacitor is best for my situation.
My cable between LM35 and arduino is very long, about 50 meter
That's your problem.
In my first post I did say:-
Also keep all the connections short.
Is the amplifier at the Arduino end? It would be much better at the sensor end. That way pickup will not be amplified. It would be even better to over amplify at the sensor and pot down at the arduino.
OK but 50 meters of cable is still a long way to send such a small analogue signal. You can try doubling the gain of the amplifier and halving it at the arduino but it will not solve the pick up problem only lessen it.
I am surprised the results are as good as you say. You should have used a sensor with a digital output and then transmitted that signal with the appropriate line drivers and receivers.
I was surprised too.[ch12288]I thought the output of Op-Amp decayed during the signal went through the long cable.
I know it is far from an ideal configuration, but it works.
I will try to use a temperature sensor with I2C interface. But the skech may become complex.