

This circuit is designed to control a pair of DC motors using an Arduino UNO microcontroller and an L298N DC motor driver. It includes two IR sensors for input, which are likely used for line tracking or obstacle detection. The motors are powered by a 12V 7Ah battery, and a rocker switch is used to control the power supply to the motor driver. The Arduino UNO is programmed to read the IR sensor inputs and accordingly control the speed and direction of the motors through the L298N driver.
5V and GND pins are connected to the 5V and ground buses, respectively, providing power to the IR sensors.D5 to D12 are used to interface with the L298N motor driver and the IR sensors.5V pin is connected to the 5V bus.GND pin is connected to the ground bus.12V pin is connected to the rocker switch to receive power from the battery.ENA and ENB pins are connected to Arduino pins D6 and D5 for enabling the motor outputs.IN1 to IN4 pins are connected to Arduino pins D7 to D10 for controlling the motor directions.OUT1 to OUT4 pins are connected to the DC motors.VCC pins are connected to the 5V bus.GND pins are connected to the ground bus.OUT pins are connected to Arduino pins D11 and D12.OUT1/OUT3 of the motor driver.OUT2/OUT4 of the motor driver.12v + pin is connected to one terminal of the rocker switch.12v - pin is connected to the ground bus.12V pin of the motor driver.12v + pin of the battery.#define IR_SENSOR_RIGHT 11
#define IR_SENSOR_LEFT 12
#define MOTOR_SPEED 180
// Right motor
int enableRightMotor = 6;
int rightMotorPin1 = 7;
int rightMotorPin2 = 8;
// Left motor
int enableLeftMotor = 5;
int leftMotorPin1 = 9;
int leftMotorPin2 = 10;
void setup() {
// Configure timer for PWM frequency adjustment
TCCR0B = TCCR0B & B11111000 | B00000010;
// Set motor driver pins as outputs
pinMode(enableRightMotor, OUTPUT);
pinMode(rightMotorPin1, OUTPUT);
pinMode(rightMotorPin2, OUTPUT);
pinMode(enableLeftMotor, OUTPUT);
pinMode(leftMotorPin1, OUTPUT);
pinMode(leftMotorPin2, OUTPUT);
// Set IR sensor pins as inputs
pinMode(IR_SENSOR_RIGHT, INPUT);
pinMode(IR_SENSOR_LEFT, INPUT);
// Initialize motors to stop
rotateMotor(0, 0);
}
void loop() {
// Read IR sensor values
int rightIRSensorValue = digitalRead(IR_SENSOR_RIGHT);
int leftIRSensorValue = digitalRead(IR_SENSOR_LEFT);
// Control logic based on sensor input
if (rightIRSensorValue == LOW && leftIRSensorValue == LOW) {
// Move forward
rotateMotor(MOTOR_SPEED, MOTOR_SPEED);
} else if (rightIRSensorValue == HIGH && leftIRSensorValue == LOW) {
// Turn right
rotateMotor(-MOTOR_SPEED, MOTOR_SPEED);
} else if (rightIRSensorValue == LOW && leftIRSensorValue == HIGH) {
// Turn left
rotateMotor(MOTOR_SPEED, -MOTOR_SPEED);
} else {
// Stop
rotateMotor(0, 0);
}
}
void rotateMotor(int rightMotorSpeed, int leftMotorSpeed) {
// Set motor direction and speed
if (rightMotorSpeed < 0) {
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, HIGH);
} else if (rightMotorSpeed > 0) {
digitalWrite(rightMotorPin1, HIGH);
digitalWrite(rightMotorPin2, LOW);
} else {
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, LOW);
}
if (leftMotorSpeed < 0) {
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, HIGH);
} else if (leftMotorSpeed > 0) {
digitalWrite(leftMotorPin1, HIGH);
digitalWrite(leftMotorPin2, LOW);
} else {
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, LOW);
}
// Apply PWM to enable pins
analogWrite(enableRightMotor, abs(rightMotorSpeed));
analogWrite(enableLeftMotor, abs(leftMotorSpeed));
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the motor driver and IR sensor pins, then enters a loop where it reads the IR sensor values and controls the motors accordingly. The rotateMotor function is used to set the direction and speed of the motors based on the sensor inputs.