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.
5V
and GND
are connected to the power rails of the IR sensors and the HC-SR04 ultrasonic sensorD2
and D3
are connected to the output of the IR sensorsA0
and A1
are connected to the ECHO
and TRIG
pins of the HC-SR04 ultrasonic sensorD5
to D13
are connected to the control pins of the L298N motor driversVin
is connected to the power supply through a rocker switchGND
is connected to the negative terminal of the power supplyD0
and D1
are connected to the VOT
and VOR
pins of the ESP32-CAM for serial communicationvcc
pins are connected to the 5V
output of the Arduino UNOgnd
pins are connected to the GND
on the Arduino UNOout
pins are connected to digital pins D2
and D3
on the Arduino UNOOUT1
, OUT2
, OUT3
, and OUT4
pins of the L298N motor driversVCC
is connected to 5V
on the Arduino UNOGND
is connected to GND
on the Arduino UNOECHO
is connected to analog pin A0
on the Arduino UNOTRIG
is connected to analog pin A1
on the Arduino UNO12V
is connected to the power supply through a rocker switchGND
is connected to the negative terminal of the power supply5V
is connected to the 5V
pin of the ESP32-CAMENA
, ENB
, IN1
, IN2
, IN3
, and IN4
are connected to various digital pins on the Arduino UNOOUT1
, OUT2
, OUT3
, and OUT4
are connected to the DC motorsGND
of the circuit5V
is connected to the 5V
output of the L298N motor driverGND
is connected to the negative terminal of the power supplyVOT
and VOR
are connected to digital pins D0
and D1
on the Arduino UNO for serial communication#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.