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 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