Menu
CoddyTech

PWM Pins Marked With ~

Part of the Outputs section of Coddy's Arduino journey. Lesson 2 of 24.

Only some pins can do PWM. On the Uno they are pins 3, 5, 6, 9, 10 and 11, and the board prints a ~ next to each of them.

On any other pin, analogWrite() cannot dim. It rounds instead: a value below 128 turns the pin off, and 128 or more turns it fully on.

analogWrite(9, 85);  // pin 9 has a ~: on a third of the time
analogWrite(8, 85);  // pin 8 has no ~: off

So when you wire an LED you want to dim, put it on a ~ pin. An LED that only needs on and off can go anywhere, with digitalWrite().

challenge icon

Challenge

Easy

The blue LED is on pin 9 and the yellow LED on pin 8.

  • dim the blue LED to a third of its brightness: analogWrite() with 85
  • pin 8 has no ~, so turn the yellow LED fully on with digitalWrite()

Press Run, then Check.

Try it yourself

const int bluePin = 9;    // a ~ pin
const int yellowPin = 8;  // no ~

void setup() {
  pinMode(bluePin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  // dim the blue LED to a third, and turn the yellow LED fully on
}

void loop() {
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Outputs

Practice on your own: Arduino playground