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