Jump to Navigation

Garden Project - Light Sensor

As it turns out, sunlight is actually pretty important for plant growth. Who knew? Right? Well, it is important and if plants need it, I want to measure and log it as part of my Garden Project. To sense light, I'm simply using some photo resistors from Radio Shack. They come in a 5 pack I think, bunch of different sizes, but they all work exactly the same way. They are super simple components, but can be kinda tricky to get meaningful information out of. We need to add an additional component and do some math. I hate math. I'm fascinated by it and love reading about it, but I'm horrible at it and it takes me forever to understand a concept and sometimes I never understand it. The math associated with this sensor is tedious and annoying, but using a spreadsheet application of some sort I should be able to plot some points that help me make sense of the values I'm getting. Excited yet? Me either.

Here's how they work:
You'll notice that many of the sensors I'm using in this project are 3 pin sensors. It makes sense. You need to power the sensor using + and GND. The sensor gives you some sort of output so you need a pin for that. Makes sense right? Well these light sensors only have 2 leads and no markings. No +V no ground, no Vout, no nothing. Just metal leads sticking out of a chunk of plastic. What do we do with that?

This thing we're using as a light sensor is called a photo resistor, and it's exactly what the name implies. It's a resistor with some properties related to light. In complete darkness, the sensor has a VERY high resistance. It's in the MegaOhms range. I'd tell you what it is, but I can't read my meter with the lights out, but in a very dark room I saw 2 MegaOhms. When it's in direct light the resistance is comparatively low. With the "60 watt" LED bulb I have clipped to my bench is pointed right at it, I was reading 1.5Kilo Ohms or somewhere in that area. That's a pretty big swing between light and dark.

How do we use this to actually measure light? Answer: I have no idea. BUT we can certainly use it to generate a voltage that represents different amounts of light. Then we can feed that voltage into our Arduino and do something with that information. I have no idea what a lumen or a candlepower is, and I think this trend of trying to give some sort of wattage equivalent is stupid, so I'm sticking with a simple voltage between 0 - 5V and I'm going to just observe the conditions and assign some sort of label to it. So, maybe 3V will be a cloudy day, and maybe 1V is a sunny day, and 4.8V is night time. Who knows. I'll post that when I figure it out.

How do we feed the voltage into arduino with only 2 pins? Answer: we don't. We need to make this 2 pins sensor into a 3 pin sensor so we can deal with it just like we deal with the other sensors. This is where the additional component and the math comes in. Those of you with electronics knowledge will get this right away, those of you without any background in electronics - this is going to suck. Just fair warning.

To get the +V, GND and Vout pins we need, we are going to create something called a voltage divider (electronics folks, you can stop reading right now, you get it, move on). We do this by adding a fixed resistor to the light sensor, connecting them in series. Just for a minute, let's forget that the photo resistor, is a photo resistor, let's just think of it as a fixed resistor, just like the one we are adding to this circuit. In normal room lighting, the sensor was reading 20K so let's think of the photo resistor as a fixed 20K resistor. Then we'll add a real fixed 20K resistor in series with it. So, now we have 2 resistors of equal value in series. It looks like this on the breadboard.

Again, forget the fact that one component is a photo resistor. For the sake of the math at this point they are both fixed at 20K Ohms. The schematic looks like this.

Make sense? You can see how the two images are the same thing? Good.

So where are our 3 pins I only see 2 still? Answer: where the 2 resistors are connected together. That's our 3rd pin.

See that now? Ok. Here comes the math. Something called Ohm's Law (electronics guys, stop rolling your eyes, it's rude. A lot of hobby guys don't understand this and it's important) describes mathematically how electricity flows through a circuit. It looks like this Voltage = Current/Resistance. We need to understand this to figure out what is going on in this circuit. Based on the circuit above with the pin numbers on it, let's use Ohm's Law to figure out how much voltage is in each resistor.

There's a couple of things I should mention up front. They are just facts, constants, knowns, etc. Trust me on these. don't stress about it.

1.) This is a series circuit.
2.) Current is the same at any point in a series circuit. No matter were you put your meter in, you're going to read the same thing.
3.) Resistance is additive in a series circuit. To find the total resistance in a series circuit, you just add up the values of the resistors.

To figure out how much current is flowing in this circuit, we need to know the total resistance in the circuit. So, according to fact #3, we just add up the resistors. So, 20K + 20K = 40K. Total resistance is 40K.

With this information we can now figure out how much current is flowing through the circuit. 5V/40K = 0.000125 Amps of current.

NOW we can figure out how much voltage is sitting in each resistor. We know current is constant, AND we know the value of each resistor. So, let's figure out the voltage for the bottom resistor. .000125 X 20K = 2.5V

NICE! 2.5V. We know we're applying 5V to the whole circuit, so the other resistor must have 2.5V in it also! Sweet! This is amazing!

Who cares?! Answer: We do. Remember how we need the 3 pins, +V, GND and Vout? Well, we have them now. Let me redraw the schematic.

There are the 3 pins we need. Power on top and bottom, and Vout in the middle.

Now, we need to start treating the photo resistor as a photo resistor. Above I mentioned that at a typical room light level, the photo resistor was reading about 20K. With the little math thing we just did, we just determined that each resistor had 2.5V in it. So, the bottom resistor for example has 2.5V in it. If we put our meter between the Vout pin, and the GND pin, our meter will read 2.5V. If we put our arduino between the Vout pin and GND the arduino will see 2.5V as well. We now have our FIRST reference point! 2.5V = normal room light!

So what happens when the light changes, and the resistance of the photo resistor starts to change? Answer: We have a functioning light sensor! Here's how. Let's keep our meter (or the Arduino) connected between the Vout and GND. Let's also make sure that the FIXED resistor is in the top position and the photo resistor is in the bottom position.

Because the photo resistor is changing it's value based on the light in the room, we don't know what the resistance is. What we DO know, is that in a dark room it's in the MegaOhms range, and in a bright room it's in the 1-2K Ohm range. So let's just put some numbers in there and try to establish our night, and our day values and add them to our normal room light value. That gives us 3 points to work with.

Let's start with "dark". I'm going to say dark is 2 MegaOhms based on what I measured with my ohm meter earlier.

Ok, back to Ohm's Law. First we need to find total resistance. We decided that "dark" meant 2 MegaOhms, and the fixed resistor is 20K. So the total resistance of this circuit is 2,020,000 ohms (2.02M).

5V / 2.02M = 000006475 Amps.

So now we need to know the voltage at the Vout pin. Which is where our meter is connected. It's connected across the photo resistor, so we do .000006475 X 2M = 4.95V. Cool, so at night our sensor is going to read 4.95V.

Let's do the day light now. With direct light on the photo resistor, my meter read about 1.5K Ohms. So let's plug that number in and see what happens.

RT = 20K + 1.5K - 21.5K
Current = 5V / 21.5K = 0.000432 Amps
Vout = 0.000432 X 1.5K = 0.348V

So we know in bright sunlight our sensor is going to read 0.348V.

We now have 3 points on our scale. Dark = 4.95V, Normal light = 2.5V and Full sun = 0.348V. We can estimate the in between values or just observe the light and note the voltage and call it good.

So, there we have it. A light sensor. I'm still working on an enclosure for it though. I'm not sure if I'm going to make a PCB or if I'm just going to solder the parts together and stick it inside of a ping-pong ball (as was suggested by a family member). No clue, but I'll keep you posted on that.

Stay tuned for more component breakdowns.

Main menu 2