Question on how to multiplex LDR's

Hi all, I would like to see if I could get a bit of help regarding multiplexing some LDR's (Light dependent resistors). :slight_smile: My end goal is to make a PCB with a grid of 13x7 LDR's (91 total) to measure the light output coming from a screen in many different points. I have never done multiplexing before, and I am having a bit of trouble getting my head around it. I have drawn a circuit which I thought would work, but i'm pretty sure it wont work now. To test things, I am prototyping on a breadboard with and a grid of 2x2 LDR's. When I wire the circuit show below to my Arduino, it does get an analog value, but the value changes when I cover any of the four resistors, not just the one I am trying to measure. I put the test code I am using below. It is just hard coded to try to measure one LDR. Once I get one working, I can worry about coding it properly. Thanks in advance for any help!!

#define V0 2  //define all the pins I am using for this test
#define V1 3 //V pins connect directly to one side of the LDR
#define G0 4 //G pins are the lines that control the side of the LDR attached to a 10K resistor
#define G1 5 
#define S0 A0 //S pins are the lines where the analog voltage is read between the LDR and 10K resistor to get a light value
#define S1 A1

void setup() {
  pinMode(V0, OUTPUT);  //set pin modes to corrdct type
  pinMode(V1, OUTPUT);
  pinMode(G0, OUTPUT);
  pinMode(V1, OUTPUT);
  pinMode(S0, INPUT);
  pinMode(S1, INPUT);
  Serial.begin(9600);  //start serial
}

void loop() {

  //read LDR 1
  digitalWrite(V0, HIGH);  //power the V0 line
  digitalWrite(G0, LOW);  //make G0 go to ground
  Serial.print("LDR 1:");  //print in serial
  Serial.println(analogRead(S0)); //read the S0 line   
  digitalWrite(V0, LOW); //put V0 and G0 back to low
  digitalWrite(G0, LOW);
  delay(1000); //wait 1 second, then repeat
}

You can’t have a two dimensional matrix to measure sensors like that because there is nothing stopping every thing shorting out, as you have found.

You need to use cascaded wiring to get all your inputs to be separate.

Grumpy_Mike:
You can’t have a two dimensional matrix to measure sensors like that because there is nothing stopping every thing shorting out, as you have found.

You need to use cascaded wiring to get all your inputs to be separate.

Ok, thanks for the reply. I am unfamiliar with what Cascaded wiring is, and I cant seem to find an explanation about it online. If you could point me in the direction of where I can learn about it I would be very grateful.

These are basically the two types of multiplexing:-

Ok, many thanks. I am going to try and see if I can implement something like that.

Grumpy_Mike:
You can’t have a two dimensional matrix to measure sensors like that because there is nothing stopping every thing shorting out, as you have found.

Mike, could it be done with a diode in series with each ldr? Obviously there would be a voltage drop across the diode, but perhaps that could be compensated for in code, probably with some loss in resolution.

could it be done with a diode in series with each ldr?

I did think about this, but as they are analogue sensors rather than a digital switch, I think the non linear conduction on the diode will screw up the readings, with sensors not being addressed affecting the ones that are.

13x7 is weird from a digital point of view. Can't you change it to something like 8X16 (128 LDRs).

Sparkfun has 16channel analogue muxer boards.
100n from each muxer input to muxer ground, pull up resisor from each muxer input to muxer VCC.
LDRs between muxer inputs and muxer ground.

Could use a Nano (8 analogue inputs) for the 8 muxer outputs (8x16) and four address lines.
Leo..

Wawa:
13x7 is weird from a digital point of view. Can't you change it to something like 8X16 (128 LDRs).

Sparkfun has 16channel analogue muxer boards.
100n from each muxer input to muxer ground, pull up resisor from each muxer input to muxer VCC.
LDRs between muxer inputs and muxer ground.

Could use a Nano (8 analogue inputs) for the 8 muxer outputs (8x16) and four address lines.
Leo..

That is true. 13x7 just worked out nicely since it spread the LDRs evenly at a good spacing on the display. Bumping it up to 16x8 seems like a pretty good idea, but I will need to make sure the LDRs would spread out evenly over the display. Also, that chip does look pretty perfect for my use case, thanks! When you say 4 address lines would be needed for the mux chips, that means all the chips address lines would be linked together? I suppose there is no need to have them separate, so that should work nicely.

When you say 4 address lines would be needed for the mux chips, that means all the chips address lines would be linked together?

No that means you need four output pins from the Arduino to select one out of 16 possible inputs. I can’t see that being of much use to you myself as one board would only allow 16 sensors, I though you needed a lot more?

Every chip output can be connected to a different analogue input.
Leo..

So that is basically the parallel configuration in reply 3. So you get 16 * number of analogue inputs you have. That would be a maximum of 128 inputs requiring 8 of those boards.
Is that enough?
Each board would be connected to the same set of four address pins from the Arduino

Another option to consider: 16 X MCP3008. Each chip has 8 10-bit analog inputs and an SPI interface. You could use a couple of cascaded 74hc595 to control the chip select lines on the MCP chips. The MCP chips will probably cost less than £2 each because you are buying more than 10.

Grumpy_Mike:
So that is basically the parallel configuration in reply 3. So you get 16 * number of analogue inputs you have. That would be a maximum of 128 inputs requiring 8 of those boards.
Is that enough?
Each board would be connected to the same set of four address pins from the Arduino

Yeah, I would need 8 of the Mux chips, im not going to buy the breakout board. I am making a PCB for the LDR array, so its no big deal to have 8 of the chips. If I order 10 it would cost £6, so not too expensive.