Making Things Interactive

May 12, 2008

Filed under: Assignments,Cat Adams,Final Project — catadams @ 12:04 am

The automatic recycling machine is designed to bring a process that is currently only done on an industrial sale, that is, the sorting of recyclables to a smaller and more personal scale. I intend for this machine to be used primarily on college campuses and areas of high traffic. I hope for people to understand the importance of recycling by being more involved in the process.

Overall View of the Recycle-Tron

View of the interior wiring

Video of a glass bottle being recycled

Video of the Recycle-Tron getting angry at someone who doesn’t recycle

Code:

/*
—Automatic Recycling Sorter—
–Making Things Interactive Spring 08 Final Project–
—Cat Adams—
*/

//states
static int Idle = 0; //name for Idle state
static int Excited = 1; //name for Excited state
static int Angry = 2; //name for Angry state
static int BigReward = 3; //name for the post-recycling Big Reward state
static int SmallReward = 4; //name for the post-recycling Big Reward state

//regular ints
int redLED = 2; //red LED connected to digital pin 2
int blueLED = 3; //blue LED connected to digital pin 3
int greenLED = 4; //green LED connected to digital pin 4
int siren = 7; //buzzer connected to digital pin 7
int pir = 8; //pir sensor connected to digital pin 8
int currentState = Idle; //sets the beginning state to Idle
int numberCycle = 0; //sets the number of items recycled to zero

//recycling ints
int servoM = 10; //Metal sorting Servo
int Mangle; //angle at which to turn servoM, set later
int servoG = 9; //Glass-Plastic sorting servo
int Gangle; //angle at which to turn servoG, set later
int switchMetal = 12; //Metal sensing wires
int switchGlass = 11; //Glass-Plastic sorting swtich analog pin 1
int bottlesense = 13; //button switch sensing presence of a bottle
int GAngle2 = 45; //angle for servo to sort out glass (from plastic)
int PAngle = 90; //angle for servo to sort out plastic
int GAngle = 90; //angle to sort glass/plastic from metal
int MAngle = 45; //angle to sort metal
int pulseWidth; //servo variable

//program for moving the metal servo
void metalPulse(int servoM, int Mangle){
pulseWidth = (Mangle * 11) + 500;
digitalWrite(servoM, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoM, LOW);
delay(20);
}

//program for moving the glass/plastic servo
void glassPulse(int servoG, int Gangle){
pulseWidth = (Gangle * 11) + 500;
digitalWrite(servoG, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoG, LOW);
delay(20);
}

//program for pulsing just one LED at a time
void PulseOne (int pin) {
for (int i=0; i<=255; i++) { analogWrite(pin, i); delay(2); } for (int i=255; i>=0; i–) {
analogWrite(pin, i);
delay(1);
}
}

void setup(){
pinMode(switchMetal, INPUT);
pinMode(servoM, OUTPUT);
pinMode(servoG, OUTPUT);
pinMode(switchGlass, INPUT);
pinMode(siren, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(pir, INPUT);
pinMode(bottlesense, INPUT);
Serial.begin(9600);
}

void loop(){

//Idle State: all LED’s off, print “Idle” on computer screen
if (currentState == Idle) {
Serial.println(“Idle”);
//turn all the LEDs off (in case a later state does not turn an led off)
digitalWrite(blueLED, LOW);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);

delay(2000);

if (digitalRead(pir) == LOW){ //if the pir sensor is tripped, a person is near and the machine goes into Excited mode
currentState = Excited;
}
else{ //if no one is around, do nothing
currentState = Idle;
}
}
//Excited State: pulse all three LED’s, print “Excited”
if (currentState == Excited){
Serial.println(“Excited”);
delay(2000);
digitalWrite(blueLED, HIGH);
digitalWrite(greenLED, HIGH);
delay(1000);
digitalWrite(blueLED, LOW);
digitalWrite(greenLED, LOW);
delay(1000);
digitalWrite(blueLED, HIGH);
digitalWrite(greenLED, HIGH);
delay(1000);
digitalWrite(blueLED, LOW);
digitalWrite(greenLED, LOW);
delay(2000);

if (digitalRead(bottlesense) == HIGH){ //if the bottle-sensing button is pressed, the bottle is either glass or plastic
Serial.println(“glass1”);
for (Mangle=20; Mangle<=105; Mangle++){ metalPulse(servoM, Mangle); } delay (1000); if (digitalRead(switchGlass) == HIGH){ //if the glass/plastic sorting button is pressed, the servo tilts and places the bottle in the glass bin Serial.println("glass2"); for (Gangle=50; Gangle<=95; Gangle++){ glassPulse(servoG, Gangle); } delay (1000); numberCycle++; //add one to the current numberCycle count if (numberCycle <=5) { //if the new numberCycle count is less than 6, go to Small Reward state currentState = SmallReward; } else{ //if the numberCycle count exceeds 5, go to the Big Reward state currentState = BigReward; } } else{ //if the glass/plastic sorting button is NOT pressed, the servo tilts and places the bottle in the plastic bin plastic(); numberCycle++; if (numberCycle <=5) { currentState = SmallReward; } else{ currentState = BigReward; } } } else{ //if the bottle sensing button is NOT pressed if (digitalRead(switchMetal) == HIGH){ //but if the switchMetal circuit is connected, there is a metal can metal(); numberCycle++; if (numberCycle<=5){ currentState = SmallReward; } else{ currentState = BigReward; } } else{ //if neither the button sensing switch or the switchMetal circuit is connected, then currentState = Angry; //the person is not recycling, so the machine becomes angry } } } //Angry State: pulse red LED and print "Angry!!" if (currentState == Angry){ Serial.println("Angry!!"); delay(2000); digitalWrite(siren, HIGH); PulseOne(redLED); digitalWrite(siren, LOW); PulseOne(redLED); digitalWrite(siren, HIGH); PulseOne(redLED); digitalWrite(siren, LOW); delay(2000); if (digitalRead(bottlesense) == HIGH){ //the person has a second chance to recycle... see above for comments Serial.println("glass1"); for (Mangle=20; Mangle<=105; Mangle++){ metalPulse(servoM, Mangle); } delay (1000); if (digitalRead(switchGlass) == HIGH){ Serial.println("glass2"); for (Gangle=50; Gangle<=95; Gangle++){ glassPulse(servoG, Gangle); } delay (1000); numberCycle++; if (numberCycle <=5) { currentState = SmallReward; } else{ currentState = BigReward; } } else{ plastic(); numberCycle++; if (numberCycle <=5) { currentState = SmallReward; } else{ currentState = BigReward; } } } else{ if (digitalRead(switchMetal) == HIGH){ metal(); numberCycle++; if (numberCycle<=5){ currentState = SmallReward; } else{ currentState = BigReward; } } else{ currentState = Idle; } } } //Small Reward: print "Small Reward" and pulse the blue LED then the green LED if (currentState == SmallReward){ Serial.println("Small Reward"); PulseOne(blueLED); PulseOne(greenLED); PulseOne(blueLED); PulseOne(greenLED); currentState = Idle; } //Big Reward: print "Big Reward" and pulse the blue then green then red LED if (currentState == BigReward){ Serial.println("Big Reward"); PulseOne(blueLED); PulseOne(greenLED); PulseOne(redLED); PulseOne(blueLED); PulseOne(greenLED); PulseOne(redLED); currentState = Idle; } } [/sourcecode]

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: