Making Things Interactive

March 6, 2008

Mid-Term Project (Due March 6,2008)

Filed under: 7: Mid-Term Project,Cat Adams — catadams @ 1:44 am

Images/video pending, here is the schematic and code for my midterm project:

Most of the notes for the project can be found in the code itself. The glass/plastic servo works perfectly, but the metal servo keeps jerking between the two values I set for it, probably because the arduino keeps reading the hall sensor
ver and over. I need to write a code for the arduino to read the sensor only once as soon as a bottle is deposited.

midterm-schem.pdfmidterm-schem.pdf


/*

Midterm Project
Automatic Recycler
Cat Adams

NOTES:
--need to tell servos to stay at 0 degrees until a bottle is dropped
--need another sensor to tell if a bottle has been dropped (photosensor/switch/rangefinder)
--need to tell the arduino to read the hall sensor only once (or once a bottle has been dropped)
--when sorting glass/plastic, need to determine a delay time for the switch (after a certain time after glass/plastic has beens sorted from metal, if the button has not been pressed, the bottle is plastic
*/

int HallPin = 12;        //Hall Sensor
int servoMetal = 6;      //Metal sorting Servo PWM pin 6
int servoGlass = 10;     //Glass-Plastic sorting servo PWM pin 10
int switchGlass = 2;     //Glass-Plastic sorting switch pin 2
int statusPin = 13;
int switchVal;           //variable to store switch value (high or low)
int HallVal;             //variable to store Hall Sensor reading (1 or 0)
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

void metal(){                            //function for servoMetal to sort metal from glass/plastic
pulseWidth = (MAngle * 11) + 500;
digitalWrite(servoMetal, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoMetal, LOW);
delay(20 - (pulseWidth/1000));
}

void glass1(){                          //function for servoMetal to sort glass/plastic from metal
pulseWidth = (GAngle * 11) + 500;
digitalWrite(servoMetal, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoMetal, LOW);
delay(20 - (pulseWidth/1000));
}

void glass2(){                         //function for servoGlass to sort glass from plastic

pulseWidth = (GAngle2 * 11) + 500;
digitalWrite(servoGlass, HIGH);
digitalWrite(statusPin, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoGlass, LOW);
digitalWrite(statusPin, LOW);
delay (20 - (pulseWidth/1000));
}

void plastic(){                         //function for servoGlass to sort plastic from glass

pulseWidth = (PAngle * 11) + 500;
digitalWrite(servoGlass, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoGlass, LOW);
delay (20 - (pulseWidth/1000));
}

void setup()                      //sets all the modes
{

pinMode(HallPin, INPUT);
pinMode(servoMetal, OUTPUT);
pinMode(servoGlass, OUTPUT);
pinMode(switchGlass, INPUT);
pinMode(statusPin, OUTPUT);
}

void loop()

{

HallVal = digitalRead(HallPin);        //read Hall sensor first
if (HallVal == 1){
metal();
}

if (HallVal == 0){                     //if there is no presence of metal then move to glass/plastic sorting functions
glass1();
switchVal = digitalRead(switchGlass); //read switch for presence of either glass or plastic
if (switchVal == LOW) {                //if the switch is pressed, sort for glass
glass2();

}

if (switchVal == HIGH) {              //if the switch is not pressed, sort for plastic

plastic();

}

}

}

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

Blog at WordPress.com.

%d bloggers like this: