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

Arduino UNO and L298N Motor Driver Controlled DC Motor with Speed and Direction Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO and L298N Motor Driver Controlled DC Motor with Speed and Direction Control

Circuit Documentation

Summary

This circuit is designed to control a DC motor using an Arduino UNO and an L298N motor driver. The motor is connected to the L298N motor driver, which is powered by a 9V battery. The Arduino UNO is used to control the motor's speed and direction through the L298N motor driver.

Component List

  1. L298N DC Motor Driver

    • Description: A dual H-Bridge motor driver that allows control of the speed and direction of two DC motors.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  2. 9V Battery

    • Description: A standard 9V battery used to power the motor driver.
    • Pins: -, +
  3. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P, used to control the motor driver.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  4. DC Motor

    • Description: A standard DC motor.
    • Pins: pin 1, pin 2

Wiring Details

L298N DC Motor Driver

9V Battery

Arduino UNO

DC Motor

Code Documentation

Arduino Sketch

/*
 * This Arduino sketch controls a DC motor using an L298N motor driver.
 * The motor is connected to the OUT3 and OUT4 pins of the L298N driver.
 * The motor will accelerate in the clockwise direction, then decelerate,
 * and then accelerate in the counter-clockwise direction, and decelerate.
 */

const int IN3 = 5; // Pin connected to IN3 on L298N
const int IN4 = 4; // Pin connected to IN4 on L298N

void setup() {
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

void loop() {
  // Accelerate motor clockwise (CW)
  for (int speed = 0; speed <= 255; speed += 5) {
    analogWrite(IN3, speed);
    analogWrite(IN4, 0);
    delay(50);
  }
  // Decelerate motor clockwise (CW)
  for (int speed = 255; speed >= 0; speed -= 5) {
    analogWrite(IN3, speed);
    analogWrite(IN4, 0);
    delay(50);
  }
  delay(1000); // Stop for 1 second

  // Accelerate motor counter-clockwise (CCW)
  for (int speed = 0; speed <= 255; speed += 5) {
    analogWrite(IN3, 0);
    analogWrite(IN4, speed);
    delay(50);
  }
  // Decelerate motor counter-clockwise (CCW)
  for (int speed = 255; speed >= 0; speed -= 5) {
    analogWrite(IN3, 0);
    analogWrite(IN4, speed);
    delay(50);
  }
  delay(1000); // Stop for 1 second
}

This code initializes the pins connected to the L298N motor driver and controls the speed and direction of the DC motor. The motor accelerates and decelerates in both clockwise and counter-clockwise directions.