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

Arduino-Controlled Robotic Vehicle with Ultrasonic and IR Sensors

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Robotic Vehicle with Ultrasonic and IR Sensors

Circuit Documentation

Summary

The circuit in question is designed to control a pair of DC motors using an L298N motor driver module, interfaced with an Arduino UNO microcontroller. The circuit also includes a pair of IR sensors and an HC-SR04 ultrasonic sensor for distance measurement or obstacle detection. A servo motor is also part of the system, which can be used for steering or other actuation purposes. The entire circuit is powered by 12V batteries, with voltage regulation provided for the 5V components.

Component List

Microcontroller

Sensors

Actuators

Motor Driver

Power Supply

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Sensor

IR Sensors

DC Motors

L298N DC Motor Driver

Servo

12V Battery

Documented Code

// Define motor driver pins
const int motorPin1 = 12; // IN1
const int motorPin2 = 13; // IN2
const int motorPin3 = 10; // IN3
const int motorPin4 = 11; // IN4
const int ENA = 5;
const int ENB = 6;

void setup() {
  // Initialize pins
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);

  // Initialize Serial Monitor
  Serial.begin(9600);
}

void loop() {
  // Beginning test
  Serial.println("Beginning test");

  // Move forward at half speed
  moveForward(128);
  delay(2000);

  // Move backward at full speed
  moveBackward(255);
  delay(2000);

  // Stop rover
  stopMotor();
  delay(1000);
}

// Function to move rover forward
void moveForward(int speed) { // Speed between 0 - 255
  analogWrite(ENA, speed);
  analogWrite(ENB, speed);
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  Serial.println("Motor moving forward");
}

// Function to move rover backward
void moveBackward(int speed) { // Speed between 0 - 255
  analogWrite(ENA, speed);
  analogWrite(ENB, speed);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  Serial.println("Motor moving backward");
}

// Function to stop rover
void stopMotor() {
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);
  Serial.println("Motor stopped");
}

This code is designed to control the motors connected to the L298N motor driver using the Arduino UNO. It includes functions to move the motors forward and backward at specified speeds, as well as to stop the motors. The Serial Monitor is used for debugging purposes, printing out the status of the motors during operation.