Bird
0
0
Arduinoprogramming~20 mins

Motor direction with H-Bridge (L293D/L298N) in Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
H-Bridge Motor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the motor direction output?
Given the following Arduino code controlling an H-Bridge motor driver, what will be the motor direction output on pins IN1 and IN2?
Arduino
const int IN1 = 8;
const int IN2 = 9;

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
}

void loop() {
  // Motor runs forward
}
AIN1 = HIGH, IN2 = LOW (Motor rotates forward)
BIN1 = HIGH, IN2 = HIGH (Motor brake)
CIN1 = LOW, IN2 = LOW (Motor stopped)
DIN1 = LOW, IN2 = HIGH (Motor rotates backward)
Attempts:
2 left
💡 Hint
Check the digitalWrite values in setup for IN1 and IN2.
Predict Output
intermediate
2:00remaining
What happens if both IN1 and IN2 are HIGH?
Consider this Arduino code snippet controlling an H-Bridge motor driver. What is the motor behavior when both IN1 and IN2 pins are set HIGH?
Arduino
const int IN1 = 8;
const int IN2 = 9;

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, HIGH);
}

void loop() {
  // Motor brake
}
AMotor rotates forward
BMotor rotates backward
CMotor runs freely (coasting)
DMotor is braking (stopped with resistance)
Attempts:
2 left
💡 Hint
Both inputs HIGH usually activate braking in an H-Bridge.
🔧 Debug
advanced
2:30remaining
Why does the motor not rotate forward?
This Arduino code is intended to rotate the motor forward using an H-Bridge, but the motor does not move. Identify the cause.
Arduino
const int IN1 = 8;
const int IN2 = 9;

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
}

void loop() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
}
AMotor driver requires PWM signals, not digital HIGH/LOW
BdigitalWrite in loop is ignored because setup sets pins LOW
CPins IN1 and IN2 are set LOW in setup, so motor never gets forward signal
DPin modes are not set correctly for output
Attempts:
2 left
💡 Hint
Check the initial pin states in setup and how loop changes them.
📝 Syntax
advanced
1:30remaining
Which code snippet correctly sets motor to rotate backward?
Choose the correct Arduino code snippet that sets the motor to rotate backward using an H-Bridge with pins IN1 and IN2.
A
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
B
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
C
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
D
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
Attempts:
2 left
💡 Hint
Backward rotation is the opposite of forward: IN1 LOW and IN2 HIGH.
🚀 Application
expert
3:00remaining
How to implement motor stop with brake using Arduino and H-Bridge?
You want to stop the motor immediately with braking effect using an H-Bridge (L293D/L298N). Which Arduino code snippet correctly implements this braking?
A
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
B
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
C
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
D
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
Attempts:
2 left
💡 Hint
Braking is done by setting both inputs HIGH to short motor terminals.