Introduction: Apple Packaging System Simulation Using PIC

The main idea of the project is to test your basics dealing with the PIC micro controller, you know, switches and motors and very basic functions. So, if you’re a beginner, this tutorial is for you!. I used PIC16876A because it’s widely used with individuals and I have my own, in case you have another version of the micro controller not much will be changed because the project doesn’t use any particular module or drives that can differ from one type to another.

Step 1: The Process

The system should consist of two conveyors, one for apples, the other is for the boxes. A sensor should detect whether a box is now standing in front of the apple conveyor or not, if so, the sensor reads 0, else it reads 1. Another sensor is used to detect whether an apple passes by or not. A box is filled with 10 apples max .

The packaging process goes as following: 1- Boxes conveyor moves until the boxes sensor detects a box, then boxes conveyors stops and apple conveyor starts moving. 2- After ten apples where detected by the apples sensor, the apple conveyor stops and and the boxes conveyors start moving again until the box is detected again and so on. I represented sensors with switches that I controlled manually, and the motors with green LED for apples and yellow LED for boxes.

Step 2: The Code:

Now the code:



#use delay(clock=8000000)

#define sensorBox pin_b2

#define sensorApple pin_b1

#define motorBox pin_c1

#define motorApple pin_c2

#use rs232(baud=9600, xmit=PIN_c6,rcv=PIN_c7)

#define limit 3


void main()

{ int8 c1=0;

int8 c2=0;

set_tris_b(0xFF); //switches (sensors) b1>>apples, b2>>bxesport_b_pullups(TRUE);set_tris_c(0x80);//motors (LEDs) c1>>motor1:boxes,c2>>motor2:applesoutput_high(motorBox);output_low(motorApple);int16 apples;int8 flag;//flag is high when 10 apples are in box while(1){ putc(‘A’);if(input(sensorApple)==0){ if(c1