Author Topic: LDR Array on microcontroller  (Read 861 times)

0 Members and 1 Guest are viewing this topic.

Offline milouTopic starter

  • Newbie
  • Posts: 5
  • Country: ch
LDR Array on microcontroller
« on: May 25, 2026, 01:14:06 pm »
Dear EEVBlog community

I'struggling connecting multiple LDRs to a teensy microcontroller. I use a classic voltage divider circuit for each LDR arranged as a matrix.
6 digital pins of my microcontroller are used to drive the voltage divider (coloumn-wise), 6 analog pins are used to read the values (line/row wise). So I have 36 LDRs in total. I use a 10k resistor per colounn to pull againt GND.

The circuit is working fine for 1 LDR and for muliple LDRs in the same column (one digital output and multiple analog inputs). But as soon as I am adding more coloumns the circuit is not working any more. The readings only show marginal changes when the light changes and the readings of all sensors are changing as well.

I tried to put a diode between each LDR and the digital output, but that did not help, I tried as well different pulldown-resistor values.
BTW: I disconnect teensys unused Outputs during readings.

Does somebody have an idea what I am doing wrong?
Is there a working circuit diagram availble for such a case?

Thank you  :)
 
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 4101
  • Country: us
Re: LDR Array on microcontroller
« Reply #1 on: May 25, 2026, 02:37:13 pm »
Here's a Falstad simulation of a 2x2 matrix with diodes.

(Falstad simulation link)

The top volt meters show the voltage of the driving GPIO lines -- press the switch to alternate driving one line or the other.

The side volt meters show the inputs to the ADC lines.

You can change the resistances using the sliders on the right and see how the changing the resistances of the unpowered resistors changes the output voltages.

 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 6102
  • Country: nl
Re: LDR Array on microcontroller
« Reply #2 on: May 25, 2026, 03:23:51 pm »
The schematic ledtester posted tells the story why it fails. Every LDR forms a path to ground via the 10k resistors, and as such influence the readings on a row.

A scanning matrix works for a keyboard because there is no path to ground. With the use of diodes per switch it is possible to detect every unique one, but that does not work with your LDR's.

