0

I am having a problem with pins of Arduino Uno. I have connected a LED to one of the analog pins (A0), and I want to light up the LED with different intensinty.

int ledPin = A0;
void setup() {
 // put your setup code here, to run once:
 pinMode(ledPin,OUTPUT);

}

void loop() {
 // put your main code here, to run repeatedly:
 analogWrite(ledPin,500);
}

The point is that even if I change the value of analogWrite, the LED lights up always with the same intensity.

1 Answer 1

3

analogWrite deals with PWM pins, those are digital pins. See https://www.arduino.cc/en/Reference/AnalogWrite

So connect the LED to one of the PWM pins and change the sketch accordingly. On the Uno those are pins 3, 5, 6, 9, 10, and 11.

The analog pins A0 - A5 are input pins. The value is read using the analogRead(pin) function.

2
  • 1
    Erik is right, but some LEDs don't have a very wide range of brightness, so you might also hit that issue. Commented Oct 11, 2017 at 9:32
  • 1
    And human light response is not linear.
    – user31481
    Commented Oct 11, 2017 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.