# Why use a pull-down resistor with a LDR and microcontroller?

I am looking at this: http://learn.adafruit.com/photocells/using-a-photocell

It's connecting VCC <-> LDR <-> resistor <-> GND. And the analog input is between the LDR and the resistor.

I understand than a resistor may be necessary to control the current (in case the LDR resistance is very low). But Why can't I just do the following:

VCC <-> LDR <-> resistor <-> Analog Input


• In short: The LDR throttles the current through it depending on the light intensity (varying resistor). The µC cannot measure current (or resistance) but only voltage. A current can be transformed to a voltage when sent through a resistor over which the resulting voltage can then be measured. - Or think about it this way: The extra resistor is there to allow comparison of the LDR's resistance (varying) with the known resistance of the fixed-value resistor, which allows to calculate first the ratio of both resistors and then from it the absolute value of the LDR. – JimmyB May 21 '13 at 14:11

When working with a digital circuitry that senses analog voltage, for example a microcontroller, or let's say Arduino, you are measuring voltages. However, without current, voltage cannot be present.

For a voltage to be created on a component, there need to be a current flowing on it. According to Ohm's law;

$V=I*R$, when $I=0$, the equation becomes; $V=0*R=0$. Thus, no voltage will be present, and the microcontroller will not be able to measure anything.

Proper way of sensor connection

Check out the schematic below. First, have a look at the left side, a proper LDR connection with a proper pull-down resistor. A current will flow through R2 and create a voltage drop on it.

$Vanalog =Isensor*R_2$, where $Isensor$ is determined with the total resistance of the sensor and $R_2$. Since LDR's resistance changes with the light, the current, hence the voltage will change.

You may have noticed that there is a resistor I drew in the input. This is called the input resistance, or impedance, of the microcontroller and is generally very big, such as $10M\Omega$.

In this configuration input resistance and $R_2$ are connected in parallel, so their effective resistance is going to be;

$\dfrac{1}{\Omega_{total}}=\dfrac{1}{R_2}+\dfrac{1}{R_{in}}=9990.00999\Omega$ which is almost equal to $10k\Omega$. So, there will be no change.

The voltage AnalogValue is then,

$Vanalog=Isensor*10k$, where $Isensor$ is $\dfrac{Vcc}{R_1+10k}$

Let's say our sensor $R_1$ is 10k at the current lighting condition. And $Vcc=5V$;

$Isensor=\dfrac{Vcc}{R_1+10k}=\dfrac{5}{10k+10k}=250 \mu A$, $Vanalog=2.5V$

What if there was no pull-down resistor?

If there was no pull-down resistor, the configuration would be as shown in below diagram. The sensor current, $Isensor$ would be the same as $Iinput$, since all the currents on a wire are the same. Our microcontroller measures the AnalogValue, the voltage on the pin.

Let's calculate the values for this scenario, too:

We know that $Isensor=Iinput$, now let's assume, again, that LDR is $10k$, AnalogValue is calculated as follows;

$Vanalog=Isensor*R_{in}$, where $Isensor$ is $\dfrac{Vcc}{R_1+R_{in}}=\dfrac{5}{10k+10M}\approx500*10^-9\approx500nA$

Thus, $Vanalog=Isensor*10M\approx(500*10^-9)(10*10^6)\approx5V$

As you can see, since almost no current flows, there is almost no voltage dropped on the sensor and even though we could read 2.5V on the previous proper configuration, we have read 5V with the same light, i.e. when $R_1=10k$. This configuration will not work.

• Thank you for the in-depth explanation. It was very easy to understand, and I really liked the comparison between the two scenarios along with formulas and calculations. – Weboide May 21 '13 at 17:34
• @Weboide You are welcome, thank you for your comment. – abdullah kahraman May 22 '13 at 6:02

In your second example by connecting Vcc, the LDR and resistor in series you'd essentially only allow different amounts of current to flow to the analog input. The analog inputs on a microcontroller tend to have a high input impedance so under most circumstances you wouldn't get a good / reliable change in the readings. In practice for typical LDR values I'd expect you'd get a full scale reading all the time much like connecting the ADC input to Vcc via a 10K resistor.

By connecting the circuit to ground you're forming a voltage divider so instead of small changes in current you'll be getting a change in voltage. That allows the internal capacitor in the ADC sample and hold circuit to charge quickly for an accurate reading.

Two things:

• A microcontroller's input has a high impedance state, which means: not ground, not Vcc
• A microcontroller's input measures voltage, not current

When you connect the two resistors as a voltage divider, like they do, current will flow from Vcc via the resistors to ground. The voltage over the normal resistor is the voltage the input will read and you can calculate it with V=IR, R being the resistance of the normal resistor, and I the current through both resistors. Since the current depends on the total resistance, the voltage on the input pin will depend on the resistance of the LDR.

However, when you connect the two resistors to the input instead of ground, no current can flow (remember the first point). Therefore, the resistors just work as a pull-up and not as a voltage divider. The voltage on the pin won't depend on the resistance of the LDR anymore.

The pull down resistor is simply acting in the circuit to create a potential divider. The LDR resistance can change over a wide range depending on the light level (say a few hundred ohms to a few hundred thousand ohms.) The junction between the LDR will therefore give a variable voltage between (nearly) 5V and (nearly) 0v i.e. the range of voltage the input of the micro controller can handle.

The resistor (10k) does limit the maximum current that flows through the LDR but its function is to to provide a voltage signal.

Your second circuit without a ground (0V) connected the input (which takes very little current) means that the input would only see the 5V (Vcc) even when the resistance of the LDR changes between its extremes.

## protected by W5VO♦May 21 '13 at 15:35

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).