Problems reading the LDR Value

Hello Arduino friends,

Hopefully I am in the right section of the forum, my apologies if I am not.

Today I wanted to use my LDR (GL5528 LDR) again. I connected it like the circuit that can be seen in the link.

My testing code also comes from that site which is like this:

int sensorPin = A3; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
  Serial.begin(9600); //sets serial port for communication
}
void loop() {
  sensorValue = analogRead(sensorPin); // read the value from the sensor
  Serial.println(sensorValue); //prints the values coming from the sensor on the screen
  delay (100);
}

Until now this has worked fine for me and the LDR values were all correct. When I tried connecting it today, the values that I read when using were not correct. The Arduino did not response at all to t he LDR. In fact, the values rose to 1023, waited for a moment and then it dropped again to 0 and it waited for a moment again. Most of the time this repeated itself.

So, to search for the origin of the problem, I changed the wires, resistor and LDR to new ones. I also changed the 100k resistor to a 10k resistor but it had no effect on the values. Lastly I tried using a different laptop port and a different analog pin but that also did not make any difference.

I honestly do not know what is causing this problem and I hope some of you can help me!

You haven't got some other part of the code talking to the A3 pin?

No, I don't. The code you see in the comment is the only piece of code that I am using right now to test the LDR.

You are perhaps picking up mains interference, but a 10k resistor ought to fix that - have you
investigated the voltage on the pin with a multimeter?

No, I haven't. I unfortunately do not have a multimeter :(.

I also tried using another Arduino Uno, since the Arduino I was using is having a Adafruit Motorshield attached to it. Changing the Arduino did not have any effect either, and I think my other Arduino with motorshield is still working fine. Could the USB cable have to do with the problem?

chineesinspace:
No, I haven't. I unfortunately do not have a multimeter :(.

Do something about it, they don't cost much (do yourself a favour and don't go for the super cheap ones) and an essential tool for anyone working with electronics. It also allows you to check whether your connections are actually there, for example.

Your problem sounds odd to me, no idea where it would go wrong assuming connections are all there. What you describe on values sounds like a floating (unconnected) pin to me.

wvmarle:
do yourself a favour and don't go for the super cheap ones

Why not?

General quality.
Leads that just don't break, good battery life, case that can withstand some abuse, usually better range of values, extra features such as sound for continuity test.

Noted the point about the crap leads and auto-off is useful. I did recently note the lack of the sounder on the DT-830B but I have a lovely Telecom red "buzz box" which is top quality for probing.

What I do like is many at home, one at work, every car, toolbox etc.

Just like screw drivers. You can't have too many of them :slight_smile:

For me it's logic analysers, I have 3 and am considering buying a forth. I'm just thinking of an excuse to do so.

Riva:
For me it's logic analysers, I have 3 and am considering buying a forth. I'm just thinking of an excuse to do so.

Well, if 3 of them fail you will have a 4th ready at hand.

Cannot have a better reason. :slight_smile:

larryd:
Well, if 3 of them fail you will have a 4th ready at hand.

Cannot have a better reason. :slight_smile:

Maybe I will get one that also has an ADC input. Will sometimes save me breaking out one of my scopes as well. ;D