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

Arduino-Controlled Dual DC Motor Driver Circuit with L298N and SPST Switch

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Dual DC Motor Driver Circuit with L298N and SPST Switch

Circuit Documentation

Summary

This circuit is designed to control two DC motors using an L298N DC motor driver, which is interfaced with an Arduino UNO microcontroller. The motors can be powered on and off using a 12V battery connected through a rocker switch (SPST). The Arduino UNO provides control signals to the L298N driver to regulate the direction and speed of the motors using PWM (Pulse Width Modulation). The circuit is powered by the 12V battery, with the Arduino receiving 5V from its onboard voltage regulator.

Component List

L298N DC Motor Driver

DC Motor (x2)

Arduino UNO

12V Battery (Small Size)

Rocker Switch (SPST)

Wiring Details

L298N DC Motor Driver

DC Motor #1

DC Motor #2

Arduino UNO

12V Battery

Rocker Switch (SPST)

Documented Code

Arduino UNO Code

/*
 * This Arduino sketch controls two DC motors connected to an L298N motor driver.
 * The motors are set to spin in opposite directions, and their speed (RPM) can
 * be controlled using PWM signals. The motor driver is connected to the Arduino
 * as follows:
 * - ENA (Motor A enable) -> D9
 * - IN1 (Motor A input 1) -> D2
 * - IN2 (Motor A input 2) -> D3
 * - ENB (Motor B enable) -> D10
 * - IN3 (Motor B input 1) -> D4
 * - IN4 (Motor B input 2) -> D5
 */

// Define motor control pins
const int ENA = 9;
const int IN1 = 2;
const int IN2 = 3;
const int ENB = 10;
const int IN3 = 4;
const int IN4 = 5;

void setup() {
  // Set all the motor control pins to output mode
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  // Initialize motors to spin in opposite directions
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

void loop() {
  // Set motor speed using PWM (0-255)
  int speed = 128; // Example speed value, can be adjusted
  analogWrite(ENA, speed);
  analogWrite(ENB, speed);

  // Add any additional logic here if needed
}

DC Motor Microcontroller Code

The DC motors in this circuit do not have associated microcontroller code as they are directly controlled by the L298N motor driver, which in turn is controlled by the Arduino UNO.