Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled Autonomous Robot with 3-Axis Robotic Arm and Obstacle Avoidance

Image of Arduino-Controlled Autonomous Robot with 3-Axis Robotic Arm and Obstacle Avoidance

Circuit Documentation

Summary

This circuit is designed to control an autonomous robot equipped with a 3-axis robotic arm. The robot is capable of detecting and picking up objects using a capacitive proximity sensor and avoiding obstacles with an ultrasonic sensor. The movement of the robot is facilitated by DC motors, which are driven by an L298N motor driver module. The robotic arm's motion is controlled by four servo motors responsible for base rotation, shoulder movement, elbow extension, and gripper operation. The entire system is managed by an Arduino UNO microcontroller, which processes sensor inputs and controls the actuators accordingly.

Component List

  • Arduino UNO: A microcontroller board based on the ATmega328P, featuring digital and analog I/O pins.
  • Servo Motors: Actuators that can rotate to a specified position, used for precise control of the robotic arm's movements.
  • LJC18A3-B-Z/BY Capacitive Proximity Sensor: A sensor used to detect the presence of nearby objects without physical contact.
  • DC Motors: Electric motors that convert electrical energy into mechanical rotation, used for robot locomotion.
  • 4 x AAA Battery Mount: A battery holder for four AAA batteries, providing power to the circuit.
  • 3xAA Battery: A battery pack providing power to the circuit.
  • HC-SR04 Ultrasonic Sensor: A sensor that measures distance by emitting ultrasonic waves and timing their return after bouncing off objects.
  • L298N DC Motor Driver: A module that allows for control of high-current DC motors using digital signals from the microcontroller.

Wiring Details

Arduino UNO

  • 5V: Powers the servo motors and the HC-SR04 ultrasonic sensor.
  • GND: Common ground for servo motors, capacitive proximity sensor, and HC-SR04 ultrasonic sensor.
  • A0, A1: Connected to the L298N motor driver's IN3 and IN4 for motor control.
  • D12: Connected to the L298N motor driver's ENB for enabling motor B.
  • D11: Connected to the L298N motor driver's ENA for enabling motor A.
  • D10: Connected to the HC-SR04 ultrasonic sensor's ECHO pin.
  • D9: Connected to the HC-SR04 ultrasonic sensor's TRIG pin.
  • D8, D7, D6, D5: Connected to the servo motors' pulse pins for control signals.
  • D4, D3: Connected to the L298N motor driver's IN2 and IN1 for motor control.
  • D2: Connected to the capacitive proximity sensor's VI (BRN) pin.

Servo Motors

  • vcc: Powered by the Arduino's 5V pin.
  • gnd: Connected to the Arduino's GND pin.
  • pulse: Receives control signals from the Arduino's digital pins (D8, D7, D6, D5).

LJC18A3-B-Z/BY Capacitive Proximity Sensor

  • SIG (BLK): Connected to the 4 x AAA Battery Mount's "+" pin.
  • VI (BRN): Connected to the Arduino's D2 pin.
  • VO (BLU): Connected to the 4 x AAA Battery Mount's "-" pin.

DC Motors

  • pin 1 and pin 2: Connected to the L298N motor driver's OUT1, OUT2, OUT3, and OUT4 for motor control.

4 x AAA Battery Mount

  • "+": Powers the capacitive proximity sensor.
  • "-": Common ground for the capacitive proximity sensor.

HC-SR04 Ultrasonic Sensor

  • VCC: Powered by the Arduino's 5V pin.
  • TRIG: Sends ultrasonic pulses, connected to the Arduino's D9 pin.
  • ECHO: Receives the reflected ultrasonic pulses, connected to the Arduino's D10 pin.
  • GND: Connected to the Arduino's GND pin.

L298N DC Motor Driver

  • OUT1, OUT2, OUT3, OUT4: Connected to the DC motors for controlling their rotation.
  • 12V, GND: Power input for the motor driver (not detailed in the net list, assumed to be connected to a power source).
  • 5V, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2: Not detailed in the net list, assumed to be jumper settings or internal connections.
  • ENA, ENB: Enable pins for the motors, connected to the Arduino's D11 and D12 pins.
  • IN1, IN2, IN3, IN4: Control pins for the direction of the motors, connected to the Arduino's D3, D4, A0, and A1 pins.

Documented Code

#include <Servo.h>

// Pin Assignments
const int proximitySensorPin = 2;
const int trigPin = 9;
const int echoPin = 10;
const int motorPin1 = 3;
const int motorPin2 = 4;
const int motorPin3 = A0;
const int motorPin4 = A1;
const int enableA = 11;
const int enableB = 12;

// Servos for 3-Axis Arm
Servo baseServo;
Servo shoulderServo;
Servo elbowServo;
Servo gripperServo;

void setup() {
  // Setup motor control pins
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(enableA, OUTPUT);
  pinMode(enableB, OUTPUT);

  // Setup sensor pins
  pinMode(proximitySensorPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // Initialize servos
  baseServo.attach(5);    // Base rotation
  shoulderServo.attach(6); // Shoulder movement
  elbowServo.attach(7);    // Elbow movement
  gripperServo.attach(8);  // Gripper

  // Set motor speed
  analogWrite(enableA, 255);  // Max speed for motor 1
  analogWrite(enableB, 255);  // Max speed for motor 2

  // Set initial positions for robotic arm
  baseServo.write(90);    // Neutral position
  shoulderServo.write(90);
  elbowServo.write(90);
  gripperServo.write(90);
}

void loop() {
  // Obstacle detection using ultrasonic sensor
  long duration, distance;
  
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;

  if (distance < 20) {  // If obstacle detected within 20cm
    stopMotors();
    delay(500);
    // Navigate backward and turn to avoid obstacle
    moveBackward();
    delay(1000);
    turnRight();
    delay(500);
  } else {
    moveForward();
  }

  // Check if plastic object is detected by proximity sensor
  int proximityState = digitalRead(proximitySensorPin);
  
  if (proximityState == HIGH) {
    // Stop motors and start the pick-up process
    stopMotors();
    pickUpObject();
    // After picking up the object, move the robot to another location
    moveForward();
    delay(2000); // Move to drop-off location
    dropObject();
  }
}

// Function to stop all motors
void stopMotors() {
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
}

// Function to move the robot forward
void moveForward() {
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
}

// Function to move the robot backward
void moveBackward() {
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
}

// Function to turn the robot right
void turnRight() {
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
}

// Function to pick up the object using the robotic arm
void pickUpObject() {
  baseServo.write(0);      // Rotate base to align with object
  delay(1000);
  shoulderServo.write(45); // Lower shoulder
  delay(1000);
  elbowServo.write(135);   // Extend elbow
  delay(1000);
  gripperServo.write(0);   // Close gripper to grab object
  delay(1000);

  // Lift object
  elbowServo.write(90);
  delay(1000);
  shoulderServo.write(90);
  delay(1000);
  baseServo.write(90);     // Return base to neutral
  delay(1000);
}

// Function to drop the object using the robotic arm
void dropObject() {
  baseServ