Vacuum loader control

IND.I/O project

Community

Vacuum loading of a plastic extrusion machine with Industruino

Alex wrote to us about his project which automates the vacuum loading of a plastic extrusion moulding machine. 

Have a look at his comprehensive video in which he clearly explains the process through a simulation.

 

Alex's code and explanation:

/*
A typical vacuum loading system, used in the plastic industry as well as other industries to convey material, works as follows: a central vacuum pump creates a vacuum. pipes and hoses connect the pump to vacuum loaders. 
when there is demand in a vacuum loader (usually both a proximity switch under the vacuum loader and a toggle switch in a panel) a signal opens a solenoid valve that allows the vacuum to pull material through to the vacuum loader.
only 1 loader should vacuum at a time.

the arduino sketch works as follows:
there are 4 toggle switches connected to digital inputs 1 to 4. these switches determine which vacuum loader demands material. 
The sketch cycles through the 4 inputs, and if a switch is on, it will power the corresponding solenoid 
valve (digital outputs 5 to 8) for a predetermined amount of time (loadDuration). Additionally, there a safety/relief valve. if there is no demand in any vacuum loader (IE all switches are off)
the sketch will power ON this valve (analog output 1). in some systems a signal might just turn off the vacuum pump, that's not the case here.
additionally, this relief valve is also turned ON if only 1 loader has demand: that is because there must always be some OFF time to unload the material in the loader: if a loader runs continuosly it will 
overfill and malfunction.
This system has one more output (analog output 2): there is a filtered dust separator between the vacuum line and the pump, and it is equipped with a blowback feature, which is scheduled to power every hour of operation (approx.). 
basically it is another selonoid valve which blows air on the filters to clean them.

---LCD---

the lcd does the following: it displays the 4 loaders, and shows which loader's switch is on (with an update delay of under 1 second). 
it shows which loader is currently active, and for how many more seconds.
it shows the total time system has been running since last reboot.
it informs if safety/relief valve is on, and if blowback valve is on.

-----------------------------

---Created by Alex Netzer----

-----------------------------

*/

#include <UC1701.h>
#include <Wire.h>
#include <Indio.h>
static UC1701 lcd;

int overallTimer;  //will keep track of total time system has been running. used to display time
int blowTimer;     //keeps track of time for the purpose of activation blower approx. every hour
int loadDuration;  //defines duration that each vacuum loader stays on. change to this will affect all loaders
int hours;
int minutes;
int seconds;
int totalLoaders;  //checks how many vacuum loaders are ON

void setup() {
  
  Indio.digitalMode(1,INPUT);  // Set CH1 as an input
  Indio.digitalMode(2,INPUT);  // Set CH2 as an input
  Indio.digitalMode(3,INPUT);  // Set CH3 as an input
  Indio.digitalMode(4,INPUT);  // Set CH4 as an input
  Indio.digitalMode(5,OUTPUT); // Set CH5 as an output 
  Indio.digitalMode(6,OUTPUT); // Set CH6 as an output 
  Indio.digitalMode(7,OUTPUT); // Set CH7 as an output 
  Indio.digitalMode(8,OUTPUT); // Set CH8 as an output 
  Indio.analogWriteMode(1, V10); //set analog CH1 to 10v output for safety valve
  Indio.analogWriteMode(2, V10); //set analog ch2 to 10v output for blowback valve
  pinMode(13,OUTPUT); // 13 is the backlight
  analogWrite(13, LOW); //backlight on
  loadDuration=5; // enter duration of each loader, in seconds. change here to affect all loaders.
  overallTimer=1; // used to display total running time
  blowTimer=0;    // used to keep track of when blowback needs to run 

  lcd.begin();
  lcd.setCursor(0, 3); 
  lcd.print("  L1   L2   L3   L4 ");
  lcd.setCursor(0, 4);
  lcd.print("  off  off  off  off");
}


// screenUpdate is the function that checks if toggle switches are on or off and accordingly updates the lcd screen
// as you can see later, this function is run every second, so any switch change will update in the lcd within up to a second

void screenUpdate(){                
   
  if (Indio.digitalRead(1) == HIGH) {
     lcd.setCursor(0, 4);
     lcd.print("  on ");
   }

    else{
     lcd.setCursor(0, 4);
     lcd.print("  off");        
  } 

  if (Indio.digitalRead(2) == HIGH) {
     lcd.setCursor(30, 4);
     lcd.print("  on ");
  }

   else{
     lcd.setCursor(30, 4);
     lcd.print("  off");        
  }  

   if (Indio.digitalRead(3) == HIGH) {
     lcd.setCursor(60, 4);
     lcd.print("  on ");
   }

    else{
     lcd.setCursor(60, 4);
     lcd.print("  off");        
  } 

   if (Indio.digitalRead(4) == HIGH) {
     lcd.setCursor(90, 4);
     lcd.print("  on ");
   }

    else{
     lcd.setCursor(90, 4);
     lcd.print("  off");        
  }   
}

