Hi All, I'm doing a small project with a pair of lm35z sensors, basically I'm trying to keep a telescope as close to ambient temperature as possible without the telescope temp. dropping to dew point. It works standalone or with a gui on the PC. It is supposed to run automatically but has manual override settings to turn the heater on and off.
I have both sensors working, and I can graph the results in processing on the PC, they are also reacting as I expect with temperature changes, so everything is ok in that respect, visual feedback via the gui also appears to be correct too. My only issue is that both sensors are about 2.5cm apart at the moment and seem to be 1deg apart in temp. How can I resolve this issue? Is it even an issue or could it be that they have a 0.5deg accuracy and between them could that explain the 1deg difference?
I'm also wondering if it has anything to do with the way the sensors are wired to the arduino, I'm doing it on a small breadboard atm.
If anyone would like see the code for processing and the arduino just to make sure the error isn't in my code somewhere, let me know and I'll post it.
I have to say I'm a n00b at electronics in general, this is only my 5th electronics project and same with coding, i've done some C++ and basic in the past but nothing for about 5years, so excuse me if my code is a bit rough around the edges although I do believe it is mostly sound.
I don't know about the "z" variant of the lm35, but the lm35 datasheet says +/- 0.25C at "room temperature". Also realize that your arduino has a 10 bit ADC, which means your resolution is 4.88mV steps with a 5V reference. This further translates into ~0.488C steps in the output. That, combined with the +/- 0.25C accuracy of the device, seems to indicate your system is working correctly within the tolerances of the components.
Depending on how you handle your conversion from the 10 bit integer from the ADC to a temperature value, there could also be rounding errors causing additional variation.
I also read somewhere that the L34 /35 sensors ar slow to react to temp. changes. So if one sensor is closer to a heat source than the other it might explain some variance between them. If this is the case then they should show he same temp. after some time of course.
kg4wsv, thanks, I believe it is +-0.5 on the z series, so either way it does help to explain things and has nothing to do with my circuit I take it?
Mikmo, in this instance they don't react inredibly quickly, but I am taking multiple samples, 8 every 200ms then averaging them, I had a bit of a time getting floats passed via serial but believe the code to be sound enough to cope?
The reaction times don't need to be incredibly quick, I'll go for some sort of either self calibration or the user can monitor temps and set the calibration points themselves, I don't expect to see 2 degree drops in the temperatures between ambient and the telescope unless my heater battery has run out
/*
this sketch is PC/Standalone automatic dew heater controller based on the Arduino and 2 lm35dz temperature sensors
this program has been adapted from code for An open-source LM35DZ Temperature Sensor for Arduino.
by Daniel Spillere Andrade , http://www.danielandrade.net http://creativecommons.org/license/cc-gpl
most of the code has changed but as the original idea was Daniels I thought I should give him due respect
(cc) Ian Baker November 2008
*/
int ledPin=13; // variable for the LED, we'll use this as a substitute for the heater until the code is stable
bool heateron = false; // variable for testing whether heater is on or off to avoid unecessary switching
bool override = false; // variable for testing whether the user wants to override the automatic settings
int pin1 = 0; // analog pin 1 scope temperature sensor is connected to this pin
int pin2 = 1; // analog pin 2 ambient temperature sensor is connected to this pin
int incomingByte = 0; // variable for storing incoming data from a PC or other serial device connected to the arduino
float scopec = 0,scopef=0; // scope temperature variables
float ambientc = 0,ambientf=0; // ambient temperature variables
float scopeavg[8],ambientavg[8]; // arrays to load sensor readings for averaging
float maxi = -100,mini = 100; // to start max/min temperature
float maxi2 = -100,mini2 = 100; // to start max/min temperature
int i;
int analog1=0; // variable for storing data read from analog pin 1
int analog2=0; // variable for storing data read from analog pin 2
void setup()
{
Serial.begin(9600); // start serial communication
pinMode(ledPin, OUTPUT); // make sure the onboard LED is used and set to output
}
void loop()
{
for(i = 0;i<=7;i++){ // gets 8 readings from each of the sensors
analog1=analogRead(pin1);
analog2=analogRead(pin2);
scopeavg = ( 5 * analog1 * 100.0) / 1024.0; ambientavg = ( 5 * analog2 * 100.0) / 1024.0; _ scopec = scopec + scopeavg*; ambientc = ambientc + ambientavg; delay(200); } scopec = scopec/8.0; // better precision as we are averaging 8 sensor readings ambientc = ambientc/8.0; // better precision if(scopec > maxi) {maxi = scopec;} // set max scope temperature if(scopec < mini) {mini = scopec;} // set min scope temperature if(ambientc > maxi2) {maxi2 = ambientc;} // set max ambient temperature if(ambientc < mini2) {mini2 = ambientc;} // set min ambient temperature // if the serial port has had data sent to it we store the value of the incoming byte* if (Serial.available() > 0) { * // read the incoming byte: incomingByte = Serial.read(); } // now we've got the byte from the serial port we test to see if it's an A/a or a Z/z* // or an M/m // if it's an A/a then we flag that the user is overriding the autmatic settings // so the heater will stay on until the user presses the Z/z key * if(incomingByte == 65 || incomingByte==97){ // its an A/a so turn the heater on if its off and let the automatic system know that its being* * // overriden by the user* * override=true; if(!heateron){ heateron=true; digitalWrite(ledPin,HIGH); } incomingByte=0; } // its an Z/z so turn the heater off if its on and let the automatic system know that its being* * // overriden by the user* * if(incomingByte == 90 || incomingByte == 122){ override = true; if(heateron){ heateron = false; digitalWrite(ledPin,LOW); } incomingByte=0; } if(incomingByte == 77 || incomingByte == 109){ // it's an M/m so we turn off manual override and pass back control of the heater circuit to the arduino* * override = false; incomingByte = 0; } // now we've got the scope and ambient temperatures we need to test to see whether* // the scope temperature has dropped by about 2degC if it has turn the heater on // but only do it if the heater isn't on already and the manual override setting // hasn't been set if(heateron == false && ambientc-scopec>=1.9 && override == false){ heateron=true; digitalWrite(ledPin,HIGH); } // we need to test to see if the ambient and scope temp are close enough to turn the heater off // if they are within 0.5degC then turn it off but only if its on and the override setting // hasn't been set if(heateron==true && ambientc-scopec<=0.5 && override==false){ heateron=false; digitalWrite(ledPin,LOW); } // send the data to the serial port, 6 bytes in total ready for processing Serial.print(ambientc*10,DEC); // ambient temperature multiplied by 10 to recover floating point value at the other end, 3bytes Serial.println(scopec*10,DEC); // scope temperature multiplied by 10 to recover floating point value at the other end, 3bytes // reset the values scopec = 0; ambientc = 0; delay(200); // delay before loop } [/quote]_
I believe it is +-0.5 on the z series, so either way it does help to explain things and has nothing to do with my circuit I take it?
Yep, looks like things are working fine within stated tolerances/precision. Given the +/- 0.5C and 4.88mV/step on the ADC, you could see as much as 1.487C difference between the two (or a bit more, I didn't add ADC error) and everything would be working correctly.