This question is very similar to this one. I'm using an ESP8266 for which the maximum analogWrite value is 1023 rather than 255 for some other Arduino boards, but I believe the principal is just the same.

I'm driving 3 LEDs directly from 3 outputs via current limiting resistors.

When I turn them on using analogWrite(PIN, 1023) they are not quite a bright as when the same LED is driven by the same pin using digitalWrite(PIN, HIGH). Which leads me to think that either 1023 does not give a 100% duty cycle or the maximum voltage in the analog case is less than that in the digital one. Is this to be expected? Are the pins significant (4,5 and 14)?

Another similar Q&A would lead me to believe they should be the same.

  • Try checking the voltage across the pin but mostly the voltage is lesser by 0.1 while using pwm than just settings the pin High.
    – xbox gamer
    Oct 28, 2020 at 15:30
  • Try measuring the current, and see if there is a difference. It might be true. I know, for example, the STM processors have a low and high-speed outputs, and those have different current handling characteristics. If this is an issue in your application you could buffer the output, by driving an transistor connected to the LED, instead of driving the LED directly.
    – Gerben
    Oct 28, 2020 at 15:54
  • default max is 255. arduino-esp8266.readthedocs.io/en/latest/…
    – Juraj
    Oct 28, 2020 at 16:38
  • The default range was originally 1023 so it is a a little bit different from version to version
    – xbox gamer
    Oct 28, 2020 at 16:57
  • sorry, yes it is 1023. the doc is changed for 3.0.0
    – Juraj
    Oct 28, 2020 at 18:20

1 Answer 1


I can confirm that 1023 does indeed give 100% duty cycle. I connected an output of my D1 Mini to my oscilloscope and got a steady voltage.

I can also confirm that the same voltage is output for digitalWrite() and analogWrite().

However the output drivers may not be the same. With analogWrite() it may be using a weaker output driver that can't deliver as much current, so the voltage droops slightly more than it would with digitalWrite(). However even with a 470Ω resistor connected between the output and GND (the smallest value I had easily to hand in a through hole variant) I see no variation in the voltage at all.

So if there is some variation then it might be some variable that is showing a variation in your specific unit but not mine.

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.