Go Down

Topic: Only 1 input reading from LDR on analog input? (Read 617 times) previous topic - next topic

PapaLaz

hi guys,

I have 2 LDR resistors hooked up to test, hoping to make a photovore as my first real project, but no matter what I do i can only get a readout from the first one,

I have the wiring like this:

5v (common) - 1k resistor - (wire to analog pin) + another wire from resistor to LDR - LDR to ground

exactly the same wiring for each LDR, I want to use analog input 0 and 1, but I have tried in every combination accross all the analog pins, and no matter what I try I only get the input for the first LDR, I have tried swapping the LDRs in case one of them was faulty, but no matter what way around all I get is the readout of the first one :(

my code is this:

<code> int reading1;
int reading2;

void setup()
{
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);

}
void loop()
{
  reading1 = analogRead(A0);
  delay(5);
  reading2 = analogRead(A1);
 
  Serial.print("sensor 1 = ");
  Serial.print(reading1);
  Serial.print("  sensor 2 = ");
  Serial.println(reading2);
 
  delay(500);
} </code>

and all i get as a readout is:


I really don't get what I'm doing wrong here, as I know both LDRs work, and the wiring is the same for both, all i can think is either there is something wrong with my code, or something broken in my arduino.

thanks

LarryD

You don't need these lines:
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);

If you change the code to only use A1 what happens?
The way you have it in your schematic isn't the same as how you have it wired up!

PapaLaz

Thanks for replying :)

I tried that, changed the code to:

int reading1;
int reading2;

void setup()
{
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);

}
void loop()
{
  reading1 = analogRead(A0);
  delay(5);
  reading2 = analogRead(A1);
 
  Serial.print("sensor 1 = ");
  Serial.print(reading1);
  Serial.print("  sensor 2 = ");
  Serial.println(reading2);
 
  delay(500);
}


but still just getting the same thing in the Serial Monitor, all the values for the first LDR (Pin A0) are coming through, and just 0 for the second one (Pin A1).

any other ideas? I suppose i could try connecting the second LDR to the digital pins with a capacitor, but I would prefer to have it as analog.

Thanks

Grumpy_Mike

Quote
all i can think is either there is something wrong with my code, or something broken in my arduino.

Well the code is fine. Well it is not posted correctly and you don't need the delay between reads.
So it is either your wiring, no ground from the other LDRs or something is wrong on your arduino.

PapaLaz

I tested it out on a friends arduino and it worked fine, must be a hardware problem with mine, thanks everyone for your help though :)

Go Up