Go Down

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

#### core2core

##### Feb 12, 2013, 12:42 pm
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.

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

void setup(){//void setup begin
Serial.begin(9600);
}//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 = ");
Serial.println(ldr);
// set 1 seconds delay to prevent
// flow of massive data
delay(1000);

}//void loop end

#### greywolf271

#1
##### Feb 12, 2013, 03:24 pm
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

#### KeithRB

#2
##### Feb 12, 2013, 06:01 pm
There also is a disconnect between your AnalogRead comment and the AnalogRead statement.

#### markvr

#3
##### Feb 13, 2013, 12:52 am
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...

#### oric_dan

#4
##### Feb 13, 2013, 01:08 am
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
stuff.

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