Problem with generic arduino uno

Hello, today I tried to make a light sensor with the generic arduino, I try to upload the code and it doesn't go, but for the project in tinkercad, it works normally, and when I disconnected the gnd wire, the red led lit up, and the yellow one slightly, but the green one didn't light up, and when I didn't disconnect it completely, both of them lit up very strongly, and it only worked on the gnd input of the analog part, on the power part it didn't work. if anyone can help me I appreciate it.

int valor=0;  
int led1=13; 
int led2=12;
int led3=11;
 
 
void setup(){
  Serial.begin(9600);      
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}
 
 
void loop(){
  
  valor = analogRead(A0);     
  Serial.println(valor);      
  
 if (valor < 600){            
    digitalWrite(led1,HIGH);  
    digitalWrite(led2,LOW);  
    digitalWrite(led3,LOW);   
  }
 if (valor >= 600 && valor <= 900){
    digitalWrite(led1,LOW);   
    digitalWrite(led2,HIGH);  
    digitalWrite(led3,LOW);   
  }
 if (valor >= 900){           
    digitalWrite(led1,LOW);   
    digitalWrite(led2,LOW);   
    digitalWrite(led3,HIGH);  
  }
  delay(200);     
}

We need to see your circuit. Please upload a picture of a diagram. Drawn by hand is Ok

What is connected to A0?

the ldr sensor

What range of values are you getting in the monitor?

what do you mean? I'm a beginner with arduino

A picture of your pc monitor is not necessarily how the hardware is connected in front of you.

ok, is that the angle of the hardware photo is a bit bad, but it's ok

What numbers does Serial.println(valor); show? Did you try shining a bright light on the LDR?
Try these numbers:

int valor=0;  
int led1=13; 
int led2=12;
int led3=11;
 
 
void setup(){
  Serial.begin(9600);      
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}
 
 
void loop(){
  
  valor = analogRead(A0);     
  Serial.println(valor);      
  
 if (valor < 200){            
    digitalWrite(led1,HIGH);  
    digitalWrite(led2,LOW);  
    digitalWrite(led3,LOW);   
  }
 else if (valor < 700){
    digitalWrite(led1,LOW);   
    digitalWrite(led2,HIGH);  
    digitalWrite(led3,LOW);   
  }
 else{           
    digitalWrite(led1,LOW);   
    digitalWrite(led2,LOW);   
    digitalWrite(led3,HIGH);  
  }
  delay(200);     
}

Looks like you have a 220Ω resistor on the LDR instead of 10K.
I hate those blue resistors. :grimacing: Can't tell red from orange from brown.

nothing happens when I put on a bright light

no, it's 10k, it's marked on the packaging, and I replaced it with the same one

they're really bad

Do you have the serial monitor window open?

Is it set to 9600?

Are numbers spilling out as you change the light shining on the LDR?

That's what @mancera1979 meant - the sketch is telling you what the LDR and analogRead() are seeing, which will tell you why it is working or not.

a7

could it be a power problem? it's only connected to the pc's usb

when the light gets closer they get bigger

Should be OK with 220Ω for the LEDs, are you sure they are connected the right way (polarity)?

yes, the resistors are on the positive side of the led

Now tell us how small they get and how big they get.

a7