Problem with LDR

Good afternoon, I have a problem with a photoresistor I would like to know if anyone can help me. I am doing a project in arduino with the LDR with 5 leds connected, when there is little light they should turn on, when there is light they will turn off. But when it gives the light to the LDR the value stays fixed in 1023 and no longer changes, it becomes cycled. What is the problem?

Thank you very much, I put my code and the connection.

int pinLed1=12;
int pinLed2=11;
int pinLed3=10;
int pinLed4=9;
int pinLed5=8;

int pinLDR=A0;

int valorLDR = 0;

void setup() {
  pinMode(pinLed1,OUTPUT);
  pinMode(pinLed2,OUTPUT);
  pinMode(pinLed3,OUTPUT);
  pinMode(pinLed4,OUTPUT);
  pinMode(pinLed5,OUTPUT);
  Serial.begin(9600);
  analogReference(EXTERNAL);
}
void loop() {
  valorLDR=analogRead(pinLDR);
  //valorLDR=map(valorLDR, sensorMin, sensorMax, 0, 255);

  //valorLDR= constrain(valorLDR,0,255);
  
  if(valorLDR <=575)
  {
    digitalWrite(pinLed1,LOW);
    digitalWrite(pinLed2,LOW);
    digitalWrite(pinLed3,LOW);
    digitalWrite(pinLed4,LOW);
    digitalWrite(pinLed5,LOW);
  }
  else if(valorLDR >=576 & valorLDR <=600)
  {
    digitalWrite(pinLed1,HIGH);
    digitalWrite(pinLed2,LOW);
    digitalWrite(pinLed3,LOW);
    digitalWrite(pinLed4,LOW);
    digitalWrite(pinLed5,LOW);
  }
  else if(valorLDR >=601 & valorLDR <=625)
  {
    digitalWrite(pinLed1,HIGH);
    digitalWrite(pinLed2,HIGH);
    digitalWrite(pinLed3,LOW);
    digitalWrite(pinLed4,LOW);
    digitalWrite(pinLed5,LOW);
  }
  else if(valorLDR >=626 & valorLDR <=640)
  {
    digitalWrite(pinLed1,HIGH);
    digitalWrite(pinLed2,HIGH);
    digitalWrite(pinLed3,HIGH);
    digitalWrite(pinLed4,LOW);
    digitalWrite(pinLed5,LOW);
  }
  else if(valorLDR >=641 & valorLDR <=651)
  {
    digitalWrite(pinLed1,HIGH);
    digitalWrite(pinLed2,HIGH);
    digitalWrite(pinLed3,HIGH);
    digitalWrite(pinLed4,HIGH);
    digitalWrite(pinLed5,LOW);
  }
  else if(valorLDR > 652)
  {
    digitalWrite(pinLed1,HIGH);
    digitalWrite(pinLed2,HIGH);
    digitalWrite(pinLed3,HIGH);
    digitalWrite(pinLed4,HIGH);
    digitalWrite(pinLed5,HIGH);
  }  
  delay(250);
  Serial.println(valorLDR);
  
}

captura.PNG

THis is a PhotoRESISTOR. It does not generate a voltage.

What is your circuit??

You need the Photoresistor in series with a resistor such as 10K, and the A0 inout connected to the junction of the photoresistor and the resistor.

So the circuit (If you want more-positive voltage for more light) is

+5V -- PhotoResistor(1)
PhotoResistor(2) -- (A0) -- Resistor (1)
Resistor(20 -- Ground

Let us know..

Heres a neat trick. After you attach an image to a post and save it, right-click on the attached image and “copy link location”. Re-edit your post and click the image button on the toolbar, paste the image location you just copied and its now included in the post! (Its a mystery why the forum software cant do this automatically)

8df88e6132a6698ec1de0e61d24e01d720d2b725.png

What is the resistance of your LDR in dark and light conditions? It may be you need a different value for the resistor thats connected to it.

I use a 10K resistance in the ldr,

What is the resistance of your LDR in dark and light conditions? It may be you need a different value for the resistor thats connected to it.

The resistance in darkness is 513 and in light is 820, thank you for answer. And I have a 10K resistor connected in series with the LDR and A0

What readings do you get if you use the default analogReference() (that is, comment out that statement).

If those values of resistance are correct (most LDR's I've seen reduce resistance in light rather than increase) then you should use a much smaller series resistor, maybe 470 or 680.

But if your getting 1023 all the time regardless then its most likely you have a wiring error.