Photoresistors

Hi, in a project i am working on i am using 6 photoresistors as switches connected to the analog pins. i need a way to use the photoresistors as switches without taking up all the analog pins. please help. thank you.

Anyone can correct me if i'm wrong but you should be able to connect them to the digital pins. Under ideal conditions the photo resistor in full light would have little to no resistance to it. So if you connected it between a digital pin and +5 it will register HIGH under full light and low under dimm to no light. Thus allowing it to act as a switch. I would have tested this before posting but i'm at work.

If the light conditions are not optimal you could always wire the photo resistor between the digital pin and an op amp so that your getting the needed 4.8 to 5v going into the digital pin so it can read HIGH. Just make sure the conditions won't change allowing a full 5V to get threw.

I'm sure i'm missing something because this seams a little too simple. There has to be more to it then the photo resistor and an op amp.

A photo-resistor is fundamentally a analog component. They are usually used with a series fixed resistor to make a variable voltage source. Trying to use such a divider for digital input pin is problematic, as specific digital inputs fixed 'legal' voltages (see datasheet for valid logic voltages) must be met to be read as a valid LOW or HIGH input.

Not saying it can't be made to work if used with just full light and full darkness conditions and the proper sized fixed resistor, but plenty of testing would have to be done to make sure the voltage stayed out of the invalid range for a digital input. Certainly such sensors wired to comparator type op-amps would work for reading as digital signals, but that would take up space and add some costs.

Lefty

I came across a circuit for using LDRs (photoresistors) with "Analog" output on digital pins. It timed how long it took to switch from high to low. A capacitor was charged through a resistor and then discharged through the LDR, the higher the light level, the quicker it discharged.

If you just want to measure the absence or presence of a fixed light source its pretty easy to get a voltage divider right with an LDR so it gives an unambiguous high/low reading on a digital pin. If the light source is variable then you either need the above method or use an analog pin.

Heres a long thread where some guy makes homemade optoisolators from LDRs (photocells) and mains neons to detect whether his machines in a laundromat are in use.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256657133/0

Here is a less code/more hardware approach.

If I really want to use DIGITAL pins... I would simply feed the output of an LDR in the Voltage Divider setup (as mentioned above) into a comparator chip, like the LM339 and feed the output of the comparator to a digital input pin. Think: Light threshold NOT met (DARK) = Logic 1, LIGHT = Logic 0 of you use a circuit shown below.

Take a look at these: http://home.cogeco.ca/~rpaisley4/PhotoDetectors.html

Thank you so much, now that i know it can be done i need to buy the LDRs but i cant seem to find them on Mouser if anyone has a part number that would be great.