Bird
Raised Fist0
Arduinoprogramming~20 mins

Motor speed control with PWM in Arduino - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
PWM Motor Control Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
PWM Signal Frequency Calculation

What is the frequency of the PWM signal generated by analogWrite() on an Arduino Uno pin 9 by default?

AApproximately 490 Hz
BApproximately 31 kHz
CApproximately 1 kHz
DApproximately 60 Hz
Attempts:
2 left
💡 Hint

Arduino Uno uses timers with default PWM frequencies around a few hundred Hz on most pins.

❓ Predict Output
intermediate
1:30remaining
Motor Speed Control Code Output

What will be the motor speed value printed by this Arduino code snippet?

int motorPin = 9;
int speed = 128;

void setup() {
  Serial.begin(9600);
  analogWrite(motorPin, speed);
  Serial.println(speed);
}

void loop() {}
Arduino
int motorPin = 9;
int speed = 128;

void setup() {
  Serial.begin(9600);
  analogWrite(motorPin, speed);
  Serial.println(speed);
}

void loop() {}
A64
B255
C0
D128
Attempts:
2 left
💡 Hint

The analogWrite() function sets the PWM duty cycle but does not change the variable.

🔧 Debug
advanced
2:00remaining
Identify the Error in PWM Motor Control Code

What error will this Arduino code cause when trying to control motor speed with PWM?

int motorPin = 9;

void setup() {
  pinMode(motorPin, INPUT);
}

void loop() {
  analogWrite(motorPin, 200);
  delay(1000);
}
Arduino
int motorPin = 9;

void setup() {
  pinMode(motorPin, INPUT);
}

void loop() {
  analogWrite(motorPin, 200);
  delay(1000);
}
AArduino will reset continuously
BNo output, motor will not run because pin is set as INPUT
CMotor runs at full speed ignoring PWM value
DSyntax error due to missing semicolon
Attempts:
2 left
💡 Hint

Check the pin mode before using analogWrite().

🧠 Conceptual
advanced
1:30remaining
PWM Duty Cycle Effect on Motor Speed

Which statement best describes how PWM duty cycle affects the speed of a DC motor?

AHigher duty cycle means higher average voltage, increasing motor speed
BLower duty cycle increases motor speed by reducing voltage
CDuty cycle does not affect motor speed, only direction
DPWM frequency controls speed, duty cycle controls torque
Attempts:
2 left
💡 Hint

Think about how average power to the motor changes with duty cycle.

❓ Predict Output
expert
2:00remaining
PWM Value After Analog Write and Read Back

Consider this Arduino code snippet. What will be the output on the Serial Monitor?

int motorPin = 9;
int pwmValue = 180;

void setup() {
  Serial.begin(9600);
  pinMode(motorPin, OUTPUT);
  analogWrite(motorPin, pwmValue);
  int readValue = analogRead(motorPin);
  Serial.println(readValue);
}

void loop() {}
Arduino
int motorPin = 9;
int pwmValue = 180;

void setup() {
  Serial.begin(9600);
  pinMode(motorPin, OUTPUT);
  analogWrite(motorPin, pwmValue);
  int readValue = analogRead(motorPin);
  Serial.println(readValue);
}

void loop() {}
A1023
B180
CA value between 0 and 1023 depending on noise, usually near 0
DCompilation error due to analogRead on PWM pin
Attempts:
2 left
💡 Hint

Remember that analogRead() reads voltage on analog input pins, not PWM output pins.

Practice

(1/5)
1. What does PWM do in motor speed control on an Arduino?
easy
A. It changes the motor's voltage permanently.
B. It switches power on and off quickly to control speed.
C. It changes the motor's direction.
D. It measures the motor's speed.

Solution

  1. Step 1: Understand PWM function

    PWM (Pulse Width Modulation) controls speed by rapidly switching power on and off.
  2. Step 2: Compare options

    Only It switches power on and off quickly to control speed. correctly describes PWM's role in speed control, others describe different functions.
  3. Final Answer:

    It switches power on and off quickly to control speed. -> Option B
  4. Quick Check:

    PWM controls speed by switching power on/off [OK]
