FINAL TEST - THE CONVEYOR: Documentation
In this documentation:
- 1. General Context
- 2. Description of components
- 3. Computer-Aided Design
- 4. Conveyor System Logic
- 5. The Arduino Code
- 6. Assembly of components
- 7. Testing the project
- 8. Helpful Ressources
1. General Context
This project involves designing and building a smart conveyor system for a waste recycling company planning to set up operations in the TEKBOT CITY industrial zone. The goal is to develop a creative and efficient automated conveyor that sorts four types of waste, represented by colored objects (green, yellow, red, and blue cubes).
Technical Description
The conveyor system will combine mechanical and intelligent components to automate waste sorting. The conveyor belt remains stationary until waste is detected, at which point it activates and moves the detected items through a sensor zone. After detection, the waste travels to the end of the conveyor, where it is manually collected and placed in the bin indicated by the sorting system.
Real-Time Web Interface
To enable real-time monitoring, an intuitive web interface will be implemented. This interface will display the quantity of sorted waste by type (green, yellow, red, blue), providing administrators with up-to-date information about the sorting process. The interface will be user-friendly and accessible, ensuring that administrators can easily track the system’s performance at any time.
2. Description of components
a. Arduino Nano
The Arduino Nano is a compact microcontroller board based on the ATmega328P, suitable for embedded applications and easy prototyping. It features 14 digital input/output pins (of which 6 can be used as PWM outputs), 8 analog inputs, a mini USB port for programming and power, and supports a voltage range of 7-12V input. Its small size (approximately 1.8 x 0.7 inches) and compatibility with the Arduino IDE make it ideal for DIY electronics, robotics, and IoT applications where space is limited and reliable performance is needed.
b. Stepper Motor Nema 17
The NEMA 17 stepper motor is a compact and commonly used motor in devices like 3D printers and CNC machines. It has a standard size, delivers precise movement, and is reliable for projects that need controlled motion. Its popularity comes from its balance of size, power, and ease of integration with various electronics.
c. Pololu A4988 Stepper Motor Driver
The Pololu A4988 is a microstepping driver for controlling bipolar stepper motors. It enables the Arduino to send signals for step and direction, translating them into precise motor motion. It features adjustable current control, over-temperature and over-current protection and also supports full, half, quarter, eighth, and sixteenth step modes.
d. KY-008 Laser Transmitter
The KY-008 is a small laser emitter module used for creating a focused light beam. It features a 650nm red laser diode that emits a focused beam, making it suitable for applications such as simple laser pointers, line detection, and light communication. Combined with a photoresistor, it can detect when an object passes through the beam (used as a tripwire sensor).
e. Photoresistor
A photoresistor, or Light Dependent Resistor (LDR), changes its resistance based on light intensity. It’s used for detecting the presence or absence of objects, or measuring ambient light. It is typically use to detect when an object interrupts a light beam.
f. TCS34725 Color Sensor
The TCS34725 is a digital color sensor that can detect RGB and clear light values. It’s used to identify the color of objects passing in front of it. It features onboard IR blocking filter, I2C interface and high sensitivity which enables for better precision.
g. Our custom power supply
To power up our setup, we should build a power supply that will provide safe and sufficient voltage to all the components. For that, we will use a pack of four 3.7V lithium batteries to supply a voltage of 14.8V.
3. Computer-Aided Design
We used the KiCad EDA (download here) to design the schematic as well as the PCB for this project. Find its official documentation here.
KiCad schematic diagram
4. Conveyor System Logic
Object Presence and Color Detection
- The KY-008 laser module emits a beam aimed at the photoresistor (LDR).
- When an object interrupts the beam, LDR detects a drop in light, signaling the Arduino that an object is present at the entry point.
- The Arduino reads color data from the TCS34725 color sensor to identify the color of the object.
- Through the serial monitor, the arduino sends a "GARBAGE COLOR" message to ROS to signal that an object is present and specify its color for tracking.
Positioning
- The Nema 17 stepper motor, controlled by the A4988 driver, moves the conveyor belt.
- The Arduino sends step and direction signals to the A4988 to rotate the motor and advance the belt.
Control Loop
- The Arduino receives input from the photoresistor (LDR) which helps to detect if an object is present/absent.
- When LDR detects an object, Arduino sends a signal to ROS specifying its color.
- ROS sends back a "MOTOR ON" message to Arduino, after which the conveyor advances the object to its end.
- ROS then sends a signal "MOTOR OFF" to signal that the conveyor should stop.
- Arduino receives this signal, the conveyor is stopped, and a "OK" confirmation message is sent back to ROS.
5. The Arduino Code
Setting up
Download the Arduino IDE using this link. It's a software that will allow you to run and upload your code to the MCUs. Once the installation is done, we can set up by installing the necessary libraries via the Library Manager in the Arduino IDE (make sure that you also install their dependencies when prompted to). We will need the following Arduino libraries:
/* ========= REQUIRED LIBRAIRIES ============== */
#include <Adafruit_TCS34725.h> // Library for our color sensor
#include <Wire.h>
Global variables and constants declarations
- Constants representing the A4988 driver pins:
// === A4988 driver pins ===
#define stepPin 3 // connected to Arduino D3
#define dirPin 4 // connected to Arduino D4
- Constants representing the Photoresistors and Laser pins:
// === Photoresistors and Laser pins ===
#define laserPin 5 // KY-008 laser emitter
#define photo1 A0 // First photoresistor
#define photo2 A1 // Second photoresistor
- Photoresistor's resistance value threshold to detect the presence of an object
// Threshold to detect if an object is blocking the beam
const int detectionThreshold = 500;
- Declaration of TCS34725 color sensor:
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
setup() function
void setup()
{
Serial.begin(115200); // start the serial monitor at 115200 bauds
// Configuration for stepper motor
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, HIGH);
// Configuration for Laser and photoresistors
pinMode(laserPin, OUTPUT);
digitalWrite(laserPin, HIGH); // Turn on laser
// Initialization of our color sensor
if (!tcs.begin()) // initialization failed
{
// print to the serial monitor for debugging
Serial.println("Color sensor setup failed !");
while (true); // Loop forever, don't proceed
}
if (!confirm_connect()) // ros and arduino connection failed
{
// print to the serial monitor for debugging
Serial.println("Connection failure !");
while (true); // Loop forever, don't proceed
}
}
Custom functions
Function to read from ROS using the serial monitor:
String read_from_ros()
{
if (Serial.available()) // check if data is available for reading
{
return Serial.readString(); // return data as string
}
return ""; // return an empty string if no data is available
}
Function to confirm Arduino-ROS connection:
bool confirm_connect()
{
String msg = read_from_ros(); // read from ros through serial
// if connection with ROS is successful, send confirmation message to ros
if (msg == "ROS CONNECTED\r\n")
{
// print to the serial monitor for arduino to ros communication
Serial.println("ARDUINO CONNECTED");
return true;
}
return false; // cannot confirm connection
}
Function to move the conveyor belt:
void startConveyor()
{
String msg = read_from_ros(); // read from ros through serial
int i = 0;
// if ROS hasn't signaled to start conveyor, don't proceed
if (msg != "MOTOR ON\r\n")
{
return;
}
while (i < 200) // Move 200 steps, partial rotation
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000); // control speed
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
i++;
}
// Let ROS know object reached end of conveyor belt
if (i == 200 - 1)
{
Serial.println("OK");
}
}
Function to stop the conveyor belt:
void stopConveyor()
{
// Just for logic
// Motor stops itself automatically when no longer receiving pulses
}
Function for detecting an object's color through the TCS34725 color sensor:
// === Color detection via TCS34725 ===
String detectColor()
{
// Read raw red, green, blue and clear values
uint16_t red, green, blue, neutral;
tcs.getRawData(&red, &green, &blue, &neutral);
// Normalize color values for fair comparison
float sum = red + green + blue;
float R = red / sum;
float G = green / sum;
float B = blue / sum;
// ======== Color dectection logic ========
if (R > 0.35 && G > 0.35 && B < 0.25)
return "YELLOW";
else 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"; // Color is not among the supported ones
}
loop() function
void loop()
{
// Read light levels from both photoresistors
int value1 = analogRead(photo1); // read from first photoresistor
int value2 = analogRead(photo2); // read from second photoresistor
// Check if laser beam is blocked (object detected)
if (value1 < detectionThreshold || value2 < detectionThreshold)
{
delay(800); // Time for object detection by color sensor
String objectColor = detectColor(); // detect the object's color
// print to the serial monitor for arduino to ros communication
Serial.print("GARBAGE"); Serial.println(objectColor);
startConveyor(); // move stepper motor
stopConveyor();
delay(1500); // 1.5 seconds pause before next detection
return;
}
Serial.println("NONE");
}
The full code is available to download here.
6. Assembly of components
This section outlines the assembly steps of all components for this project:
Integrating the power supply
- Connect the four 3.7V lithium batteries in series to form a 14.8V pack.
- Use a voltage regulator to step down the voltage for the Arduino Nano (recommended: 7-12V).
- Distribute power: connect the battery pack to the A4988 Vmot/GND for the motor, and to the Arduino and sensors.
- Double-check battery polarity and connections to prevent damage.
Wiring and soldering
- Plan the layout and cut wires to length needed for permanent installation.
- Solder the NEMA 17 stepper motor wires to the Pololu A4988 driver pins according to the datasheet.
- Connect the A4988 STEP and DIR pins to two digital pins on the Arduino Nano (in our case D3 and D4). Solder these connections directly.
- Wire the A4988 driver's logic power (VDD, GND) to the Arduino Nano's 5V and GND.
- Solder the KY-008 laser’s VCC and GND to the Arduino’s 5V and GND; if control is needed, connect its signal pin to a digital output.
- Mount and solder wires from the photoresistor to an analog input (in our case A0) and to GND and 5V as needed.
- Connect the TCS34725 color sensor’s SDA and SCL to the Arduino Nano’s I2C pins (A4, A5). Solder power and ground connections.
- Insulate all solder joints with heat-shrink tubing or electrical tape to prevent shorts.
Component Placement
- Fix the NEMA 17 stepper motor securely to drive the conveyor belt.
- Position the Arduino Nano, Pololu A4988 driver, and voltage regulator inside the housing, ensuring accessibility for programming and maintenance.
- Mount the KY-008 laser so its beam crosses the conveyor belt, aligned with the photoresistor opposite for object detection.
- Place the TCS34725 color sensor above the conveyor belt, oriented to scan passing items.
- Ensure all components are spaced to avoid interference and allow for cooling and wire routing.
Mounting everything in the housing
- Secure all components to the housing using screws, standoffs, adhesive pads, or custom mounts as needed.
- Route and fix wires neatly along the housing, using cable ties, clips, or hot glue to prevent movement and interference with moving parts.
- Confirm all modules are firmly fixed and wires are clear of the conveyor mechanism.
7. Testing and Validation
Before uploading the Arduino program, you need to do some final checks:
- Visually inspect and check all connections to prevent short circuits.
- Apply power gradually while monitoring the LEDs and voltage rails.
After performing these steps, upload The Arduino Code, and observe.