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

Arduino-Controlled DC Motor with L298N Driver

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

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a DC motor using an Arduino UNO microcontroller and an L298N DC motor driver. The motor's speed and direction are controlled by the Arduino, which sends signals to the L298N driver. The driver, in turn, powers the motor using a 12V battery as the power source. The Arduino's firmware is programmed to alternate the motor's rotation between clockwise and counterclockwise directions every 3 seconds.

Component List

Arduino UNO

L298N DC Motor Driver

12V Battery

DC Motor

Wiring Details

Arduino UNO

L298N DC Motor Driver

12V Battery

DC Motor

Documented Code

// Define motor control pins
int motorPin1 = 8;  // IN1 on L298N
int motorPin2 = 9;  // IN2 on L298N
int enablePin = 10; // EN A on L298N (controls speed)

void setup() {
  // Set motor control pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);

  // Set initial motor speed (255 is full speed, 0 is off)
  analogWrite(enablePin, 200); // Set motor speed to 200 out of 255
}

void loop() {
  // Rotate motor forward (clockwise)
  digitalWrite(motorPin1, HIGH); // Turn on IN1
  digitalWrite(motorPin2, LOW);  // Turn off IN2
  delay(3000);  // Keep running forward for 3 seconds

  // Rotate motor backward (counter-clockwise)
  digitalWrite(motorPin1, LOW);  // Turn off IN1
  digitalWrite(motorPin2, HIGH); // Turn on IN2
  delay(3000);  // Keep running backward for 3 seconds
}

Filename: sketch.ino

Description: This Arduino sketch sets up the motor control pins and initializes the motor speed. In the main loop, it alternates the motor's direction every 3 seconds by toggling the IN1 and IN2 pins of the L298N motor driver.