# Variable resistance components: Thermistors and Light dependent resistors (LDR) on a Arduino simple circuit

In the past blog post we used a potentiometer to provide a user variable voltage to one of the Analog In pin. We then used the value read from the Analog In pin to set the blinking delay of an LED. This resulted in the LED which was blinking faster and slower depending on how the potentiometer was set.

Potentiometer aren’t the only circuit components whose provide a variable resistance. In fact there are many others: providing a different resistance its a common behavior in most sensors.

In the Arduino Base Workshop KIT I have two components of this type: a 4,7K Ohm Thermistor and a 10..40K Ohm LDR VT90N2. Let’s have a look at them.

## Thermistors

thermistor is a type of resistor whose resistance varies with temperature. Thermistors are widely used as inrush current limiters, temperature sensors, self-resetting overcurrent protectors, and self-regulating heating elements.

Thermistors follows the following rule: ΔR = k * ΔT, where

• ΔR = change in resistance
• ΔT = change in temperature
• k = first-order temperature coefficient of resistance

This means that, given k positive and k=0.7, if we increase the temperature of 5 degrees, the component resistance will also increase by ΔR = k * ΔT = 0.7 * 5 = 3.5 Ohm (these values are just as example).

Note that some thermistors have a temperature coefficient of resistance k which is negative. This will make ΔT and ΔR inversely proportional.

Below you see a picture of the 4.7K Ohm thermistor available in the Arduino Base Workshop KIT.

## Light Dependent Resistor (LDR) or Photoresistor

photoresistor or light dependent resistor (LDR) is a resistor whose resistance decreases with increasing incident light intensity.

In the Arduino Base Workshop KIT we found a 10..40K Ohm LDR VT90N2:

## Using Thermistors and LDRs with Arduino

I wanted to test thermistors and LDRs usage with Arduino. So, I started with the same circuit from the Potentiometer example. For testing purposes, I replaced the potentiometer with two series resistors. Our circuit is now:

The circuit above, once assembled on the Arduino, looks like:

If we use the same code used on the Potentiometer example with the circuit above we will end up with a the LED blinking always at the same speed. The speed, which depends on the voltage on Analog In, depends on the type of resistors used. If you use different resistors the speed will change as the voltage read by the Analog pin will be different.

As an add-on to the Potentiometer code, I wanted to get the read value from the Analog In pin printed to the screen. Doing this is a good idea for debugging purposes as well for exactly detecting minimal changes in resistance of the components (this will be good once we will use Thermistors and LDRs).

I implemented this using the Serial communication tools of the Arduino board. I just print the read value on the Analog In pin to the serial interface so that when using the serial monitor available on the Arduino IDE we’ll be able to see the printed values from Arduino.

So, the potentiometer code became:

```/* read the value from a potentiometer and use it as delay */

#define POTPIN 0
#define LEDPIN 13

int val = 0;

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

void loop() {
digitalWrite(LEDPIN, HIGH);  // turn the ledPin on
Serial.println(val);
delay(val);                  // stop the program for some time
digitalWrite(LEDPIN, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time
}
```

With the circuit above and running this code I always get a value around 839-840. If we interchange the two resistors we get something around 183. This is a consequence of the fact that by switching the two resistors we change the voltage which gets to Analog In pin resulting in a different value read by the Arduino program.

### Testing the Thermistor

We can now replace the 2.2K resistors with the thermistor so that our circuit will be:

The circuit once assembled on our Arduino board and breadboard will looks like:

Without touching the thermistor I get values around 690 but if I touch it with my fingers I gets values around 760. This means that, as we expected, the resistence of the thermistor changed after I touched it due to the increse in temperature of my touch.

Unfortunately, as we can see from the video below, the change in the readed value isn’t noticable on the LED blinking.

### Testing the LDR

We can now replace the thermistor with the LDR. Our circuit will be:

The above assembled on the Arduino board will becames:

Now, if I stay far from the circuit, Arduino reads values around 920. If I put my hand close to the LDR, so that I stops light to reach the sensor, I read values around 500. The less light the sensor gets the lower the value is. We can see everything in the video below:

## Conclusions

Well, it seems that the two sensors I have works pretty well! Now, I know how they are expected to work, some theory around them and how to attach them to my circuits. I already have some cool ideas of usages for these sensors, I’m sure I’ll have quite some fun with them!

#### References:

1. Thermistors on Wikipedia
2. Photoresistor on Wikipedia
3. Potentiometers: what they are, how they work and how to use them with Arduino – previous post on this blog
Scroll to Top