# Automatic sorting machine – Mechatronics Student Project

This machine was created as a student project for the subject Construction & CAD, at the Mechanical Engineering faculty in Skopje, by a team of five students.
It is a machine that is sorting two types of plates. One of the plates have holes and the other ones don’t have. Our task was to develop a machine that will sort out these plates automatically. We have came out with this solution, which actually won the first place out of 25 other machines.

## How It Works

This is how the Automatic Sorting Machine works:

• The plates are fed into the machine by hand.
• The roller aligns the plates to fall in the plate magazine one by one.
• When the plate reach the bottom of the sorter, it triggers a micro switch.
• When the switch is on, the LED turns ON.
• If the plate has a hole the Photocell will receive more light and the motor will rotate to one side.
• If the plate doesn’t have a hole the Photocell will receive less light and the motor will rotate to the other side.

## Circuit Schematic

The machine uses PIC16F628A micro-controller and it is programmed using MikroElektronika.

## Source Code

```.wp-block-code {
border: 0;
}

.wp-block-code > span {
display: block;
overflow: auto;
}

.shcb-language {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
position: absolute;
width: 1px;
word-wrap: normal;
word-break: normal;
}

.hljs {
box-sizing: border-box;
}

.hljs.shcb-code-table {
display: table;
width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
color: inherit;
display: table-row;
width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
white-space: pre;
}

.wp-block-code code.hljs.shcb-wrap-lines {
white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
border-spacing: 0;
counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
}

.hljs.shcb-line-numbers .shcb-loc::before {
border-right: 1px solid #ddd;
content: counter(line);
display: table-cell;
text-align: right;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: 1%;
}
```/********************************************************************************/
/* Mechatronic Design Team */
/* Proekt po Konstruiranje i CAD */
/* "Dizajn i razvoj na nov ured za razdeluvanje na dva tipa plocki" */
/* */
/* */
/* */
/* Mikrokontroler: PIC16F628A */
/* Oscilator: Interen na 4MHz */
/* */
/* Dekemvri, 2012, Skopje */
/********************************************************************************/
void left () {

RB2_bit = 1; //motorot pocnuva da se dvizi na levo
delay_ms (500); // motorot se dvizi do krajna leva polozba
delay_ms (500);
delay_ms (500);
delay_ms (500);
PORTB = 0x00; //koga ke stigne do krajnata leva polozba se gasi
delay_ms (200); //vreme za kocenje na motorot
RB3_bit = 1; //se aktivira relejot za promena na nasokata
delay_ms (20);
RB2_bit = 1; //motorot pocnuva da se dvizi desno
delay_ms (500); //sredna pozicija na motorot
delay_ms (500);
delay_ms (500);
delay_ms (500);
PORTB = 0x00; //motorot se gasi koga ke dojde do sredina
delay_ms (150); //vreme za kocenje na motorot
}

//////////////////////////////////////////////////////////////////////////////

void right () {
RB3_bit = 1; //Se uklucuva relejot za promena na nasoka na motorot
delay_ms (30);
RB2_bit = 1; //motorot pocnuva da se dvizi desno
delay_ms (500);
delay_ms (500);
delay_ms (500);
delay_ms (500); //motorot se dvizi do krajna desna polozba
PORTB = 0x00; //koga ke stigne do krajna desna polozba se gasi
delay_ms (200); //vreme za kocenje na motorot
RB2_bit = 1; //motorot pocnuva da se dvizi levo
delay_ms (500); //sredna pozicija na motorot
delay_ms (500);
delay_ms (500);
delay_ms (500); //sredna pozicija na motorot
PORTB = 0x00; //motorot se gasi koga ke dojde do sredina
delay_ms (150); //vreme za kocenje na motorot
}

//////////////////////////////////////////////////////////////////////////////

void main() { //pocetok na glavna programa
TRISB = 0x00; //PORTB Izlezi
TRISA = 0xff; //PORTA Vlezovi
CMCON = 0x07; //gasenje na komparatori
do {
delay_ms (50);
PORTB = 0x00;
if (PORTA.b0==1) { //dali ima kocka?
delay_ms (100);
if (PORTA.b1==0) { //dali ima otvor?
left (); } //ako ima otvor dvizi se levo
else (right ()); }} //ako nema dvizi se desno
while (1); }```Code language: Arduino (arduino)```