This device independently separates four different spheres (ping pong balls of two different colors, golf balls and a unspecified type of ball that has a 50% smaller diameter than a golf ball) by type and color in a timed fashion; to place each type of sphere in four different buckets once the artifact has separated them (this requirement must be met in a maximum of 30 seconds, and all spheres of each type must be in their bucket before another bucket starts being filled); to at least use eight spheres (two of each type). The artifact design described in the following documentation meets all parameters described above. In addition, the number of spheres used in the following artifact is twelve, and the time-period for the entire process to finish is twenty-four seconds (using two seconds per sphere).
ARDUINO CODE:
#include <Servo.h>
#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6
Servo bottomServo;
int frequency = 0;
int color=0;
void setup() {
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
// Setting frequency-scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
bottomServo.attach(12);
Serial.begin(9600);
}
// Custom Function - readColor()
int readColor() {
// Setting red filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int R = frequency;
// Printing the value on the serial monitor
Serial.print("R= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(50);
// Setting Green filtered photodiodes to be read
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int G = frequency;
// Printing the value on the serial monitor
Serial.print("G= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(50);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int B = frequency;
// Printing the value on the serial monitor
Serial.print("B= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.println(" ");
delay(50);
if(R<64 & R>58 & G<64 & G>59){
color = 1; // White PingPong Ball
}
if(R<48 & R>36 & G<104 & G>97){
color = 2; // Orange PingPong Ball
}
return color;
}
void loop() {
color = readColor();
delay(10);
switch (color) {
bottomServo.write(180); //Standard servos work by commanding
a degree between 0 and 180
delay(500);// insert a delay here in order to give your servo time to
move.
break;
case 2:
bottomServo.write(0);
delay(500);//Another delay here (500 being safe in the beginning)
break;
case 0:
break;
delay(300);
}
}