# Reading From a Large Array of Photoresistors

I'm an undergrad just starting to study Electrical Engineering. For the first hobby project I'm starting, I want to use a microcontroller to read analog voltage values from a very large array of photoresistors (18x24). From these values I will pinpoint the location of various light sources near the sensor array using some algorithm I haven't thought much about yet.

What is the "correct" way to structure the circuit so that I can access one resistor at a time from my microcontroller. I want to select one specific resistor using some sort of parallel output from the microcontroller that is set to the resistor's address. Once the resistor is selected I want a voltage corresponding to it's resistance to be put through a common analog-to-digital converter connected to the MCU. Then, I will read and analyze the value.

• Also, it might be better to have them all wired permanently into the ADC, but to power them individually. Either way the question is "how to I access an individual resistor at location (x,y)?" – Keegan Jay Dec 15 '11 at 5:21
• this doesn't really matter as far as the electronics, but I'm curious, what's the physical arrangement of the sensors? Are you wiring up a grid of individual discrete pieces? Or have you found some kind of compact matrix of multiple sensors in a single package? – JustJeff Dec 20 '11 at 23:37

This likely calls for an X-Y grid approach in the circuit topology as well as the physical layout, with the photoresistors connected between the rows and columns.

Let's just say for sake of argument that you will drive one of the rows and read one of the columns, though the other way is fine too.

First off, to read a photoresistor, you need to make a voltage divider between it and another resistor, chosen so that you get a nice range of voltage variation between light and dark conditions.

Many micro-controllers have an internal analog multiplexer which lets the ADC read one of several input pins, but likely not enough, so extend the idea by buying analog multiplexors to have one input for each of the columns you need to read. At each input, connect a fixed pullup resistor to VCC, which will form the voltage divider with the selected photo-resistor.

Now we need to drive a low voltage onto one of the rows at a time, while leaving the others floating. This is probably best done with a chip having open-collector (or today, open-drain) outputs, but it could also be done by putting diodes in series with normal outputs. If you had enough micro-controller pins for all the rows, you could in software make all but the drive-low pin an input (provided that it's a truly floating high impedance input, not one with a pulling resistor), but you probably don't and would be using external demultiplexor chips to fan out from a binary code to one driven output and a bunch of undriven ones. (for examaple, a couple of 3-of-8 decoders should do the job).

There are both extremes and variations of this idea; the electrical grid doesn't have to have the same dimensions as the physical one. You can also substitute measuring the time to charge or discharge a capacitor in place of the ADC. (In fact, you can time a capacitor that is itself the image sensor, measuring the leakage of charge from the capacitors that form DRAM cells either in a purpose built device or an old ceramic DRAM chip with the cover pried off - though you have to keep light off the output logic as once the lid is off "ordinary" transistors celebrate by indulging their latent photo-transistor urges)

• Can you explain how to use the 3-of-8 decoders? I've never heard of this. I'm assuming 3 is referring to number of bits, and 8 is the number of lines that can be driven. How do I use 3-of-8 decoders to drive 18 or more rows? – Keegan Jay Dec 15 '11 at 6:29
• You'd need several of them. Often they (the old 74LS138 comes to mind) have some active high and active low enable pins you can use to decode higher order bits to select which chip is active. Or you could use two stages of them, one enabling the others. – Chris Stratton Dec 15 '11 at 6:35
• Also, instead of using a multiplexer to select the column to read from, could I just use another set of 3-to-8 decoders where each output of the decoder is wired to a transistor that gates the specified column? – Keegan Jay Dec 15 '11 at 6:43
• You could, if you get the transistor circuit right, but it's probably easier to use the analog multiplexor. Consider reshuffling the row/column count when you figure out which is cheaper, drivers, or analog muxes. – Chris Stratton Dec 15 '11 at 7:00
• Okay, thanks so much for your help Chris. I'm still completely new to EE (freshman in college), but you've made this very clear. – Keegan Jay Dec 15 '11 at 7:10

You say 18 x 24 grid implying =432 inputs BUT do not let the optical or geometric constraints force you into treating them logically as an array of a given shape or number of dimensions.

The "obvious" way is to address an X=-Y array.
If you use 18 rows and 24 columns you need 18+24 = 42 pins.
But sqrt(432) = 20.78.
As we can't find 0.78 of a pin a square array = 21 x 21 = 42 pins still. No gain. But that will access 21 x 21 = 441 locations so you have 441-432 = 9 more "free" locations if desired.

BUT the cube root of 432 =~ 7.56.
If we implement an 8 x 8 x 8 array we can access 512 locations with only 24 pins.
= 42 - 24 = 18 less pins and 512-432 = 80 extra locations.

BUT can we scan a cubical array?
That's a definite maybe. Much depends on other parameters such as access speed loading etc, but one way may be to eg make each photocell position into a DTL (diode-transistor logic) AND gate or a DTL NOR gate. In one case the optical transistor can be active only when all 3 address lines are high - if any one is low the transistor is disabled. In the other case all inputs must be low - if any is high the transistor is disabled. This MAY require 3 diodes and a resistor per node, and may not. The opto transistors may all be able to be paralled when off - or th e loading may be too high.
The transistors may be able to be broken up into moddules with simple addressing of this sort.

Consider the possibility of using an open collector multiple output digital driver IC that normally has outputs open circuit but grounds one at a time as required. Or N at a time. The IC may have been conceived as a digital device but can still be used for analog enabling.

eg look at the MM5450 / MM5451 34 output LED display driver and get excited.
This IC MAY be able to do what you want. MAY. Just possible 432/34 = 13 of these may be able to drive your array with little else. Or not. But if not something similar may.

Be aware of what the CD4051 / 52 / 53 analog multiplexers can do for you. Very olde. Very useful. Better and newer available - usually for more \$. These are about 25 cents in 100+ quantity.
DO note th ability to switch higher V AC with lower V DC or to switch bipolar signals with +ve control voltages.

DTL

Note that if implementing a 3D multiplex address scheme, careful design will probably allow most or even all of the resistors to be eliminated.

Wikipedia

• Schematic of basic two-input DTL NAND gate. R3, R4 and V- shift the positive output voltage of the input DL stage below the ground (to cut off the transistor at low input voltage).

• The DTL circuit shown in the picture consists of three stages: an input diode logic stage (D1, D2 and R1), an intermediate level shifting stage (R3, R4 and V-) and an output common-emitter switching-transistor stage (Q1 and R2). The two resistors R3 and R4 form a resistive summing circuit with weighted inputs that adds the negative bias voltage V- to the positive diode logic output voltage. As a result, the unipolar (positive) diode output voltage (about V+ for logical one and 1.0 V for logical zero) is converted into a bipolar voltage (a few volts above and below ground) to drive the output transistor.

• The IBM 1401 (announced in 19591) used DTL circuits similar to the simplified circuit, but avoided the level shifting stage (R3, R4, and V-) by alternating NPN and PNP based gates operating on different power supply voltages. The 1401 used germanium transistors and diodes in its basic gates[2]. - The 1401 also added an inductor in series with R2[2][3]. In an integrated circuit version of the DTL gate, two series connected level shifting diodes replace R3. Also the bottom of R4 is connected to ground to provide bias current for the diodes and a discharge path for the transistor base. The resulting integrated circuit runs off a single power supply voltage.[4][5][6]

Yet another option would be to use (2) 1 of 16 decoders and (2) 1 of 8 decoder (all analog mux's) this way all you will need 14 I/O lines. use a micro with a good floating point math package and you are good to go.