Lesson 06: Controlling Motors — DC Motors & L298N

Course: Robotics & Arduino Lesson 06 of 12

How DC motors work, using the L298N dual motor driver and controlling speed/direction.


Learning Objectives

By the end of this lesson you will be able to:


Hardware Required

See the Kit List on the course overview page for the full component list. For this lesson you will specifically need the components mentioned in the steps below.


Step-by-Step Guide

  1. DC motor basics: two wires, reverse polarity reverses direction, higher voltage = faster spin.
  2. Why a driver? Arduino pins can’t supply enough current for motors. The L298N provides up to 2A per channel.
  3. L298N connections: ENA/ENB for speed (PWM), IN1/IN2 for motor A direction, IN3/IN4 for motor B.
  4. Power: Motor supply (6–12V battery) to L298N Vs and GND. Arduino GND to L298N GND (common ground!).
  5. Wire Motor A: IN1 → pin 7, IN2 → pin 8, ENA → pin 9 (PWM).
  6. Forward: digitalWrite(7,HIGH); digitalWrite(8,LOW); analogWrite(9,200);
  7. Backward: digitalWrite(7,LOW); digitalWrite(8,HIGH); analogWrite(9,200);
  8. Stop: digitalWrite(7,LOW); digitalWrite(8,LOW);
  9. Wire Motor B on IN3/IN4/ENB. Test both motors moving together.
  10. Build helper functions: void forward(int spd), void backward(int spd), void stopAll().

Extension Challenges


Review Questions

  1. Explain in your own words what this lesson’s main component does.
  2. What would happen if you changed one key parameter in your sketch?
  3. How does this lesson’s content connect to the final robot build in Lesson 12?

Troubleshooting Tips


Back to Course Next: Lesson 07