Attiny45 analogRead LDR (newb alert!)

Hello!

Im created a dark sensor circuit with arduino.
Work correct, but im not need a full arduino, enough a little attiny45.
Can you help me, what wrong in this code?

LDR = attiny45 PB2 (sensor)
led = attiny45 PB0

Thank you

int sensor = 2;        //Attiny45 PB2 pin
int led = 0;                       //Attiny45 PB0 pin
int sensorValue;

void setup(){
  pinMode(sensor,INPUT);
  pinMode(led, OUTPUT);
}

void loop(){
  sensorValue = analogRead(sensor);
  if (sensorValue < 500){
    digitalWrite(led, HIGH);
  }
    else{
      digitalWrite(led, LOW);
  }
}

cant see anything wrong.
If it dont work, verify pin capabilities.
for fun:

{
  sensorValue = analogRead(sensor);
  if (sensorValue < 500){
    digitalWrite(led, HIGH);
  }
    else{
      digitalWrite(led, LOW);
  }

can be

{
    digitalWrite(0,analogRead(2)<500);
  }

can be

But shouldn't, as that is way harder to debug and to change!

int sensor = 2;        //Attiny45 PB2 pin

Analog input 2 is PB4 not PB2.

Damn, thanks.

Meanwhile solved, with pin change

int sensor = 3; //ADC3 :slight_smile:

Annoying, when make mistake with like this...