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

Arduino-Controlled Dual DC Motor Robot with IR Obstacle Detection

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Dual DC Motor Robot with IR Obstacle Detection

Circuit Documentation

Summary

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.

Component List

Arduino UNO

DC Motor (x2)

L298N DC Motor Driver

12V Battery

IR Sensor (x2)

Wiring Details

Arduino UNO

DC Motors

L298N DC Motor Driver

12V Battery

IR Sensors

Documented Code

// 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.