Here I build a small application which detects and separate out black and white objects
This project is very useful in many industry for sorting out black and white objects separately. In this project I used Arduino, Servo motor, and IR Sensor.
Project Mechanism
Here I used IR sensor to detect color of object whether it is black or white. If object is white then reflects the IR rays and detect object is white and when object is black then there is no any reflection because black color not reflect any light rays.
It gives digital one or zero form of output to the Arduino board and from that rotate the servo motor left or right.
If object is black then rotate servo motor to right side 90 degree and object is white then rotate servo motor to the left side 90 degree.
Now connect Servo motor and IR Module to the Arduino board as shown in connection diagram.
Connection Diagram
.png)
Y-shaped Arm
Here I used foam material to build Y-shaped arm, you can use other type material also.
Now cut foam sheet as your object specification’s need and connect them as shown in figure below.

Now, connect this Y-shaped arm to the top of Servo motor, for connection I used double sided tape.

Next, connect the IR module to the body of Servo Motor sh shown in figure below.


The complete connection is shown like this,

Code
#include <Servo.h>
Servo myservo;
#define sensor 7
int sensorstate;
void setup() {
pinMode(sensor, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
myservo.attach(9);
myservo.write(90);
delay(1000);
}
void loop() {
myservo.write(90);
if(digitalRead(sensor) == HIGH){
myservo.write(0);
delay(500);
myservo.write(90);
delay(500);
Serial.println("WHITE");
}
else if(digitalRead(sensor) == LOW){
digitalWrite(13, HIGH);
myservo.write(180);
delay(500);
myservo.write(90);
delay(500);
Serial.println("BLACK");
digitalWrite(13, LOW);
}
delay(5000);
}