0Pricing
Arduino & IoT Academy · Lesson

analogWrite 0–255

Set duty cycle to control LED brightness.

The Command That Does PWM

To produce PWM you call one function: analogWrite. You give it a pin and a level, and the chip handles the fast pulsing for you.

analogWrite(9, 200);

The Value Range Is 0 to 255

The second argument goes from 0 to 255. That is 256 steps, because one byte holds exactly that many values.

All lessons in this course

  1. What PWM Actually Does
  2. analogWrite 0–255
  3. Fade an LED Up and Down
  4. Knob Controls LED Brightness
← Back to Arduino & IoT Academy