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

Arduino UNO-Based Obstacle Avoidance Robot with IR Sensors and Ultrasonic Sensor

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Obstacle Avoidance Robot with IR Sensors and Ultrasonic Sensor

Circuit Documentation

Summary

This circuit is designed to control a robot with automatic and manual navigation capabilities. It includes an Arduino UNO microcontroller interfaced with IR sensors, an HC-SR04 ultrasonic sensor, DC motors, an L298N motor driver, an ESP32-CAM module, and a power supply consisting of 18650 Li-ion batteries. The robot can navigate autonomously by following a line and avoiding obstacles, or it can be controlled manually through serial commands. The ESP32-CAM module can be used for additional functionalities such as video streaming or image capture.

Component List

Arduino UNO

IR Sensors

DC Motors

HC-SR04 Ultrasonic Sensor

L298N DC Motor Driver

18650 Li-ion Batteries

ESP32-CAM

Rocker Switches

Wiring Details

Arduino UNO

IR Sensors

DC Motors

HC-SR04 Ultrasonic Sensor

L298N DC Motor Driver

18650 Li-ion Batteries

ESP32-CAM

Rocker Switches

Documented Code

#include <SPI.h>
#include <MFRC522.h>

// Define sensor pins
const int leftSensorPin = 2;
const int rightSensorPin = 3;
const int trigPin = 16;
const int echoPin = 17;

// Define motor pins
const int motor1Enable = 10;
const int motor1In1 = 9;
const int motor1In2 = 8;
const int motor2In3 = 7;
const int motor2In4 = 6;
const int motor2Enable = 5;
// Define RFID pins
#define RST_PIN 14
#define SS_PIN 15

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create instance of the RFID reader

bool manualMode = false; // Flag for manual mode

void setup() {
  // Initialize motor pins
  pinMode(motor1Enable, OUTPUT);
  pinMode(motor1In1, OUTPUT);
  pinMode(motor1In2, OUTPUT);
  pinMode(motor2Enable, OUTPUT);
  pinMode(motor2In3, OUTPUT);
  pinMode(motor2In4, OUTPUT);

  // Initialize sensor pins
  pinMode(leftSensorPin, INPUT);
  pinMode(rightSensorPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // RFID initialization
  SPI.begin();        // Start SPI communication
  mfrc522.PCD_Init(); // Init MFRC522 module

  Serial.begin(9600);  // For debugging
}

void loop() {
  if (Serial.available() > 0) {
    char command = Serial.read();
    handleCommand(command);
  }

  if (!manualMode) {
    autoNavigate(); // Only run automatic navigation if not in manual mode
  }
}

void handleCommand(char command) {
  // Handle serial commands for manual control
}

// Main navigation logic
void autoNavigate() {
  // Autonomous navigation logic
}

// Function to calculate the distance using ultrasonic sensor
long getUltrasonicDistance() {
  // Ultrasonic distance measurement logic
}

// Function to move robot forward slowly for RFID scan
void slowlyApproachObject() {
  // Logic for slow approach for RFID scanning
}

// Function to check for RFID tag
bool checkForTag() {
  // RFID tag detection logic
}

// Function to avoid obstacle and check distances to left and right
void avoidObstacle() {
  // Obstacle avoidance logic
}

// Function to reverse until a specified distance from an object
void reverseUntilDistance(int targetDistance) {
  // Logic for reversing until a certain distance is reached
}

// Motor control functions
void moveForward() {
  // Logic to move the robot forward
}

void moveBackward() {
  // Logic to move the robot backward
}

void turnLeft() {
  // Logic to turn the robot left
}

void turnRight() {
  // Logic to turn the robot right
}

void stopRobot() {
  // Logic to stop all motor activity
}

This code is designed to run on the Arduino UNO and controls the robot's movement based on sensor inputs. It includes functions for manual control via serial commands, autonomous navigation, RFID scanning, and motor control. The robot can navigate autonomously by following a line and avoiding obstacles, or it can be controlled manually through serial commands. The ESP32-CAM module can be used for additional functionalities such as video streaming or image capture.