sorting conveyor

need help so that i can place more than one part on conveyor to sort. there are 6 part small tall, small short,medium tall.,medium short , large tall and large short. there are three sorter i am doing small , large ,and middle need help with shift data to run more than one part

UCI_BB2_S3_Dual_DS1820.ino (2.08 KB)

Has the program that you attached got anything to do with your question ?
By the way, I don't understand your question.

came only do one part at a time. need to have mult part on at on time to sort

int SWG = 31;  // Switch Green          
int SWR = 33;  // Switch Red            
int S2 = 37;   // Sensor #2             

//Outputs

int LG = 53;  // Green Light          
int LR = 51;  // Red Light            
int E = 39;   // Energize    
int C1 = 45;  // Piston Farthest            
int C2 = 47;  // Piston Middle      
int C3 = 43;  // Piston Closest        

//Variables

boolean enable = LOW;       
boolean lastGreen = LOW;
boolean currentGreen = LOW;
boolean lastRed = LOW;
boolean currentRed = LOW;

//Debounce

boolean debounce(boolean last)
  {
  boolean current = digitalRead(SWG);
  
  if (last != current)
    {
          delay(5);
          current = digitalRead(SWG);
     }
     return current;
  }
  
  

boolean debounceRed(boolean last)
  {
  boolean current = digitalRead(SWR);
  
        if (last != current)  
        {
              delay(5);
              current = digitalRead(SWR);
        }
        
  return current;
  }


void setup()
  
  {
    
  Serial.begin(9600);
  pinMode(SWG, INPUT);
  pinMode(SWR, INPUT);
  pinMode(S2, INPUT);

  pinMode(LG, OUTPUT);
  pinMode(LR, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(C1, OUTPUT);
  pinMode(C2, OUTPUT);
  pinMode(C3, OUTPUT);

  }

int i=0;

void loop()
  
  {
//Button Debounce 

  currentRed = debounceRed(lastRed);
  
  if (lastRed == LOW && currentRed == HIGH)
    
    {
        lastRed = currentRed;
    } 
    
  else 
    
    {
      lastRed = digitalRead(SWR);
    }
    
    
  currentGreen = debounce(lastGreen);
  
  if (lastGreen == LOW && currentGreen == HIGH)
    {
          lastGreen = currentGreen;
    
    } 
    
  else 
    {
          lastGreen = digitalRead(SWG);
    }

if (lastGreen == HIGH)
  {
  
  enable = HIGH;

  } 
  
  else if (lastRed == HIGH) 
  {
  
  enable = LOW;
  }

//Start and Stop Buttons

  if (enable == HIGH) 
    {
    
        digitalWrite(E, HIGH); // Belt & Green Light=ON
        digitalWrite(LG, HIGH); //Green light=ON
        digitalWrite(LR, LOW);  // Red light=OFF
        do  
        
        {
    
         i++;
         
        } 
          
         while (digitalRead(S2)==LOW);   // measure width of part passing through sensor
          Serial.println(S2);             //display on serial monitior 
         Serial.println(i);
         Serial.println(37);
         
        
        if (i>=67 && i<=77)
          {
                
                delay (2000);
                digitalWrite(C3, HIGH);  // Piston 3 ON=Extend Plunger Arm
                delay (500);             // Small Part
                digitalWrite(C3, LOW);   // Piston Closest OFF=Retract
          }
        
        else if ( i>=110 && i<=120)
        
          {
                delay (2900);
                digitalWrite(C2, HIGH);  // Piston 2 ON=Extend Extend Plunger Arm
                delay (500);             // Medium Part
                digitalWrite(C2,LOW);    // Piston Middle OFF=Retract
          }
        
        else if (i>=145 && i<=155)
          {
                delay (4000);
                digitalWrite(C1, HIGH);  // Piston 1 ON=Extend Plunger Arm
                delay (500);             // Large Part
                digitalWrite(C1, LOW);   // Piston Farthest OFF=Retract
          }
        
        else if(i<=89 && i>=186)
          {
         
          }
        
        i=0;
        
          } 
        
        else if (enable == LOW)
          
          {
  
        digitalWrite(E, LOW);  // Belt, Green Light is off 
        digitalWrite(LG, LOW);
        digitalWrite(LR, HIGH); // Red light "ON"
        
          } 


        }

I don't understand the question either, except that you 'need help'.

need to no how to program a loop in so that i can place more than one item on conveyor. once the sensor read one part and starts reading another the first part does not work. does one part at a time i have six different parts to sort. would like then to to be able to put part on on behind the other. cannot use shift register. the parts are sorted in to 3 different containers small, medium large

Look up both the Blink without Delay example in the IDE and Functional State Machine. You'll need both methods.

Next question -- is this a homework assignment? Because this sounds like you're asking us to do your homework ...

You need to write a long description of what you are doing - don't skimp on the typing.

What things are placed on the conveyor?
What are you using to identify them?

What is the Arduino supposed to do?
How is it connected to whatever it needs to be connected to?

I wrote a demo sketch here Demonstration code for several things at the same time - Project Guidance - Arduino Forum that sjows how the Blink Without Delay and the State Machine concepts can be used to do several tasks at the same time.

...R

jholland7766:
the first part does not work

You aren't giving us much to go on here, but I guess you have some code that moves one part past three sensors and decides what to do with it at the end based on all the sensor readings. If you want to be able to pass different parts simultaneously past each sensor then you need to design your sketch to keep track of which part is at which sensor and accumulate all the sensor readings associated with each part. For example you could define a struct holding all the sensor readings for a given part, and then create a circular buffer of those structs which advances as the physical parts are moved through the sensors. It's far from a trivial design problem, and if you're being set problems this difficult I'd expect you to know how to go about designing algorithms and writing software.

here is a video of what i want the conveyor to do. i am using one sensor to sort. each container will sort to part in each. their are two part that have the same diameter in each container.one part is taller the the other. total of six parts. my program i can do one part at a time. once the sensor reads another part in will not sort the first part just the second. need help to hold data to keep it sorting all part .

You need to do something like what I described in Using Millis! HELP!!! - Programming Questions - Arduino Forum. Each whacker has a time scheduled in the future by the thing size detector when it is going to whack a part into the bin.

Again, you have given us only a few words of description. The video is interesting and helpful. I now know how I would plan your project. The problem is that I have no idea how you are planning to do it.

You need to write a script (like for a play or a movie - not a computer) describing every single thing that happens as one piece moves along the conveyor. Once you have done that it should be reasonably simple to write code that does the same thing.

...R

Robin2:
Again, you have given us only a few words of description. The video is interesting and helpful. I now know how I would plan your project. The problem is that I have no idea how you are planning to do it.

You need to write a script (like for a play or a movie - not a computer) describing every single thing that happens as one piece moves along the conveyor. Once you have done that it should be reasonably simple to write code that does the same thing.

…R

Agreed. 10 minutes spent with a pen and paper, accurately defining what is needed, can save hours of programming time. If it’s an accurate and complete, stepwise definition, the program will be almost written.

i have 6 part. place part a on belt si reads width and sort in to desire spot . if part b is placed on belt and si reads before part a is sort. part a will not sort just ride the belt to the end. i need to no have to declare value to hold the part as si reads the . so if "i’ is >what read data how can i get it to other value. i have tried using if i is greater than my value it a the same for b and c still will not work . can some please help thanks