Skip to content

Final Project

Recycling Bin

At first I was working on printing some things using a 3D printer and then I noticed something which is that the printer wastes a lot of plastic and this depends on the thing that it prints. So I decided to make something that would make it easier for me to sort the plastic.

Tools

1. Microcontroller

2. Jumber Wire

3. DC Motor

4. Motor Driver

5. Power Source

6. 3D Design

7. Servo Motor

8. TCS34725 Color Sensor

9. Hole effec sensor

10. 3mm MDF Wood

2D and 3D Modeling

First I drew a circle and hollowed it out using the extrude tool.

Then I downloaded the ROTATING DISK from thingiverse. And I make two hole in the bin one for gear and another for sorting.

I made a soap-like piece to isolate the pieces.

Then I designed a piece to separate the pieces to mount them on the servo motor using several tools including sweep, offcetfaces, extrude and shell.

I made bases to hold the parts and put the motor in them.

After that I made the gears and I make sure it is good to used.

I made a base so I can hold the basket and other parts on it.

I made some holes in the basket so I could put magnets.

I made a holes for scrwo and also I made cups and I put them on the base. This is the final resulet.

3D Print

I start printing using PLA type of filament.

Some important pieces

Laser cutter

I cut the base by use 3mm MDF wood with CO2 laser machine.

Final Result:

Circuit Diagram

In developing my circuit diagram, I leveraged a variety of tools to ensure optimal functionality and performance. At the core of the system, I utilized an Arduino UNO as the primary microcontroller, chosen for its versatility and ease of programming. To control the DC motor effectively, I integrated an L298N motor driver, which provides the necessary current and direction control, enabling precise motor operation.

In addition to the Arduino UNO, I incorporated a XIAO ESP32 microcontroller, known for its compact size and robust capabilities, to manage a servo motor and a TCS34725 RGB color sensor. The ESP32’s advanced features allow for seamless communication and control over the servo’s position, while the color sensor enables accurate detection and processing of RGB values.

Full Circuit Diagram

This image represents the electrical circuit I used in the project:

This picture also shows the locations of the wires and how to connect them:

The entire setup was programmed using the Arduino IDE, which facilitated the development and uploading of code, allowing for real-time adjustments and debugging. This comprehensive approach not only enhanced the project’s functionality but also ensured a smooth integration of all components, resulting in a cohesive and efficient system.

Programing

The following code was implemented on the XIAO ESP32 to facilitate the operation of both the servo motor and the TCS34725 RGB color sensor. This code enables precise control of the servo motor’s position while simultaneously allowing the color sensor to accurately detect and process RGB values. By integrating these functionalities, the program ensures efficient communication between the components, resulting in a cohesive and responsive system.

#include <Wire.h>
#include <Adafruit_TCS34725.h>
#include <ESP32Servo.h>
// Create an instance of the TCS34725 class
#define SERVO1_PIN D0  // Pin for Servo 1
#define SERVO_PIN D1  // Pin for the servo 2


Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

Servo myServo;
Servo myServo1;

void setup() {
  Serial.begin(9600);
  Serial.println("TCS34725 Color Sensor Test");
    // Attach the servo objects to the respective pins
  myServo.attach(SERVO1_PIN);
  myServo1.attach(SERVO_PIN);

  // Initialize servos to a starting position
  myServo1.write(0);  // Start at 0 degrees



  if (!tcs.begin()) {
    Serial.println("No TCS34725 found ... check your connections");
    while (1);
  }
}

void loop() {

  uint16_t r, g, b, c;
  tcs.getRawData(&r, &g, &b, &c);

  Serial.print("R: "); Serial.print(r);
  Serial.print(" G: "); Serial.print(g);
  Serial.print(" B: "); Serial.print(b);
  Serial.print(" C: "); Serial.print(c);

  // Determine the color name based on RGB values
  String colorName = getColorName(r, g, b, c);
  Serial.print("Detected Color: "); Serial.println(colorName);
  if (colorName == "Blue"){

   // Red color detected
   myServo.write(45);  // Move slide to red container
   Serial.println("Blue color detected");

  } 
  else if (colorName == "Green"){
     myServo.write(135);  // Move slide to red container
     Serial.println("Green color detected");
  }
   // Move to 180 degrees
  myServo1.write(180);
  delay(6500);  // Wait for 10 seconds

  // Move back to 0 degrees
  myServo1.write(0);
  delay(6500);  // Wait for 10 seconds

}

String getColorName(uint16_t r, uint16_t g, uint16_t b, uint16_t c) {
  if (r > g && r > b) {
    return "Red";
  } else if (g > r && g > b) {
    return "Green";
  } else if (b > r && b > g) {
    return "Blue";
  } else {
    return "Unknown";
  }
}

The following code was developed for the Arduino UNO to control the DC motor connected to the L298N motor driver. This code facilitates precise operation of the motor, allowing for both directional control and speed regulation. By leveraging the capabilities of the L298N motor driver, the program ensures efficient power management and smooth execution of motor commands, thus optimizing the overall performance of the system.

// Define motor control pins
const int motorPinD1 = D9;   // IN1 on L298N
const int motorPinD2 = D10;  // IN2 on L298N

// Define timing
const int runTime = 5000;    // Motor running time in milliseconds
const int pauseTime = 2000;  // Pause time before reversing

void setup() {
  // Start serial communication for debugging
  Serial.begin(115200);

  // Set motor control pins as output
  pinMode(motorPinD1, OUTPUT);
  pinMode(motorPinD2, OUTPUT);

  // Start with the motor off
  digitalWrite(motorPinD1, LOW);
  digitalWrite(motorPinD2, LOW);

  Serial.println("Setup complete. Starting motor test.");
}

void loop() {
  // Spin motor in one direction
  Serial.println("Motor spinning forward.");
  digitalWrite(motorPinD1, HIGH);
  digitalWrite(motorPinD2, LOW);
  delay(runTime);  // Run for defined time

  // Stop the motor
  Serial.println("Motor stopping.");
  digitalWrite(motorPinD1, LOW);
  digitalWrite(motorPinD2, LOW);
  delay(pauseTime);  // Pause before reversing

  // Spin motor in the opposite direction
  Serial.println("Motor spinning backward.");
  digitalWrite(motorPinD1, LOW);
  digitalWrite(motorPinD2, HIGH);
  delay(runTime);  // Run for defined time

  // Stop the motor
  Serial.println("Motor stopping.");
  digitalWrite(motorPinD1, LOW);
  digitalWrite(motorPinD2, LOW);
  delay(pauseTime);  // Pause before restarting the loop
}

Video

From Vimeo

Sound Waves from George Gally (Radarboy) on Vimeo.

From Youtube

3D Models


Last update: September 15, 2025