This circuit is designed to control two DC motors using an Arduino UNO and an L298N motor driver. The motors are powered by a 12V battery and can be controlled via PWM signals from the Arduino. A rocker switch is used to control the power supply to the motor driver.
L298N DC Motor Driver
DC Motor (Motor A)
DC Motor (Motor B)
Arduino UNO
12V Battery (Small Size)
Rocker Switch (SPST)
/*
* 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
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}