Bird
0
0
Arduinoprogramming~10 mins

Motor direction with H-Bridge (L293D/L298N) 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 direction pin as output.

Arduino
pinMode([1], OUTPUT);
Drag options to blanks, or click blank then click option'
AmotorPin1
BmotorPin2
CmotorSpeed
DanalogPin
Attempts:
3 left
💡 Hint
Common Mistakes
Using the speed pin instead of direction pin.
Forgetting to set the pin mode.
2fill in blank
medium

Complete the code to turn the motor forward by setting motorPin1 HIGH.

Arduino
digitalWrite(motorPin1, [1]);
Drag options to blanks, or click blank then click option'
ALOW
BHIGH
CINPUT
DOUTPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW instead of HIGH.
Confusing pin modes with pin states.
3fill in blank
hard

Fix the error in the code to stop the motor by setting both direction pins LOW.

Arduino
digitalWrite(motorPin1, [1]);
digitalWrite(motorPin2, [1]);
Drag options to blanks, or click blank then click option'
AOUTPUT
BINPUT
CHIGH
DLOW
Attempts:
3 left
💡 Hint
Common Mistakes
Setting one pin HIGH and the other LOW.
Using pin modes instead of pin states.
4fill in blank
hard

Fill both blanks to reverse the motor direction by setting motorPin1 LOW and motorPin2 HIGH.

Arduino
digitalWrite(motorPin1, [1]);
digitalWrite(motorPin2, [2]);
Drag options to blanks, or click blank then click option'
ALOW
BHIGH
CINPUT
DOUTPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Setting both pins HIGH or both LOW.
Mixing up which pin is HIGH or LOW.
5fill in blank
hard

Fill all three blanks to create a 2D array that maps motor states to pin values: forward (motorPin1 HIGH, motorPin2 LOW), reverse (motorPin1 LOW, motorPin2 HIGH), stop (both LOW).

Arduino
int motorStates[3][2] = {
  [1],  // forward
  [2],  // reverse
  [3]   // stop
};
Drag options to blanks, or click blank then click option'
A{HIGH, LOW}
B{LOW, HIGH}
C{LOW, LOW}
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the HIGH/LOW order for forward and reverse.
Using HIGH for stop state.