Pages: [1]   Go Down
Author Topic: LDR - Keep getting a reading of 0 in the serial monitor  (Read 373 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Land of Oz
Offline Offline
Jr. Member
**
Karma: 3
Posts: 73
I dream in Assembler
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 90
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: