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

Arduino-Based Robotic Arm with RGB Color Detection and Servo Control

View and Edit Project In Cirkit DesignerImage of Arduino-Based Robotic Arm with RGB Color Detection and Servo Control

Circuit Documentation

Summary

This circuit is designed to control a robotic arm using an Arduino UNO microcontroller. The arm's movements are determined by the color detected by an Adafruit TCS34725 RGB Color Sensor. The circuit includes multiple servos to control different parts of the arm, a pushbutton for user input, and a power supply to provide the necessary voltage and current.

Component List

Adafruit TCS34725 RGB Color Sensor

Servo (4 units)

Arduino UNO

POWER SUPPLY 5V 5AMP

Pushbutton

Resistor

Wiring Details

Adafruit TCS34725 RGB Color Sensor

Servo 1

Servo 2

Servo 3

Servo 4

Arduino UNO

POWER SUPPLY 5V 5AMP

Pushbutton

Resistor

Documented Code

#include <Servo.h>
#include <Adafruit_TCS34725.h>
#include <Servo.h>
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

int tiempo1 = 30;
int tiempo2 = 1000;

Servo Cintura;  // Declaramos variable para contolar Servo Cintura
Servo Hombro;   // Declaramos variable para contolar Servo Hombro
Servo Codo;     // Declaramos variable para contolar Servo Codo
Servo Pinzas;   // Declaramos variable para contolar Servo Pinzas

int ang;

void setup() {

  Serial.begin(9600);
  tcs.begin();  // inicializamos el sensor

  Cintura.attach(6);  // Para control servo Cintura asignamos el pin digital 6
  Hombro.attach(9);   // Para control servo Hombro asignamos el pin digital 9
  Codo.attach(10);    // Para control servo Codo asignamos el pin digital 10
  Pinzas.attach(11);  // Para control servo Pinzas asignamos el pin digital 11

  Cintura.write(90);  //  Posición inicial servo cintura  = 90 Grados
  Hombro.write(20);   //  Posición inicial servo hombro = 20 Grados
  Codo.write(50);     //  Posición inicial servo codo = 50 Grados
  Pinzas.write(0);    //  Posición inicial servo pinzas = 0 Grados
}

void loop() {

  float red, green, blue;           // variables para colores R,g,b
  tcs.getRGB(&red, &green, &blue);  // lectura de colores con el sensor
  int R = int(red);
  int G = int(green);
  int B = int(blue);
  String color = "";
  
  if ((R - B > 10) & (G - B > 25)) {
    color = "BLANCO";
    // ---------------------------------------------------SECUENCIA 1 (COLOR BLANCO) -------------------------------------------------------------------------------

    for (ang = 20; ang < 90; ang++)  //Hombro gira al frente hasta 90 grados
    {
      Hombro.write(ang);
      delay(tiempo1);
    }
    delay(tiempo2);

    Pinzas.write(22);  // Pinzas se cierran hasta 22 grados
    delay(tiempo2);

    for (ang = 90; ang > 20; ang--)  //hombro regresa hasta 30 grados
    {
      Hombro.write(ang);
      delay(tiempo1);
    }
    delay(tiempo2);
    for (ang = 90; ang > 40; ang--)  // Cintura gira a la derecha hasta 40 grados
    {
      Cintura.write(ang);
      delay(tiempo1);
    }
    delay(tiempo2);

    for (ang = 50; ang > 35; ang--)  //codo gira de 50 a 35 grados
    {
      Codo.write(ang);
      delay(tiempo1);
    }

    for (ang = 20; ang < 91; ang++)  //Hombro gira al frente de 20 a 90 grados
    {
      Hombro.write(ang);
      delay(tiempo1);
    }
    delay(500);
    Pinzas.write(0);  // Pinzas se abren hasta la posición de 0 grados

    delay(tiempo2);

    for (ang = 90; ang > 20; ang--)  //hombro regresa de 90 a 20 grados
    {
      Hombro.write(ang);
      delay(tiempo1);
    }
    delay(tiempo2);

    for (ang = 35; ang < 50; ang++)  //Codo regresa  a la posición de  50 grados
    {
      Codo.write(ang);
      delay(tiempo1);
    }

    for (ang = 40; ang < 90; ang++)  // Cintura gira