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

This circuit is designed to control a DC motor using an Arduino UNO microcontroller and an L298N DC motor driver. The Arduino UNO interfaces with the L298N driver to regulate the direction and speed of the motor. A 9V battery provides the power source for the motor driver and indirectly for the Arduino through voltage regulation.

Component List

Arduino UNO

L298N DC Motor Driver

DC Motor

9V Battery

Wiring Details

Arduino UNO

L298N DC Motor Driver

DC Motor

9V Battery

Documented Code

// Define control pins
int ena = 5; // Enable pin for motor speed
int in1 = 6; // Input pin 1 for motor direction
int in2 = 7; // Input pin 2 for motor direction

// Setup function runs once at startup
void setup() {
  // Initialize the motor control pins as outputs
  pinMode(ena, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
}

// Loop function runs repeatedly
void loop() {
  // Clockwise rotation at maximum speed
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  analogWrite(ena, 255);
  delay(2000);

  // Stop the motor
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  delay(2000);

  // Counter-clockwise rotation at maximum speed
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  analogWrite(ena, 255);
  delay(2000);

  // Stop the motor again
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  delay(2000);
}

Note: The code provided controls the motor to rotate in one direction at full speed, stop, rotate in the opposite direction at full speed, and then stop again. This cycle repeats indefinitely.