Challenge - 5 Problems
PWM Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the PWM duty cycle output by analogWrite()?
Consider the Arduino code below. What is the duty cycle percentage of the PWM signal on pin 9 after running this code?
Arduino
void setup() {
pinMode(9, OUTPUT);
analogWrite(9, 128);
}
void loop() {
// empty
}Attempts:
2 left
💡 Hint
The analogWrite() value ranges from 0 to 255, representing 0% to 100% duty cycle.
✗ Incorrect
The value 128 is about half of 255, so the duty cycle is approximately 50%.
❓ Predict Output
intermediateWhat happens if analogWrite() is called with 0?
What is the output signal on the pin after calling analogWrite(pin, 0)?
Arduino
void setup() {
pinMode(6, OUTPUT);
analogWrite(6, 0);
}
void loop() {
// empty
}Attempts:
2 left
💡 Hint
Think about what a PWM duty cycle of 0 means.
✗ Incorrect
A value of 0 means the PWM signal is always off, so the pin stays LOW.
🔧 Debug
advancedWhy does this analogWrite() code not produce PWM on pin 2?
The code below tries to output PWM on pin 2 but it doesn't work. Why?
Arduino
void setup() {
pinMode(2, OUTPUT);
analogWrite(2, 128);
}
void loop() {
// empty
}Attempts:
2 left
💡 Hint
Check which pins support PWM on your Arduino board.
✗ Incorrect
Not all pins support PWM. On many Arduino boards, pin 2 is not a PWM pin.
🧠 Conceptual
advancedHow does PWM simulate analog voltage with digital pins?
Which statement best explains how PWM output from analogWrite() simulates an analog voltage?
Attempts:
2 left
💡 Hint
Think about how turning a light on and off quickly can look dimmer.
✗ Incorrect
PWM changes the ratio of ON to OFF time quickly, so devices see an average voltage.
❓ Predict Output
expertWhat is the output frequency of analogWrite() PWM on Arduino Uno?
What is the approximate frequency of the PWM signal generated by analogWrite() on pins 5 and 6 of an Arduino Uno?
Attempts:
2 left
💡 Hint
Arduino Uno uses different PWM frequencies on different pins.
✗ Incorrect
Pins 5 and 6 use a PWM frequency of about 980 Hz by default.
