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

Arduino Nano Controlled Dual DC Motor System with L298N Driver

View and Edit Project In Cirkit DesignerImage of Arduino Nano Controlled Dual DC Motor System with L298N Driver

Circuit Documentation

Summary

This circuit is designed to control two DC motors using an Arduino Nano and an L298N DC motor driver. The Arduino Nano sends control signals to the L298N motor driver, which in turn drives the motors. A 12V battery powers the entire setup.

Component List

Arduino Nano

L298N DC Motor Driver

DC Motor (Motor A)

DC Motor (Motor B)

12V Battery

Wiring Details

Arduino Nano

L298N DC Motor Driver

DC Motor (Motor A)

DC Motor (Motor B)

12V Battery

Code Documentation

// #include <Arduino.h>

#define ENA_PIN 9
#define IN1_PIN 8
#define IN2_PIN 7
#define ENB_PIN 11
#define IN3_PIN 12
#define IN4_PIN 10

void setup() {
    // Initialize motor pins as outputs
    pinMode(ENA_PIN, OUTPUT);
    pinMode(IN1_PIN, OUTPUT);
    pinMode(IN2_PIN, OUTPUT);
    pinMode(ENB_PIN, OUTPUT);
    pinMode(IN3_PIN, OUTPUT);
    pinMode(IN4_PIN, OUTPUT);
}

void loop() {
    // Motor A Clockwise
    digitalWrite(IN1_PIN, HIGH);
    digitalWrite(IN2_PIN, LOW);

    for (int speed = 0; speed <= 255; speed++) {
        analogWrite(ENA_PIN, speed);
        delay(10);
    }

    delay(1000); // Full speed for 1 second

    // Motor A Counter-Clockwise
    digitalWrite(IN1_PIN, LOW);
    digitalWrite(IN2_PIN, HIGH);

    for (int speed = 255; speed >= 0; speed--) {
        analogWrite(ENA_PIN, speed);
        delay(10);
    }

    delay(1000); // Stop for 1 second

    // Motor B Clockwise
    digitalWrite(IN3_PIN, HIGH);
    digitalWrite(IN4_PIN, LOW);

    for (int speed = 0; speed <= 255; speed++) {
        analogWrite(ENB_PIN, speed);
        delay(10);
    }

    delay(1000); // Full speed for 1 second

    // Motor B Counter-Clockwise
    digitalWrite(IN3_PIN, LOW);
    digitalWrite(IN4_PIN, HIGH);

    for (int speed = 255; speed >= 0; speed--) {
        analogWrite(ENB_PIN, speed);
        delay(10);
    }

    delay(1000); // Stop for 1 second
}

This code initializes the motor control pins on the Arduino Nano and then runs a loop to control the speed and direction of two DC motors connected to the L298N motor driver. The motors are driven in both clockwise and counter-clockwise directions with varying speeds.