# Would this circuit work?

I've been a software dev for a while, but never really did a lot with hardware so please forgive me if this question is really basic.

I have an Arduino project I am trying to set up that involves a photocell. Most of my Arduino knowledge so far is from the book Getting Started with Arduino. They have a section that actually talks about photocells. Below is the diagram they give for building a circuit. I have two questions about it.

First, what is the point of the resistor (seeing how the photocell is basically a light sensitive resistor)? Why couldn't the circuit just be "5V to photocell, photocell to A0"?

Second, if my project has already used the 5V pin (its for an LCD display) could I rig the circuit up to start at a digital pin (which would be set to output 5V) to photocell back to A0? If not, how would I power the photocell?

Normally I'd just try this (without the resistor) and see what would happen, however I don't have a spare Arduino and don't feel like frying this one quite yet. • those unfamiliar with the arduino take note - that's an analog input being used in the picture, not a digital one. – JustJeff Jan 14 '12 at 20:40

## 2 Answers

First, what is the point of the resister (seeing how the photocell is basically a light sensitive resister)? Why couldn't the circuit just be 5v to photocell, photocell to A0?

I don't know anything about Arduino's but from looking at the circuit, I surmise that A0 connects to an input pin of the microcontroller. What's happening is that when light hits the photocell, its resistance decreases, so the A0 pin is pulled high, and the Arduino reads a "high" input. When there's no light input, then, you want to read a "low" input.

What happens is, with no light, the photocell resitance increases, and the extra resistor pulls down the A0 pin to ground, so the Arduino can read a 0 input. If there was no extra resistor, no matter how high the resistance of the photocell, it would still always pull up, and A0 would always be "high".

Second, if my project has already used the 5v pin (its for an lcd display) could I rig the circuit up to start at a digital pin (which would be set to output 5v) to photocell back to A0? If not, how would I power the photocell?

Again, I only know from the way the board is labeled in your diagram, but I expect that "5V" is a power supply pin. If it is, then you should be able to connect it to multiple loads, as long as the total current needed by those loads is not more than the board can supply (check the data sheet or manual for your board). But the photocell circuit shouldn't draw more than a few mA, so it should be safe to add this load to the load from the LCD you already have. You just need to find some physical way to connect both the LCD and the photocell to the same pin. One easy way would be to just solder three wires together to form a "Y"; connect one leg of the Y to the Arduino, one to the photocell, and one to the LCD circuit.

# Edit

You explained that the A0 is an analog input pin for the Arduino.

In that case, what you're doing is using the photocell as one part of a resistor divider: In your case Vin is 5 V, and R1 is the photocell, and R2 is the "extra resistor". The voltage at Vout is connected to A0 of the Arduino so you can measure it.

The formula for the output voltage of the resistor divider is

$$V_{out} = V_{in}\times \frac{R2}{R1+R2}$$

If you remove the extra resistor, that's like taking R2 to infinity. You can see from the formula that in the limit as R2 goes to infinity, you get $$V_{out}=V_{in}\times R2 / R2$$ or $$V_{out} = V_{in},$$ meaning you'll always read 5 V at Vout if the extra resistor isn't there.

Resistor divider image from Wikimedia, Creative Commons Attribution Share Alike

• Since A0 is analog and not digital the Arduino could read 0 input (I think). Would what you said about the resister still be true? – CountMurphy Jan 14 '12 at 20:53
• Yes, still true. Without the extra resistor, the photocell always pulls up, and A0 will always be at 5 V. One caveat is that the input pin on the Arduino will have some (probably relatively high, like 5 kOhms or more) input associated with it, so there will be some variation without the extra resistor. But the designer of the circuit presumably calculated that the extra resistor is needed to optimize the range of input voltages seen at the analog input. – The Photon Jan 14 '12 at 20:58
• ok, I'm about to let my ignorance shine...what exactly do you mean by "pull up?" – CountMurphy Jan 14 '12 at 21:04
• When a resistor is connected between a supply voltage and some other circuit node, we often say the resistor "pulls" the other node toward that supply. Since 5 V is (I'm assuming) the highest voltage in your circuit, we say a resistor to 5 V pulls its other end "up". – The Photon Jan 14 '12 at 21:08
• ...It also means the resistor can't absolutely force the other end to the supply voltage, it can just "pull" it there; but other circuit elements might be "pulling" it the other way. – The Photon Jan 14 '12 at 21:09

IMPORTANT: If your Arduino runs on 3V3 then use the 3V3 voltage to drive the circuit.

(1) Yes, your circuit will work as shown.
The resistor should be about the same resistance as the photocell in its typical operating light range, although non optimum values will work well enough in many cases.

As shown the two resistors form a "voltage divider" with the share of the available voltage depending on their relative resistances. The same current flows through both so, as Ohms law tells us that
V= I x R, if we change R we change the relative V. As A0 measures Voltage this will work.

(2) You ask

• Why couldn't the circuit just be 5v to photocell, photocell to A0?

If you connect it directly to the port with no divider, as you suggest, then varying the resistor will vary the current into the port only by an extremely little amount as the port is high impedance and the varying external resistance is effectively added to the very high internal resistance. This does in fact have a very very small effect on the voltage that the port "sees" but the difference is minute and is not "designable" as the port impedance is not accurately specified.

The target of the comment by @clabacchio was uncertain and I have now edited the answer to make it clearer so his comment is now fully inapplicable.

• That's true, but actually the input resistance of an input pin is very high (i think hundreds of kOhms) so actually you have no current flowing in the photoresistor and so no voltage drop and nothing to measure, basically. – clabacchio Jan 14 '12 at 23:04