// displayTime checks overallTimer and uses it to update the total running time displaid in the top line. as you can see later, it updates every second.  

void displayTime()  //this function was adapted from a tutorial by John Boxall, which you can view here: http://tronixstuff.com/2011/06/22/tutorial-arduino-timing-methods-with-millis/

{
  float h,m,s;
  int over;
  h=int(overallTimer/3600);
  over=overallTimer%3600;
  m=int(over/60);
  over=over%60;
  s=over;
  lcd.setCursor(20, 0);  
  lcd.print(h,0);
  lcd.setCursor(40, 0);
  lcd.print(":");
  lcd.setCursor(45, 0);
  lcd.print(m,0);
  lcd.setCursor(58, 0);
  lcd.print(":");
  lcd.setCursor(63, 0);
  lcd.print(s,0);
}


void loop() {

// the following 4 IF statements cycle through the inputs and -  if they are ON- will turn the corrisponding output ON for "loadDuration" seconds.
//input 1  

 if (Indio.digitalRead(1) == HIGH) {
     for (int i=1; i <= loadDuration; i++){
      Indio.digitalWrite(5, HIGH);
      lcd.setCursor(15,6);
      lcd.print(loadDuration-i);
      screenUpdate();
      displayTime();
      delay(1000);                         // as you can see, there is a delay of 1 second which is repeated "loadDuration" times, 
      overallTimer=overallTimer + 1;        //this affects the "refresh rate" of the screen, as well as the time keeping element of the sketch.
      blowTimer=blowTimer + 1;               // while this might not be a very precise way to keep time, it is sufficient for the project.
      } 

      Indio.digitalWrite(5,LOW);
      lcd.setCursor(15,6);
      lcd.print("   ");
}

//input 2

 if (Indio.digitalRead(2) == HIGH) {
     for (int i=1; i <= loadDuration; i++){
      Indio.digitalWrite(6, HIGH);
      lcd.setCursor(45,6);
      lcd.print(loadDuration-i);
      screenUpdate();
      displayTime();
      delay(1000);
      overallTimer=overallTimer + 1;
      blowTimer=blowTimer + 1;
    } 

      Indio.digitalWrite(6,LOW);
      lcd.setCursor(45,6);
      lcd.print("   ");
 }

//input 3

 if (Indio.digitalRead(3) == HIGH) {

     for (int i=1; i <= loadDuration; i++){
      Indio.digitalWrite(7, HIGH);
      lcd.setCursor(75,6);
      lcd.print(loadDuration-i);
      screenUpdate();
      displayTime();
      delay(1000);
      overallTimer=overallTimer + 1;
      blowTimer=blowTimer + 1;
    } 

      Indio.digitalWrite(7,LOW);
      lcd.setCursor(75,6);
      lcd.print("   ");
 }

//input 4

 if (Indio.digitalRead(4) == HIGH) {

     for (int i=1; i <= loadDuration; i++){
      Indio.digitalWrite(8, HIGH);
      lcd.setCursor(105,6);
      lcd.print(loadDuration-i);
      screenUpdate();
      displayTime();
      delay(1000);
      overallTimer=overallTimer + 1;
      blowTimer=blowTimer + 1;
    } 

      Indio.digitalWrite(8,LOW);
      lcd.setCursor(105,6);
      lcd.print("   ");
 }

//-------relief valve operation----------

totalLoaders=Indio.digitalRead(1) +  Indio.digitalRead(2) +  Indio.digitalRead(3) +  Indio.digitalRead(4);  // here we check how many switches are on, in total

 if (totalLoaders <=1) {                //if only 1 loader is on, this safety valve runs for 5 seconds before returning to that loader. if no loaders are on,
     for (int i=1; i <=5; i++){          // sketch will keep returning to this function.
      Indio.analogWrite(1, 5, false);     // I only used analog output bacause I ran out of digital ones...
      lcd.setCursor(0,6);
      lcd.print("safety valve on!");
      screenUpdate();
      displayTime();
      delay(1000);
      overallTimer=overallTimer + 1;
     }  

      Indio.analogWrite(1, 0, false);
      lcd.setCursor(0,6);
      lcd.print("                ");  
  }  

//---------blowback valve operation---------

 if (blowTimer >3600) {                       // after every 3600 seconds of operations, which are tracked by blowTimer, blowback valve goes on for 7 seconds.
         for (int i=1; i <=7; i++){            // blowTimer only incremented when loaders where running and did not increase when relief valve was running. 
         Indio.analogWrite(2, 5, false);
         lcd.setCursor(0,2);
         lcd.print("BLOWBACK ACTIVATED!!!");
         screenUpdate();
         displayTime();
         delay(1000);
         overallTimer=overallTimer + 1;
     }  
  blowTimer=0;              // this counters now resets, waiting for one more hour to restart blowback valve
  Indio.analogWrite(2,0,false);
  lcd.setCursor(0,2);
  lcd.print("                        ");
 }
}