1
votes

I have arduino uno r3, temp sensor lm335z and 2 led. I found this code in internet

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(10000); 
}

and works great with this schema

temp only

I add two led with this code:

float celsius = 0, kelvin=0;
int led_green = 13;
int led_red = 12;

void setup()
{
  Serial.begin(9600);
  pinMode(led_green, OUTPUT);
  pinMode(led_red, OUTPUT); 
}

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();
  if (celsius <= 25.00)
  {
    digitalWrite(led_green, HIGH); 
    digitalWrite(led_red, LOW); 
  }
  else
  {
    digitalWrite(led_green, LOW); 
    digitalWrite(led_red, HIGH); 
  }
  delay(10000); 
}

and this schema:

led and temp

Temperature 1,2 or 3 degree plus than normal where or what I miss?

1
So your temperature reading is out by a degree or two? I'm not sure i'd worry too much about that. Also, it doesn't look like you've hooked up the temperature sensor correctly. The 3 pins should be connected - is this just a schematic 'typo'?Marty

1 Answers

1
votes

Because of

kelvin = analogRead(0) * 0.004882812 * 100;

So each step of the ADC will imply ~0.5 degrees of temperature difference. Since you did not specify anything in your sketch the voltage reference is the supply voltage. Loading the Arduino's outputs with just one LED (as you do) may affect the supply voltage in the order of magnitude of 50-100 mV. This in turn will affect your temperature reading by several degrees.

You can find a detailed analysis of this effect in my blog

So the issue can be explained by the addition of LEDs to your circuit.