# adjusting math for multiple LDRs to a common value

I don't have code written yet for this just was wanting to see if its possible. If I had 12 different LDRs attached to analog pins of an arduino mega, as well as corresponding LEDs on the digital side. If each LDR detects the lighting at different values due to different location, shadows, ambient lighting etc; what is the math needed to bring all of them to a common value, so all I would need to do is code a single variable to control it if I were to shine a light at each one separately, to light up the LED. (which one the LED is lit, would affect the new ambient lighting, so I would need to adjust it the value for the others again).

for example:

etc...

changed to:
etc..

then changes to this, once I hit it with a light, regardless of what light level it is at:
etc...

You will have 12 integer values (0-1023), add them together and divide by 12. Keep doing this whilst all values are “ similar “. You will need to do some testing to define the numbers . When light levels are high , you might find it hard to discriminate between them .

When a light is shined that one will be significantly different from the others and the background average .

I think it is more complex because the intensity of the light falling on the LDRs varies as the square (or is it the cube?) of the distance from the light to the LDR.

Add to that (IIRC) the non-linear response of the LDRs to light.

And then there is even more complexity if the light being shone on the LEDs has a directional bias - as most torches and LED lamps have.

But maybe I have misunderstood the OP's requirement.

@Rufio it would be a big help if you would post a simple diagram to show what you have in mind. See this Simple Image Posting Guide

...R

I hope your will be posting a pic of your wiring, a schematic and your properly formatted code, in code tags.

The resistance of the Light Dependent Resistor (LDR) varies according to the amount of light that falls on it. The relationship between the resistance RL and light intensity Lux for a typical LDR is RL=500/Lux (1) If the LDR connected to 5V through a 3.3K resistor, using the voltage divider rule, the output voltage of the LDR is Vo=5×RL/(RL+3.3) (2) Substituting RL from equation 1 into equation 2, we obtain the light intensity

I buy a large quantity of LDR's. I expose each one to a light source in a box. I take a dark resistance reading and a lighted resistance reading to find near matching LDR's; yup a tedious process.

Record each LDR reading of the near matched set.

Apply the linked to formula to get a near lux value.

I use the Simple Kalman FIlter library GitHub - denyssene/SimpleKalmanFilter: A basic implementation of Kalman Filter for single variable models. to smooth out the readings.

The LUX value can be your common number of association.