The article titled “Smart Conveyor System with Automatic Object Sorting using Favoriot IoT Platform” provides a step-by-step guide to building a smart conveyor system integrated with the Favoriot IoT Platform for remote monitoring.
Step 1: Hardware Preparation
Main Components
- Microcontroller: ESP32 or ESP8266
- Sensors for Object Detection:
- IR Sensor: Detects the presence of objects
- Color Sensor TCS3200/TCS230: Detects the color of objects
- Ultrasonic Sensor HC-SR04: Measures the size of objects
- Servo Motor: Used to push objects into their respective categories
- DC Motor with L298N Driver: Drives the conveyor belt
- Power Supply: 5V or 12V, depending on component requirements
Step 2: Hardware Connections
- DC Motor: Connect to the L298N Driver to control conveyor movement.
- IR Sensor: Install at the end of the conveyor to detect the presence of objects.
- Color Sensor TCS3200: Connect to the microcontroller to read object colors.
- Servo Motor: Connect to the microcontroller to push objects into designated categories.
Step 3: Code for Color Detection & Sorting
The code utilizes the TCS3200 color sensor to read object colors, operates the servo motor to sort objects based on color, and sends data to the Favoriot IoT Platform via Wi-Fi.
#include <WiFi.h>
#include <HTTPClient.h>
#include <Servo.h>
// Wi-Fi Information
const char* ssid = "Your_WiFi_SSID";
const char* password = "Your_WiFi_Password";
// Favoriot Information
const char* favoriot_host = "https://apiv2.favoriot.com/v2/streams";
const char* apiKey = "Your_API_Key";
const char* device_developer_id = "Your_Device_Developer_ID";
// TCS3200 Color Sensor Pins
const int s2 = 4;
const int s3 = 5;
const int sensorOut = 6;
// Servo Motor Pin
const int servoPin = 9;
Servo sorterServo;
// Color Variables
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
void setup() {
Serial.begin(115200);
// Wi-Fi Connection
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to Wi-Fi");
// Pin Configuration
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(sensorOut, INPUT);
// Initialize Servo
sorterServo.attach(servoPin);
sorterServo.write(0); // Initial position
}
void loop() {
// Read Color
redFrequency = getColorFrequency(LOW, LOW);
greenFrequency = getColorFrequency(HIGH, HIGH);
blueFrequency = getColorFrequency(LOW, HIGH);
// Determine Color
String color = detectColor(redFrequency, greenFrequency, blueFrequency);
Serial.println("Detected Color: " + color);
// Move Servo Based on Color
moveServo(color);
// Send Data to Favoriot
sendDataToFavoriot(color);
delay(5000); // Wait before reading the next object
}
int getColorFrequency(int s2State, int s3State) {
digitalWrite(s2, s2State);
digitalWrite(s3, s3State);
return pulseIn(sensorOut, LOW);
}
String detectColor(int red, int green, int blue) {
if (red < blue && red < green) {
return "Red";
} else if (blue < red && blue < green) {
return "Blue";
} else if (green < red && green < blue) {
return "Green";
} else {
return "Unknown";
}
}
void moveServo(String color) {
if (color == "Red") {
sorterServo.write(30); // Position for red objects
} else if (color == "Blue") {
sorterServo.write(90); // Position for blue objects
} else if (color == "Green") {
sorterServo.write(150); // Position for green objects
} else {
sorterServo.write(0); // Default position
}
delay(1000); // Wait for servo to move
sorterServo.write(0); // Return to initial position
}
void sendDataToFavoriot(String color) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(favoriot_host);
http.addHeader("Content-Type", "application/json");
http.addHeader("apikey", apiKey);
String jsonData = "{\"device_developer_id\":\"" + String(device_developer_id) + "\",\"data\":{\"color\":\"" + color + "\"}}";
int httpResponseCode = http.POST(jsonData);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("Data sent: " + response);
} else {
Serial.println("Failed to send data");
}
http.end();
} else {
Serial.println("Wi-Fi not connected");
}
}
Note:
- Replace
Your_WiFi_SSID,Your_WiFi_Password,Your_API_Key, andYour_Device_Developer_IDwith your actual information. - Ensure you have included the necessary libraries such as
WiFi.h,HTTPClient.h, andServo.hin your Arduino IDE environment.
Reference
Disclaimer
This article provides a step-by-step guide. The source code may need adjustments to fit the final project design.
![[Tutorial] : Smart Conveyor System with Automatic Object Sorting using Favoriot IoT Platform](https://iotworld.co/wp-content/uploads/2025/03/DALL·E-2025-03-19-15.17.52-A-futuristic-smart-conveyor-system-with-automated-object-sorting-featuring-a-magenta-aesthetic.-The-conveyor-is-equipped-with-infrared-sensors-color.webp)





Leave a Reply