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 ~: offSo 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
EasyThe 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 withdigitalWrite()
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() {
}
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