Arduino UNO and L298N DC Motor Driver Controlled Dual DC Motor System
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control two DC motors using two L298N DC motor drivers and an Arduino UNO microcontroller. The motors are powered by two 12V batteries, and the Arduino UNO is programmed to control the direction of the motors.
Component List
L298N DC Motor Driver
- Description: Dual H-Bridge motor driver
- 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
Arduino UNO
- Description: Microcontroller board based on the ATmega328P
- 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
Battery 12V
- Description: 12V power supply
- Pins: +, -
DC Motor
- Description: Standard DC motor
- Pins: pin 1, pin 2
Wiring Details
L298N DC Motor Driver (1)
- OUT1: Connected to pin 1 of DC Motor (1)
- OUT2: Connected to pin 2 of DC Motor (1)
- 12V: Connected to + of Battery (1)
- GND: Connected to - of Battery (1)
- IN1: Connected to D2 of Arduino UNO
- IN2: Connected to D3 of Arduino UNO
L298N DC Motor Driver (2)
- OUT1: Connected to pin 1 of DC Motor (2)
- OUT2: Connected to pin 2 of DC Motor (2)
- 12V: Connected to + of Battery (2)
- GND: Connected to - of Battery (2)
- IN1: Connected to D4 of Arduino UNO
- IN2: Connected to D5 of Arduino UNO
Arduino UNO
- D2: Connected to IN1 of L298N DC Motor Driver (1)
- D3: Connected to IN2 of L298N DC Motor Driver (1)
- D4: Connected to IN1 of L298N DC Motor Driver (2)
- D5: Connected to IN2 of L298N DC Motor Driver (2)
Battery 12V (1)
- +: Connected to 12V of L298N DC Motor Driver (1)
- -: Connected to GND of L298N DC Motor Driver (1)
Battery 12V (2)
- +: Connected to 12V of L298N DC Motor Driver (2)
- -: Connected to GND of L298N DC Motor Driver (2)
DC Motor (1)
- pin 1: Connected to OUT1 of L298N DC Motor Driver (1)
- pin 2: Connected to OUT2 of L298N DC Motor Driver (1)
DC Motor (2)
- pin 1: Connected to OUT1 of L298N DC Motor Driver (2)
- pin 2: Connected to OUT2 of L298N DC Motor Driver (2)
Code Documentation
int motor1pin1 = 2;
int motor1pin2 = 3;
int motor2pin1 = 4;
int motor2pin2 = 5;
void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// Controlling speed (0 = off and 255 = max speed):
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
delay(3000);
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
delay(3000);
}
Code Explanation
- motor1pin1 and motor1pin2 are connected to pins D2 and D3 of the Arduino UNO, respectively, to control the first motor.
- motor2pin1 and motor2pin2 are connected to pins D4 and D5 of the Arduino UNO, respectively, to control the second motor.
- In the
setup()function, the pins are set as outputs. - In the
loop()function, the motors are controlled to alternate directions every 3 seconds.