Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Controlled Dual DC Motor Driver with L298N

Image of Arduino UNO Controlled Dual DC Motor Driver with L298N

Circuit Documentation

Summary of the Circuit

This circuit is designed to control two DC motors using an Arduino UNO microcontroller and an L298N DC motor driver. The Arduino UNO is responsible for generating control signals that are sent to the L298N driver, which in turn drives the motors. The motors can move forward or backward at varying speeds. A 12V battery provides the necessary power for the motors and the motor driver, while the Arduino is powered through its Vin pin.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Purpose: Acts as the control unit for the circuit, generating PWM signals to drive the motors via the L298N motor driver.

L298N DC Motor Driver

  • Description: A dual H-bridge motor driver capable of driving two DC motors.
  • Purpose: Receives control signals from the Arduino UNO to drive the motors in either direction and at varying speeds.

DC Motor (x2)

  • Description: A standard DC motor.
  • Purpose: Converts electrical energy into mechanical motion when driven by the L298N motor driver.

Battery 12V

  • Description: A 12V power source.
  • Purpose: Provides power to the L298N motor driver and the DC motors.

Wiring Details

Arduino UNO

  • GND connected to the ground of the battery and L298N motor driver.
  • Vin connected to the 5V output of the L298N motor driver.
  • Digital pins D6, D7, D8, D9, D10, and D11 connected to the L298N motor driver's IN4, IN3, IN2, IN1, ENA, and ENB respectively.

L298N DC Motor Driver

  • GND connected to the ground of the battery and Arduino UNO.
  • 5V connected to the Vin of the Arduino UNO.
  • 12V connected to the positive terminal of the battery.
  • ENA and ENB connected to digital pins D10 and D11 of the Arduino UNO.
  • IN1, IN2, IN3, and IN4 connected to digital pins D9, D8, D7, and D6 of the Arduino UNO.
  • OUT1 and OUT2 connected to one DC motor.
  • OUT3 and OUT4 connected to the other DC motor.

DC Motors

  • Each motor has two pins connected to the OUT1/OUT2 and OUT3/OUT4 of the L298N motor driver.

Battery 12V

  • Positive terminal connected to the 12V input of the L298N motor driver.
  • Negative terminal connected to the ground of the L298N motor driver and Arduino UNO.

Documented Code

// DEFINE motor driver pins
const int MotorPin1 = 9; // IN1
const int MotorPin2 = 8; // IN2
const int MotorPin3 = 7; // IN3
const int MotorPin4 = 6; // IN4
const int ENA = 10;      // Enable A
const int ENB = 11;      // Enable B

void setup() {
  // Initialize pins for output
  pinMode(MotorPin1, OUTPUT);
  pinMode(MotorPin2, OUTPUT);
  pinMode(MotorPin3, OUTPUT);
  pinMode(MotorPin4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);

  // Initialize serial communication
  Serial.begin(9600);
}

void loop() {
  // Test sequence
  Serial.println("Beginning test, good luck");

  // Move forward at half speed
  moveForward(128);
  delay(2000);

  // Move backward at full speed
  moveBackward(255);
  delay(2000);

  // Stop motor
  stopMotor();
  delay(1000);
}

void moveForward(int speed) {
  // Set motor speed and direction for forward motion
  analogWrite(ENA, speed);
  analogWrite(ENB, speed);
  digitalWrite(MotorPin1, HIGH);
  digitalWrite(MotorPin2, LOW);
  digitalWrite(MotorPin3, HIGH);
  digitalWrite(MotorPin4, LOW);
  Serial.println("Motor moving forward");
}

void moveBackward(int speed) {
  // Set motor speed and direction for backward motion
  analogWrite(ENA, speed);
  analogWrite(ENB, speed);
  digitalWrite(MotorPin1, LOW);
  digitalWrite(MotorPin2, HIGH);
  digitalWrite(MotorPin3, LOW);
  digitalWrite(MotorPin4, HIGH);
  Serial.println("Motor moving backward");
}

void stopMotor() {
  // Stop motor by disabling ENA and ENB
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);
  Serial.println("Motor stopped");
}

This code is designed to control the speed and direction of two DC motors using the L298N motor driver. The moveForward and moveBackward functions control the direction of the motors by setting the appropriate pins high or low. The stopMotor function stops the motors by setting the enable pins to low. The analogWrite function is used to control the speed of the motors by varying the voltage on the enable pins.