Projects / DC motor direction and speed lab

DC motor direction and speed lab

Beginner30 minGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNO

    Wire the driver

    Connect ENA, IN1, IN2 and the motor as in the table; take the ENA jumper off.

  2. UNO

    Power it

    Connect the AA pack and share the ground with the Uno.

  3. UNO

    Run forward

    Turn the pot to speed it up.

  4. UNO

    Reverse

    Press the button twice: brake, then reverse.

  5. UNO

    Look at speed

    Watch the speed value on the serial monitor.

  6. UNO

    Compare brake and coast

    Set ENA to 0 to coast and note how long it spins.

  7. UNO

    Check the heat

    Feel the driver heatsink after a minute.

In short

How do you build a DC motor direction and speed lab?

Drive a DC motor forward, backward and at different speeds with an L298N. You need Arduino Uno R3, L298N Dual H-Bridge Module, TT gear motor 3 to 6 V, Potentiometer 10 kΩ, Tactile push button 6 mm, Battery holder 4 × AA with switch, AA alkaline battery × 4, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 30 minutes.

Level
Beginner
Time
About 30 min
Parts
9

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
L298N ENAUno D9 (PWM)Speed, remove the jumper on ENA
L298N IN1Uno D7Direction
L298N IN2Uno D8Direction
L298N OUT1 and OUT2Motor wiresMotor
4 AA holder +L298N 12 V terminalMotor supply, about 6 V
4 AA holder -L298N GND and Uno GNDCommon ground
Potentiometer wiperUno A0Speed control, ends on 5V and GND
ButtonUno D2 and GNDBrake and coast toggle

Code

The L298N has two H-bridges. With IN1 high and IN2 low the motor turns one way, the opposite way with them swapped, and ENA sets the average voltage using PWM. The module drops about 2 V, so a 6 V pack gives the motor about 4 V, which is plenty for a TT gear motor. Keep the 5 V jumper on the driver as it is and do not connect the driver's 5 V terminal to the Uno; power the Uno from USB. The ground of the motor supply and the Uno must be joined. The driver heatsink can get warm at higher currents, so keep the load small and do not stall the motor for long. Arduino IDE, board "Arduino Uno" (or "Arduino Nano" with processor ATmega328P).

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// L298N: ENA sets speed with PWM, IN1 and IN2 set direction.
const byte ENA = 9, IN1 = 7, IN2 = 8, POT = A0, BTN = 2;
bool forward = true;
bool lastBtn = HIGH;
bool brake = false;

void setup() {
  pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  pinMode(BTN, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  // Button: first press brakes, next press runs the other way
  bool b = digitalRead(BTN);
  if (b == LOW && lastBtn == HIGH) {
    delay(30);
    if (!brake) { brake = true; }
    else { brake = false; forward = !forward; }
  }
  lastBtn = b;

  int speed = analogRead(POT) / 4;          // 0 to 255
  if (brake) {
    digitalWrite(IN1, HIGH); digitalWrite(IN2, HIGH);   // both inputs high with enable on brakes the motor
    analogWrite(ENA, 255);
  } else {
    digitalWrite(IN1, forward ? HIGH : LOW);
    digitalWrite(IN2, forward ? LOW : HIGH);
    analogWrite(ENA, speed);
  }
  Serial.println(speed);
  delay(20);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

128
127
128
127
128
127

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Pot at zeroMotor stopped
Pot raisedFaster
Button pressed onceMotor brakes
Button pressed againRuns the other way

If it does not work

Motor does not move

Check the ENA jumper is removed and PWM is on D9, and the common ground.

Only one direction

Check IN1 and IN2 wiring.

Motor weak

Fresh batteries and the 2 V drop; check the supply.

Uno resets

Power it from USB, not the motor pack.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the DC motor direction and speed lab?

Arduino Uno R3, L298N Dual H-Bridge Module, TT gear motor 3 to 6 V, Potentiometer 10 kΩ, Tactile push button 6 mm, Battery holder 4 × AA with switch, AA alkaline battery × 4, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the DC motor direction and speed lab take to build?

About 30 minutes for a beginner maker, in 7 steps.

How do I know the DC motor direction and speed lab works?

Pot at zero: Motor stopped. Pot raised: Faster. Button pressed once: Motor brakes.

Motor does not move: what should I check?

Check the ENA jumper is removed and PWM is on D9, and the common ground.

Only one direction: what should I check?

Check IN1 and IN2 wiring.

Motor weak: what should I check?

Fresh batteries and the 2 V drop; check the supply.

Uno resets: what should I check?

Power it from USB, not the motor pack.