Bird
0
0
Arduinoprogramming~10 mins

DC motor with transistor driver in Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the motor pin as an output.

Arduino
const int motorPin = 9;

void setup() {
  pinMode([1], OUTPUT);
}

void loop() {
  // Motor control code here
}
Drag options to blanks, or click blank then click option'
AINPUT
BmotorPin
C9
DpinMode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the number 9 directly instead of the variable name.
Using INPUT instead of OUTPUT.
2fill in blank
medium

Complete the code to turn the motor ON by setting the pin HIGH.

Arduino
const int motorPin = 9;

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

void loop() {
  digitalWrite(motorPin, [1]);
  delay(1000);
  digitalWrite(motorPin, LOW);
  delay(1000);
}
Drag options to blanks, or click blank then click option'
AHIGH
BLOW
COUTPUT
DINPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW instead of HIGH to turn the motor ON.
Confusing pinMode values with digitalWrite values.
3fill in blank
hard

Fix the error in the code to correctly control the motor speed using PWM.

Arduino
const int motorPin = 9;

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

void loop() {
  analogWrite(motorPin, [1]);
  delay(1000);
}
Drag options to blanks, or click blank then click option'
AOUTPUT
BHIGH
C255
DdigitalWrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using HIGH instead of a numeric PWM value.
Using digitalWrite instead of analogWrite.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps motor speeds to their PWM values if speed is greater than 100.

Arduino
int speeds[] = {50, 120, 200};

void setup() {
  // This is a conceptual example, Arduino C++ does not support dictionary comprehensions
  // Imagine a map: {speed: [1] for speed in speeds if speed [2] 100}
}

void loop() {}
Drag options to blanks, or click blank then click option'
Aspeed * 2
B<
C>
Dspeed + 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Using incorrect expressions for the value.
5fill in blank
hard

Fill all three blanks to create a function that sets motor speed only if the speed is within 0 to 255.

Arduino
const int motorPin = 9;

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

void setMotorSpeed(int speed) {
  if (speed [1] 0 && speed [2] 255) {
    analogWrite(motorPin, [3]);
  }
}

void loop() {
  setMotorSpeed(200);
}
Drag options to blanks, or click blank then click option'
A>=
B<=
Cspeed
DmotorPin
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Passing motorPin instead of speed to analogWrite.