Is it possible to use a photocell as a digital input?
It's really because of the amount of photocells I need to use and the amount of analog inputs available to me.
Thanks,
Adam
Is it possible to use a photocell as a digital input?
It's really because of the amount of photocells I need to use and the amount of analog inputs available to me.
Thanks,
Adam
First of all, if you've got a lot of photocells you might consider using an analog multiplexer like the 4051 which provides up to eight analog inputs with three digital outputs and one analog in.
That said, you could obtain a binary value from a photocell by setting it up as one side of a voltage divider. The voltage at the output of the divider would then vary from 0-5V depending on light input, and the Arduino will generally interpret that voltage as a logical 0 when between 0-0.8V and a logical 1 when between 2.2-5V. The trouble is that between those ranges, the logical value is indeterminate and you can get wacky results. You can overcome this limitation by using a schmidt triggered buffer (such as 74310) in between the voltage divider and the arduino input or a comparator to provide some hysteresis.
Thank you for your reply, I have 2 questions now:
Firstly, how do I set up the photocell as 1 side of a voltage divider? that sounds like something I do on the breadboard?
Second, what is a Schmidt triggered buffer?
Thanks,
Adam
Voltage divider. Replace one of the resistors with your photocell, and the output of the divider would depend on the resistance of the photocell (which of course in turn depends on incident light).
Most digital devices will see a voltage of 0-0.8V as a logical 0 and a voltage of 2.2-5V as a logical 1. Voltages between 0.8-2.2V, however, cannot be definitively resolved as one or the other. Apply a voltage in that no-man's land to an arduino input and your results are not guaranteed. A Schmidt trigger is a circuit that is implemented at the input of many digital devices to provide noise immunity that defeats this problem. It incorporates feedback such that , for example, the input of a schmidt-triggered digital device will not flip from a logical 1 to a logical 0 or vice versa unless the input voltage is well out of that no-man's land. It's also important for your application to note that it incorporates hysteresis, which means that it will not go from 0 to 1 until the input rises past 2.2V, at which point it will not switch back to 0 until the voltage drops below 0.8V. This provides a 'dead band' that prevents small fluctuations in analog value from being translated into fluctuations in logical value. It will be a deal breaker if you want to be able to detect small fluctuations in light, in which case you will want to use a comparator instead.
The wikipedia article on schmidt triggers lists some 7400 and 4000 series devices that have schmidt triggered inputs that you could use for your application.
Also, you could do it this way: http://web.ics.purdue.edu/~fwinkler/590E/workshop_04.pdf
you could also use a transistor with the photocell hooked to the base pin but like with the voltage divider you have to calculate the base current so that the transistor will turn off.