Bird
0
0
Arduinoprogramming~20 mins

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

Choose your learning style9 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.