ATTiny85 Analog Read problems

I did everything right in terms of programming the ATTiny, I tested it on an Uno and Nano board and it worked. I basically want to dim an LED with a pot through an arduino but later I switched to an ATTiny for obvious reasons. But while the pot dims the LED down completely on the Uno and Nano, it doesn’t on the Tiny. It turns the LED off after just a few ohms, about a third of the way. Here’s my code:

int pbr;
byte br;

void setup(){
  
  Serial.begin(9600);
  pinMode(0, OUTPUT); //PWM pin for LED
}

void loop(){
  
  Serial.print("BR: ");
  Serial.print(br);
  delay(10);
  Serial.print("  +  Pot: ");
  Serial.println(pbr);
  
  pbr = analogRead(A0); //potentiometer pin
  delay(50);
  br = pbr / 4;
  
  if(pbr <= 180){
    analogWrite(0, 0);
    br = 0;
  }
  if(pbr >= 181){
    pbr = analogRead(A0);
    delay(20);
    br = pbr / 4;
    analogWrite(0, br);
  }
}

If using my ATTinyCore:

Remove the Serial.begin. Per documentation, Serial on the tiny's without hardware serial is a software serial implementation on the AIN0 and AIN1 pins (this allows software serial without interfering with PCINTs, which many people use - the analog comparator interrupt is much less frequently used). AIN0 is on digital pin 0, which is what you're trying to output on.

Also, A0 is on the reset pin - so unless you've disabled reset (possibly on one of those digispark clones or something), as soon as the voltage on that pin goes below about 0.9 x Vcc, the tiny will enter reset state.

Thanks for the reply! I think I haven't disabled reset yet. So how do I do that?

No other pins usable?

You disable it with avrdude from the command line. It's one of the bits in the high fuse.

Once you disable reset, you need a high voltage programmer in order to reprogram it (since reset is needed for programming via ISP) - that's why using the reset pin is for I/O is not popular.

As I noted above, you'll have problems if the Serial.begin() is there, because it tries to use one of the pins you're trying to output on (assuming you're using my core - on most cores, it won't even compile if you reference Serial, since the t85 doesn't have hardware serial. Mine has a software serial named "Serial" to make it easier to port sketches to tinies)

I tried using another pin and commenting out the Serial but that doesn't work either. And I could easily fix this problem if the tiny had a serial connection but I can't see what exactly the problem is.

Then use the builtin software serial (named Serial) for debugging; that's mostly what it's there for!