Project Title: Arduino DC Motor Speed and Direction Control Using L298N
Project Title: Arduino DC Motor Speed and Direction Control Using L298N 2bfc897d c75f 4cb9 bc0c 6e470f46

Project Title: Arduino DC Motor Speed and Direction Control Using L298N


1. Introduction

In this project, you’ll control the speed and direction of a DC motor using an Arduino and an L298N motor driver module. This is a core concept in robotics, automation, and any electromechanical system involving motion.

Real-World Applications:

  • Robotic wheels and arms
  • Conveyor belt control
  • Fan speed regulators
  • Automated doors and systems with motorized movement

2. Learning Objectives

  • Understand how to control a motor’s direction using H-Bridge logic.
  • Use PWM (Pulse Width Modulation) to vary motor speed.
  • Interface Arduino with L298N motor driver.
  • Gain hands-on experience with analog and digital signals for actuation.
  • Learn safe power handling for motors.

3. Tools and Components Needed

  • Arduino Uno (or compatible board)
  • DC Motor (6V to 12V)
  • L298N Motor Driver Module
  • External Power Supply (Battery or Adapter, 6V–12V for motor)
  • Jumper Wires
  • Breadboard (optional for powering logic side)
  • Arduino IDE (for code upload)

4. Background Concepts and Definitions

PWM (Pulse Width Modulation):

A technique to simulate analog voltage by rapidly switching a digital pin HIGH and LOW at a given frequency. The duty cycle determines the power delivered:

  • 100% Duty Cycle = Full Speed
  • 50% Duty Cycle = Half Speed

H-Bridge:

An electronic circuit that allows a voltage to be applied across a load in either direction. The L298N is a dual H-Bridge module, capable of controlling two motors independently.

Motor Control Pins (L298N):

  • IN1/IN2: Controls direction of Motor A.
  • ENA: Enables PWM speed control for Motor A.
  • VCC: Power for the motor (6V–12V).
  • GND: Common ground.
  • 5V: Logic power supply for Arduino side.

5. Wiring Guide (No Tables, Just Clear Steps)

Connect DC Motor to L298N:

  • Motor wires to OUT1 and OUT2.

Connect L298N to Arduino:

  • IN1 to Arduino Pin 8
  • IN2 to Arduino Pin 9
  • ENA to Arduino Pin 10 (PWM Pin)

Power Connections:

  • VCC of L298N to external battery + (6V–12V)
  • GND of L298N to external battery and to Arduino GND
  • 5V jumper enabled on L298N to power logic side (check jumper cap)

6. Arduino Code (With Full Explanations)

// Motor control pins
int in1 = 8;
int in2 = 9;
int ena = 10; // PWM-capable pin

void setup() {
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(ena, OUTPUT);
}

void loop() {
  // Rotate motor forward at full speed
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  analogWrite(ena, 255); // 255 = 100% duty cycle
  delay(3000); // Run for 3 seconds

  // Stop motor
  analogWrite(ena, 0);
  delay(1000); // Pause for 1 second

  // Rotate motor backward at half speed
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  analogWrite(ena, 128); // 128 = 50% duty cycle
  delay(3000);

  // Stop motor again
  analogWrite(ena, 0);
  delay(1000);
}

7. Operation Explanation

  • Direction Control:
    • IN1 HIGH + IN2 LOW = Motor spins forward
    • IN1 LOW + IN2 HIGH = Motor spins backward
  • Speed Control:
    • analogWrite(ena, value) sets speed from 0 (stop) to 255 (max speed)
  • Delays are used to demonstrate motion changes over time.

8. Testing and Debugging Tips

  • Motor doesn’t spin?
    • Check motor power (VCC and GND from battery).
    • Ensure jumper cap is placed on 5V enable pin of L298N.
  • Wrong direction?
    • Swap motor wires or switch IN1/IN2 signals.
  • PWM has no effect?
    • Ensure you are using a PWM pin on Arduino (like Pin 10).
  • Arduino resets during motor start?
    • Motors draw high current at startup; ensure stable power with proper capacitors or separate power supply for Arduino and motor.

9. Project Extensions

  • Add a potentiometer to control motor speed manually.
  • Use a joystick or push buttons for interactive direction and speed control.
  • Upgrade to dual motor control for robot car.
  • Integrate Bluetooth module (HC-05) for wireless motor control via smartphone.
  • Add current sensors to monitor motor load.

Wrap-Up

You’ve just learned how to control a DC motor’s speed and direction using Arduino and the L298N motor driver—a core skill for robotics and automation. This project lays the groundwork for building robotic vehicles, automated systems, and smart actuators.

Ready to take it further? Let me know if you’d like to explore servo motor control, stepper motors, or sensor-based motor automation next!