Hint: PWM controls speed by fast power switching [OK]
Common Mistakes:
  • Thinking PWM changes voltage permanently
  • Confusing speed control with direction control
  • Believing PWM measures speed
2. Which Arduino function is used to set motor speed with PWM?
easy
A. pinMode(pin, OUTPUT)
B. digitalWrite(pin, value)
C. analogWrite(pin, value)
D. delay(value)

Solution

  1. Step 1: Identify PWM function

    analogWrite(pin, value) sets PWM signal on a pin with value 0-255 controlling speed.
  2. Step 2: Check other functions

    digitalWrite sets HIGH/LOW only, pinMode sets pin mode, delay pauses code; none control PWM speed.
  3. Final Answer:

    analogWrite(pin, value) -> Option C
  4. Quick Check:

    Use analogWrite for PWM speed control [OK]
Hint: Use analogWrite to set PWM speed value [OK]
Common Mistakes:
  • Using digitalWrite instead of analogWrite
  • Confusing pinMode with speed control
  • Trying to use delay to control speed
3. What will be the motor speed if the code runs
analogWrite(9, 128);
?
medium
A. Motor runs at full speed
B. Motor is off
C. Motor runs at double speed
D. Motor runs at about half speed

Solution

  1. Step 1: Understand PWM value range

    analogWrite value ranges 0 (off) to 255 (full speed). 128 is about half of 255.
  2. Step 2: Interpret speed from value

    Value 128 means roughly half the power, so motor runs at about half speed.
  3. Final Answer:

    Motor runs at about half speed -> Option D
  4. Quick Check:

    128/255 ≈ half speed [OK]
Hint: PWM 128 means about half speed [OK]
Common Mistakes:
  • Thinking 128 means full speed
  • Assuming motor is off at 128
  • Believing speed can be doubled
4. Identify the error in this code snippet for motor speed control:
int speed = 300;
analogWrite(6, speed);
medium
A. Speed value is out of PWM range (0-255).
B. Pin 6 cannot be used for PWM.
C. analogWrite requires three arguments.
D. Variable speed must be declared as float.

Solution

  1. Step 1: Check PWM value limits

    analogWrite accepts values from 0 to 255. 300 is outside this range.
  2. Step 2: Verify other options

    Pin 6 supports PWM, analogWrite takes two arguments, and int is fine for speed.
  3. Final Answer:

    Speed value is out of PWM range (0-255). -> Option A
  4. Quick Check:

    PWM value must be 0-255 [OK]
Hint: PWM values must be 0 to 255 only [OK]
Common Mistakes:
  • Using values above 255 for PWM
  • Thinking analogWrite needs 3 arguments
  • Believing PWM pins are limited incorrectly
5. You want to smoothly increase motor speed from 0 to full over 5 seconds using PWM on pin 10. Which code snippet achieves this?
hard
A. for(int speed=0; speed<=255; speed++) { analogWrite(10, speed); delay(20); }
B. analogWrite(10, 255); delay(5000); analogWrite(10, 0);
C. for(int speed=255; speed>=0; speed--) { analogWrite(10, speed); delay(20); }
D. digitalWrite(10, HIGH); delay(5000); digitalWrite(10, LOW);

Solution

  1. Step 1: Understand smooth speed increase

    Gradually increasing PWM value from 0 to 255 in small steps with delay creates smooth speed change.
  2. Step 2: Analyze code snippets

    for(int speed=0; speed<=255; speed++) { analogWrite(10, speed); delay(20); } uses a for loop from 0 to 255 with delay(20)ms, totaling about 5 seconds. Others either jump speed or use digitalWrite which is not PWM.
  3. Final Answer:

    for(int speed=0; speed<=255; speed++) { analogWrite(10, speed); delay(20); } -> Option A
  4. Quick Check:

    Gradual PWM increase with delay = smooth speed [OK]
Hint: Use for loop with analogWrite and delay for smooth speed [OK]
Common Mistakes:
  • Using digitalWrite instead of analogWrite
  • Jumping speed without gradual steps
  • Not using delay to slow speed change
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard