Go Down

Topic: LDR - Keep getting a reading of 0 in the serial monitor (Read 547 times) previous topic - next topic


I have a bunch of LDR and I have used this example, directly connect the resistor to Analog 0 and GND, but I keep getting the reading of 0 in the serial monitor.

// declare a variable to store
// light dependent resistor
// reading
int ldr;

void setup(){//void setup begin
}//void setup end
void loop() {//void loop begin

// set the value of ldr
// as analogRead(A0)
ldr = analogRead(0);
// pring the reading on serial
// monitor
Serial.print("ldr reading = ");
// set 1 seconds delay to prevent
// flow of massive data

}//void loop end


Since the purpose of this forum is also to make you think for yourself and not be a substitute for basic electonics knowledge:
1) look up light dependent RESISTOR on wiki.
2) think about what sort of circuit is needed for a resistor.
3) put 1 and 2 together to figure out why an input pin is giving you 0 volts


There also is a disconnect between your AnalogRead comment and the AnalogRead statement.


I think you need to connect it so when there is low resistance, the pin connects to 5v, and when it's high resistance, it connects to gnd (or vice versa I guess).  Related to the idea of pull up and pull down resistors.   Or you could try and connect it between 5v and A0, with another resistor in series so it doesn't short when the LDR is low resistance.  I think...


An LDR needs to be setup in a voltage divider configuration. If its value is 10K at
ambient light levels, then you should use a 10K pullup.

Other than that, wolf is 100% correct. You could have figured this out yourself in
30-seconds by doing a google search on how LDRs work. They're very simple. You
need to learn something about electronics if you're going to be doing electronics

The other thing is, you need to buy yourself a DMM [look it up], and if you had one,
you'd have seen that the voltage on the ADC pin was always 0V.

Also, use the "code" symbol = #, instead of the quote symbol for code.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131