My photoresistors give me different feedback

I am working on a project where I am using four photoresistors (GL5539), all from the same package. I used the same circuit as shown in the attachment, using 10k resistors.

When using the following code:

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println(analogRead(A1));
Serial.println(analogRead(A2));
Serial.println(analogRead(A3));
Serial.println(analogRead(A4));
Serial.println();
delay(1000);
}

Then this is what I get in the command window:

23
119
212
1023

Anyone know why my sensorfeedback varies so between the sensors, and hopefully how to fix it?

EDIT: Added picture of circuit in text

Firstly, your code reads A1 to A4 when the wiring shows A2 to A5 connected. Secondly, when changing inputs on the ADC you should discard the first reading - read twice and use only the second reading.

Hi Martin-X, and thank you for your reply.

The circuit shown on the picture shows only the consept of my circuit, it is not mine. I have of course connected the sensors to to A1 - A4 on the Uno.

So, for your second point. Are you telling me that the following code should work better (at least for printing more correct values to the command window)? Why should the first analog reading be discarded?

void setup() {
Serial.begin(9600);
}

void loop() {
float trash = analogRead(A1);
Serial.println(analogRead(A1));

trash = analogRead(A2);
Serial.println(analogRead(A2));

trash = analogRead(A3);
Serial.println(analogRead(A3));

trash = analogRead(A4);
Serial.println(analogRead(A4));
Serial.println();
delay(1000);
}

I used the same circuit as shown in the attachment

The circuit shown on the picture shows only the consept of my circuit, it is not mine.

Why on earth would you post the wrong circuit, when you are asking for advice?

When switching between analog channels, it is generally recommended that you discard the first reading. If you don't want to accept this advice, convince yourself by experimentation.

Finally, photoresistors are not precision measuring devices and vary considerably in their nominal resistance values and sensitivity to light.

One unused reading is only important when the impedance of the circuit is >10kohm. Or when you want a very accurate reading. Not important in this circuit.

Take care with breadboards. The side strips (+ and -) are sometimes interrupted in the middle. You could get 1023 if the ground connection is broken.

Try connecting the LDRs between analogue input and ground. No resistor. And use INPUT_PULLUP in your code. Leo..

You are using the LDR from 5v to the input with R to gnd. This will give “inverted” values as the ADC reads across the R. IE, high value LDR will give low reading. ( Edited this sentence out.)

You may wish to have it this way, but it is common to do it with a R from 5v via the internal pull-up. This has the advantage of protection of the power supply in the event of a short circuit.

Weedpharma

weedpharma: You are using the LDR from 5v to the input with R to gnd. This will give "inverted" values as the ADC reads across the R. IE, high value LDR will give low reading. You are reading how dark it is.

You might have to re-think that. Leo..

Couldn't you easily estimate what to expect from the analogReads by measuring the photoresistor resistances with a multimeter (while not powered) and then doing the math?

DaveEvans: Couldn't you easily estimate what to expect from the analogReads by measuring the photoresistor resistances with a multimeter (while not powered) and then doing the math?

Yes, I would measure the LDR in the [u]average[/u] light I want to use it in, or switch something, and then pick a pull-up resistor that is about the same value. Then it is the most sensitive at that light condition.

For a quick and easy dark sensor, I would just use the internal pullup resistors (INPUT_PULLUP) Leo..