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:


void loop() {
 // put your main code here, to run repeatedly:

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


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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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