LM335A sensor, LED and resistors issue.

Good morning,

perhaps another post on the temperature sensor LM335A but I cannot figure it out. I connected the LM335A sensor to arduino, as I have seen on many posts, with 2 resistors of 1K (don't have a single 2K). The returned values ??are plausible (I do not need the highest accuracy). I wanted to connect a LED on the digital port 7 (for example) in order to have it turn when certain temperature is reached. I realized that by connecting the LED, the value reported by the sensor rises instantly from about 25 degrees to almost 36 (I mean Celsius - I made a conversion from Kelvin in the sketch). Why is that? In my real, final project, in place of the LED at I will insert a relay which activates a fan, once exceeded 40° C in a small room but I cannot figure how to deal with this variation. I figured that adding a LED I need to decrease the resistor... but how much (even if it was correct)?

You have advice for me on this? Thank you!


The sensor output voltage only changes by 10mV per degree, so its vital that you measure the voltage across the sensor, not the voltage across the sensor plus the voltage along a wire carrying current. This means the ground wire to the sensor must run separately from any other ground wiring. You are probably just seeing the IR losses along the ground wiring to the LED.

The Arduino has several ground connections available, reserve one for analog sensors only, use different ones for anything else.

However having said that you are seeing about 0.11V change, which is more than I'd expect - perhaps your 5V rail is not regulated? The ADC only measures relative to its reference voltage, which is (by default) the 5V rail. If you power the Arduino from the barrel jack then the internal 5V regulator will be operational and should ensure clean power rail voltage.

Do you have a resistor in line with that LED if not that could cause your problem.

Hi everybody and thanks a lot. @Mark: Yes! This could be part of the problem... the main part. I'm going to try with a different ground for led and sensor. @Mike: I put no resistor in line with led. I'll try this solution also. I put the code I'm using for a better knowledge. One important thing - I suppose - is that I'm using an Apple MacBook Pro, connecting Arduino duemilanove board via USB port. I think that my voltage is not 5V... but something similar to 4.8V. In fact if I put in my sketch analogValue = (5000*(analogValue/1024.0))/10-273; the resulting temperature is completely wrong (about 45° celsius... man, here in Rome is warm... but not so much!). So I tryed to change the value in 4800, as you can find in the code below. And now the value is correct (23° celsius). But this solutions seams to me a little bit... redneck way. Mark, how can I know exactly the Voltage that goes out from my USB?

Thanks again!


int sensorPin = 0;
# define LED1 7

void setup() {
    pinMode (LED1, OUTPUT);

void loop() {
    //write the temperatre to serial
    Serial.print("Centigrade: ");

    Serial.print("Fahrenheit: ");

    Serial.print("Kelvin: ");

    //wait 1000ms (1sec) before next read

int getCentigrade(int analogPin) {
    unsigned int analogValue = analogRead(analogPin);
    analogValue = (4800*(analogValue/1024.0))/10-273; //convert to degrees C
    return analogValue;

USB voltage will depend on your computer's power supply and load from disk/processor/screen etc - it should always stay between 4.75 and 5.25V I think, but it is unlikely to be stable enough for taking measurements. You can use a different analog reference such as the internal one or the 3.3V rail (which ought both to be stable, but need calibrating.)

MarkT: You can use a different analog reference such as the internal one or the 3.3V rail (which ought both to be stable, but need calibrating.)

Hi Mark, excuse me, I'm at first approach with some concepts in Arduino. What do you mean with this sentence? What's the internal analog reference? I know there should be a way to mesure the V of USB with an Arduino Sketch... but don't know how. And I cannot figure out what do you mean when you say that the 3.3V rail needs to be calibrated. How can I calibrate it?

Once again, thanks for your reply.


One way of calibrating it is to measure it with a meter and then use the value you measured in your calculations. You must NEVER run an LED without a resistor or some other form of current limit. You will damage the arduino's output and the LED.

Search for the tutorial on the internal referance voltage.

Ok, thanks a lot!