This circuit is designed to control two DC motors using an Arduino UNO microcontroller and an L298N DC motor driver. The circuit also includes two IR sensors for input and a 12V battery as the power source. The Arduino UNO is programmed to interpret signals from the IR sensors and drive the motors accordingly, allowing for forward and backward movement as well as stopping the motors.
3.3V
connected to VCC of both IR sensors.GND
connected to the ground of the battery, L298N motor driver, and both IR sensors.D13
connected to the output of one IR sensor.D12
connected to the output of the other IR sensor.D11
connected to ENB on the L298N motor driver.D10
connected to ENA on the L298N motor driver.D9
connected to IN1 on the L298N motor driver.D8
connected to IN2 on the L298N motor driver.D7
connected to IN3 on the L298N motor driver.D6
connected to IN4 on the L298N motor driver.pin 1
connected to OUT4 and pin 2
to OUT3 on the L298N motor driver.pin 1
connected to OUT2 and pin 2
to OUT1 on the L298N motor driver.12V
connected to the positive terminal of the battery.GND
connected to the negative terminal of the battery and GND of the Arduino UNO.+
connected to 12V on the L298N motor driver.-
connected to GND on the L298N motor driver.VCC
connected to 3.3V on the Arduino UNO.GND
connected to GND on the Arduino UNO.out
connected to D13 on the Arduino UNO.out
connected to D12 on the Arduino UNO.// Define motor driver pins
const int motorpin1 = 2; // IN1 forward
const int motorpin2 = 3; // IN2
const int motorpin3 = 4; // IN3 forward
const int motorpin4 = 5; // IN4
const int ENA = 9;
const int ENB = 10;
const int IRL = 7; // Left IR sensor
const int IRR = 6; // Right IR sensor
int R; // Right IR sensor value
int L; // Left IR sensor value
void setup() {
// Initialize motor driver pins as outputs
pinMode(motorpin1, OUTPUT);
pinMode(motorpin2, OUTPUT);
pinMode(motorpin3, OUTPUT);
pinMode(motorpin4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
}
void loop() {
// Print a message to the serial monitor
Serial.println("Begin testing");
// Read the IR sensor values
R = digitalRead(IRR);
L = digitalRead(IRL);
// Print the IR sensor values to the serial monitor
Serial.println(IRR);
Serial.println(IRL);
// TODO: Implement the logic based on IR sensor values
// if (condition) {
// // Perform actions based on sensor readings
// }
}
// Function to move the car forward
void moveForward(int speed) {
// Motor 1 forward
analogWrite(ENA, speed);
digitalWrite(motorpin1, HIGH);
digitalWrite(motorpin2, LOW);
// Motor 2 forward
analogWrite(ENB, speed);
digitalWrite(motorpin3, HIGH);
digitalWrite(motorpin4, LOW);
// Print a message to the serial monitor
Serial.println("Motor moving forward");
}
// Function to move the car backward
void moveBackward(int speed) {
// Motor 1 backward
analogWrite(ENA, speed);
digitalWrite(motorpin2, HIGH);
digitalWrite(motorpin1, LOW);
// Motor 2 backward
analogWrite(ENB, speed);
digitalWrite(motorpin4, HIGH);
digitalWrite(motorpin3, LOW);
// Print a message to the serial monitor
Serial.println("Motor moving back");
}
// Function to stop the car
void stop() {
// Turn off all motors
digitalWrite(ENA, LOW);
digitalWrite(ENB, LOW);
digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin3, LOW);
digitalWrite(motorpin4, LOW);
// Print a message to the serial monitor
Serial.println("Stopped");
}
Note: The code provided is incomplete and contains placeholders for logic based on IR sensor values. The user should complete the implementation according to the specific requirements of the application.