analog read on attiny13

int potPin = 4;
int motorPin = 1;
int potValue = 0;
int motorValue = 0;
void setup()
{
pinMode(motorPin, OUTPUT);
}
void loop()
{
potValue = analogRead(potPin);
motorValue = map(potValue, 0, 1023, 0, 255);
analogWrite(motorPin, motorValue);
delay(20);
}

Is there anything wrong with this code? I am trying to control the PWM to a DC motor. My AnalogRead function doesn't seem to work. PWM is fine cos i substituted a numerical value in the place of motorValue and its working.

Which core are you using ?

If you are using smeezekitty core, and you connect the potmeter wiper to pin PB4, you are using ADC2.

So this line

int potPin = 4;

should be

int potPin = 2;

Which PHYSICAL PIN on the chip are you connecting the analog input to?
ADC0 = pin-1
ADC1= Pin-7
ADC2= Pin=3
ADC3= Pin-2
SEE ATTACHED DATASHEET , PAGE-1

atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf (3.67 MB)

Sorry for late reply, I connected on Physical pin 3

DITTO Reply#1

Thanks guys...

That’s it ? You’re done ? (in less than 5 Replies ? I can’t believe it…)