Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano Controlled Dual DC Motor Driver Circuit

View and Edit Project In Cirkit DesignerImage of Arduino Nano Controlled Dual DC Motor Driver Circuit

Circuit Documentation

Summary

This circuit is designed to control two DC motors using an Arduino Nano microcontroller and an L298N DC motor driver. The Arduino Nano is responsible for generating control signals that are sent to the L298N driver, which in turn drives the motors. The motors can be moved forward or backward, and their speed can be controlled. The circuit is powered by two 9V batteries, one for the Arduino Nano and the other for the L298N motor driver.

Component List

Arduino Nano

L298N DC Motor Driver

DC Motor (x2)

9V Battery (x2)

Wiring Details

Arduino Nano

L298N DC Motor Driver

DC Motor 1

DC Motor 2

9V Battery 1

9V Battery 2

Documented Code

// Define pin connections
const int motor1Pin1 = 2;  // IN1
const int motor1Pin2 = 3;  // IN2
const int motor2Pin1 = 4;  // IN3
const int motor2Pin2 = 5;  // IN4
const int enableA = 6;      // ENA
const int enableB = 7;      // ENB

void setup() {
  // Set motor control pins as output
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(enableA, OUTPUT);
  pinMode(enableB, OUTPUT);
  
  // Start with motors off
  stopMotors();
}

void loop() {
  // Move motors forward
  moveForward();
  delay(10000);
  
  // Move motors backward
  moveBackward();
  delay(10000);
  
  // Stop motors
  stopMotors();
  delay(1000);
}

void moveForward() {
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin1, HIGH);
  digitalWrite(motor2Pin2, LOW);
  
  // Optional: Set speed (0-255)
  analogWrite(enableA, 255); // Full speed for motor 1
  analogWrite(enableB, 255); // Full speed for motor 2
}

void moveBackward() {
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin1, LOW);
  digitalWrite(motor2Pin2, HIGH);
  
  // Optional: Set speed (0-255)
  analogWrite(enableA, 255); // Full speed for motor 1
  analogWrite(enableB, 255); // Full speed for motor 2
}

void stopMotors() {
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin1, LOW);
  digitalWrite(motor2Pin2, LOW);
}

This code is designed to control the two DC motors connected to the L298N motor driver. The setup() function initializes the motor control pins as outputs and ensures that the motors are stopped at the beginning. The loop() function contains a simple sequence of commands to move the motors forward, then backward, and finally stop them, with delays in between each action. The moveForward(), moveBackward(), and stopMotors() functions are helper functions that set the appropriate pin states to control the motor direction and speed.