What you need is analog muxes like the 4051 (https://www.ti.com/lit/ds/symlink/cd4051b.pdf) to select the individual LDR's. With 5 of those you can handle 40 LDR's.

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 17187
  • Country: de
Re: LDR Array on microcontroller
« Reply #3 on: May 25, 2026, 03:31:20 pm »
As already written by other the simple matrix does not work, because the current can split and go multiple ways. The matix works with LED output as the diodes block current going the other way.
One could still get away with a diode in series to each LDR. The diode drop however adds to the measurement and makes it a bit less accurate.
 

Offline PGPG

  • Super Contributor
  • ***
  • Posts: 1295
  • Country: pl
Re: LDR Array on microcontroller
« Reply #4 on: May 25, 2026, 03:32:13 pm »
I use a classic voltage divider circuit for each LDR arranged as a matrix.

Show schematic of this matrix.
 

Offline WattsThat

  • Frequent Contributor
  • **
  • Posts: 913
  • Country: us
Re: LDR Array on microcontroller
« Reply #5 on: May 25, 2026, 03:48:00 pm »
I use a classic voltage divider circuit for each LDR arranged as a matrix.

Show schematic of this matrix.

The above as well as specs of the LDR’s and Teensy model. Anything less and we’re just making wild guesses in the dark.
 

Offline milouTopic starter

  • Newbie
  • Posts: 5
  • Country: ch
Re: LDR Array on microcontroller
« Reply #6 on: May 25, 2026, 05:31:50 pm »
My schematic drawing skills are rather limited..   :-X but I hope you get the idea.
In addition I tried to add diodes in series with the LDR, between Dx and the LDR. But then I got no readable results.
Thanks
« Last Edit: May 25, 2026, 05:40:38 pm by milou »
 

Offline milouTopic starter

  • Newbie
  • Posts: 5
  • Country: ch
Re: LDR Array on microcontroller
« Reply #7 on: May 25, 2026, 05:34:02 pm »
I do not see how this schematic could help  :(
Thanks anyway!

Here's a Falstad simulation of a 2x2 matrix with diodes.

(Falstad simulation link)

The top volt meters show the voltage of the driving GPIO lines -- press the switch to alternate driving one line or the other.

The side volt meters show the inputs to the ADC lines.

You can change the resistances using the sliders on the right and see how the changing the resistances of the unpowered resistors changes the output voltages.
 

Offline milouTopic starter

  • Newbie
  • Posts: 5
  • Country: ch
Re: LDR Array on microcontroller
« Reply #8 on: May 25, 2026, 05:37:28 pm »
You're absolutely right.
I am using teensy 4.0
The LDR is PDV-P9008. Dark resistance 20M, light resistance 10 - 200k.

I use a classic voltage divider circuit for each LDR arranged as a matrix.

Show schematic of this matrix.

The above as well as specs of the LDR’s and Teensy model. Anything less and we’re just making wild guesses in the dark.
 

Offline pqass

  • Super Contributor
  • ***
  • Posts: 1161
  • Country: ca
Re: LDR Array on microcontroller
« Reply #9 on: May 25, 2026, 05:59:19 pm »
In addition I tried to add diodes in series with the LDR, between Dx and the LDR. But then I got no readable results.

Seems to work.  See attached and simulation here.

The in-line diodes prevent their LDR from interfering with each other when the column line is low.
 

Offline PGPG

  • Super Contributor
  • ***
  • Posts: 1295
  • Country: pl
Re: LDR Array on microcontroller
« Reply #10 on: May 25, 2026, 06:13:47 pm »
I do not see how this schematic could help  :(

It helps a lot as it confirms that you missed the diodes that are needed in such matrix.
In other words it explains where from are all your problems.

In your schematic D0A0 LDR is in paralel with serial connection of D0A1 + {(D1A1 + D1A0) || (D2A1 + D2A0)} LDRs and it is not the only one combination of LDRs that are in paralel to D0A0 one.
Each LDR have some others connected to it that way.
Everything because there are no diodes to break these connections by being reverse polarized.
« Last Edit: May 25, 2026, 06:20:30 pm by PGPG »
 
The following users thanked this post: milou

Offline milouTopic starter

  • Newbie
  • Posts: 5
  • Country: ch
Re: LDR Array on microcontroller
« Reply #11 on: May 25, 2026, 06:33:01 pm »
Thanks. I will review my circuit. There has to be an error then.  :-+

I do not see how this schematic could help  :(

It helps a lot as it confirms that you missed the diodes that are needed in such matrix.
In other words it explains where from are all your problems.

In your schematic D0A0 LDR is in paralel with serial connection of D0A1 + {(D1A1 + D1A0) || (D2A1 + D2A0)} LDRs and it is not the only one combination of LDRs that are in paralel to D0A0 one.
Each LDR have some others connected to it that way.
Everything because there are no diodes to break these connections by being reverse polarized.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 4101
  • Country: us
Re: LDR Array on microcontroller
« Reply #12 on: May 25, 2026, 06:34:19 pm »
As pqass has mentioned, the schematic I provided seems to work. LDRs are not precise devices anyways and there's a lot of variance between them and the diodes seem to prevent the unenergized LDRs from greatly affecting the output voltages.

To the OP -- I would simplify the circuit to debug what's going on.

1. Create a 2x2 matrix with the diodes.

2. First remove the LDRs from the first column and test reading the LDRs in the second column.

3. Do the same with the roles of the columns switched (remove the 2nd column LDRs, etc.)

4. Now populate the LDRs in the first column and just one LDR in the second column and see how that affects the voltage readings. Add LDRs one-by-one.

5. Add another row (or column) and test again.

If things aren't working try swapping out LDRs -- maybe one or some of them are bad.

Basically you want to find the simplest circuit that doesn't work for you.
« Last Edit: May 25, 2026, 07:05:26 pm by ledtester »
 
The following users thanked this post: milou

Online negativ3

  • Frequent Contributor
  • **
  • Posts: 468
  • Country: th
Re: LDR Array on microcontroller
« Reply #13 on: May 25, 2026, 06:39:51 pm »
Might work for you...
 

Offline lichurbagan

  • Regular Contributor
  • *
  • Posts: 204
  • Country: bd
Re: LDR Array on microcontroller
« Reply #14 on: June 03, 2026, 09:04:20 am »
Dear EEVBlog community

I'struggling connecting multiple LDRs to a teensy microcontroller. I use a classic voltage divider circuit for each LDR arranged as a matrix.
6 digital pins of my microcontroller are used to drive the voltage divider (coloumn-wise), 6 analog pins are used to read the values (line/row wise). So I have 36 LDRs in total. I use a 10k resistor per colounn to pull againt GND.

The circuit is working fine for 1 LDR and for muliple LDRs in the same column (one digital output and multiple analog inputs). But as soon as I am adding more coloumns the circuit is not working any more. The readings only show marginal changes when the light changes and the readings of all sensors are changing as well.

I tried to put a diode between each LDR and the digital output, but that did not help, I tried as well different pulldown-resistor values.
BTW: I disconnect teensys unused Outputs during readings.

Does somebody have an idea what I am doing wrong?
Is there a working circuit diagram availble for such a case?

Thank you  :)

Don't matrix LDRs. They're resistive devices. So the network causes crosstalk and inaccurate readings. Instead, give each of the 36 LDRs its own voltage divider and route the outputs through analog multiplexers such as the CD74HC4067 or 74HC4051. Three 16-channel multiplexers provide 48 inputs and use only a handful of MCU pins.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf