// Industrial Shields by BOOT & WORK CORP.
// Nov.2014 technical information for newsletter
//
//////////////////////////////
//// PLC: ARDBOX ANALOG MODULE////
//// Number of inputs: 7
//// Number of outputs: 8
//// you need confiurate the correctly switch position for running like digital / analog or PWM mode.
//////////////////////////////
////   Ardbox Connector:
//// LEFT SIDE////
//// Q0.6 ----- PIN 3  ---- Analog / PWM / Digital Output (0-10Vdc / 24Vdc)
//// Q0.5 ----- PIN 5  ---- Analog / PWM / Digital Output (0-10Vdc / 24Vdc)
//// Q0.4 ----- PIN 6  ---- Analog / PWM / Digital Output (0-10Vdc / 24Vdc)
//// Q0.3 ----- PIN 9  ---- Analog / PWM / Digital Output (0-10Vdc / 24Vdc)
//// Q0.2 ----- PIN 10 ---- Analog / PWM / Digital Output (0-10Vdc / 24Vdc)
//// Q0.1 ----- PIN 11 ---- Analog / PWM / Digital Output (0-10Vdc / 24Vdc)
//// Q0.0 ----- PIN 13 ---- Analog / PWM / Digital Output (0-10Vdc / 24Vdc)
////RIGHT SIDE////
//// I0.9 ----- PIN A0 ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// I0.8 ----- PIN A1 ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// I0.7 ----- PIN A2 ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// I0.6 ----- PIN A3 ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// I0.5 ----- PIN A4 ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// I0.4 ----- PIN A5 ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// I0.3 ----- PIN 4  ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// I0.2 ----- PIN 8  ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// I0.1 ----- PIN 12 ---- Analog / Digital Input (0-10Vdc / 24Vdc)
//// com-I0.0 ------------- GND isolated from I0.0 signal.
//// I0.0 ----- PIN 2  ---- Digital Input (24Vdc)
//// Q0.9 ----- PIN 0 ----  Digital Output (24Vdc)
//// Q0.8 ----- PIN 1 ----  Digital Output (24Vdc)
//// Q0.7 ----- PIN 7 ----  Digital Output (24Vdc)
////
//// LED INFORMATION
////  0 -- Q0.1
////  1 -- Q0.0
////  2 -- Q0.3
////  3 -- Q0.2
////  4 -- Q0.5
////  5 -- Q0.4
////  6 -- Q0.7
////  7 -- Q0.6
////  8 -- Q0.9
////  9 -- Q0.8
////  10 -- I0.1
////  11 -- I0.0
////  12 -- I0.3
////  13 -- I0.2
////  14 -- I0.5
////  15 -- I0.4
////  16 -- I0.7
////  17 -- I0.6
////  18 -- I0.9
////  19 -- I0.8
////
//// <<< IMPORTANT>>>> : SEE SWITCH CONFIGURATION IN USER_GUIDE_ARDBOX_FAMILY IN WWW.INDUSTRIALSHIELDS.COM
////
// Pin Ardbox Analog PLC conection:
// ------RIGHT SIDE------
// RP01 : Not Conected.
int I09 = A0;    // LEVEL OF STORAGE TANK (ANALOG INPUT "0-10Vdc")
int I08 = A1;    // REGULATOR QUANTITY OF ACID (ANALOG INPUT "0-10Vdc")
int I07 = A2;    // REGULATOR QUANTITY OF FLOCCULANT (ANALOG INPUT "0-10Vdc")
int I06 = A3;    // NOT CONECTED ....... select the Analog (0-10Vdc) / Digital (24Vdc)IN  **warning"" (if Analog slection connect 10Vdc MAX).
int I05 = A4;    // NOT CONECTED ....... select the Analog (0-10Vdc) / Digital (24Vdc)IN  **warning"" (if Analog slection connect 10Vdc MAX).
int I04 = A5;    // OK WATER INTO PROCESSING PLANT ( DIGITAL INPUT "24Vdc")
int I03 = 4;     // AUTO/MANUAL SELECTOR (DIGITAL INPUT "24Vdc")
int I02 = 8;     // MINIMUM LEVEL OF GRAVITY FILLING TANK (DIGITAL INPUT "24Vdc")
int I01 = 12;    // FULL LEVEL GRAVITY FILLING TANK (DIGITAL INPUT "24Vdc")
int I00 = 2;     // NOT CONECTED ...... Digital INPUT (24Vdc)
int Q09 = 0;     // GREEN LIGHT (AUTO MODE)(Digital OUTPUT "24Vdc")
int Q08 = 1;     // RED LIGHT (AUTO MODE) (Digital OUTPUT "24Vdc")
int Q07 = 7;     // AIR ELECTROVALVE (Digital OUTPUT "24Vdc")
// ------LEFT SIDE------
//Configuration Digital IN (24Vdc)
int Q06 = 3;     // ACID DOSING PUMP (ANALOG OUTPUT "0-10Vdc")
int Q05 = 5;     // GRINDER PUMP (DIGITAL OUTPUT "24Vdc")
int Q04 = 6;     // FILLING PUMP TO PROCESSING MACHINE (DIGITAL OUTPUT "24Vdc")
int Q03 = 9;     // FLOCCULANT DOSING PUMP (PWM OUTPUT "24Vdc")
int Q02 = 10;    // FULL LEVEL GRAVITY FILLING TANK (DIGITAL OUTPUT "24Vdc")
int Q01 = 11;    // NOT CONECTED ...... select the Analog (0-10Vdc) / PWM (10 OR 24Vdc) /Digital (24Vdc)OUTPUT  
int Q00 = 13;    // NOT CONECTED ...... select the Analog (0-10Vdc) / PWM (10 OR 24Vdc) /Digital (24Vdc)OUTPUT  

int MinStorageTank=200; // defineix el valor minim del tank.
int MaxStorageTank=1000; // defineix el valor minim del tank.


void setup() {
pinMode(Q06, OUTPUT);  
pinMode(Q05, OUTPUT);  
pinMode(Q04, OUTPUT);  
pinMode(Q03, OUTPUT);  
pinMode(Q02, OUTPUT);  
pinMode(Q01, OUTPUT);  
pinMode(Q00, OUTPUT);  
pinMode(Q09, OUTPUT); 
pinMode(Q08, OUTPUT); 
pinMode(Q07, OUTPUT); 

pinMode(I09, INPUT);  
pinMode(I08, INPUT);  
pinMode(I07, INPUT);  
pinMode(I06, INPUT);  
pinMode(I05, INPUT);  
pinMode(I04, INPUT);  
pinMode(I03, INPUT);
pinMode(I02, INPUT);
pinMode(I01, INPUT);
pinMode(I00, INPUT);
//Start configuration mode
digitalWrite(Q00,LOW); //Digital configuration -NOT WORKING NOW-
digitalWrite(Q01,LOW); //Digital configuration -NOT WORKING NOW-
digitalWrite(Q02,LOW); //Digital configuratioN
analogWrite(Q03,0); //PWM 24Vdc configuration
digitalWrite(Q04,LOW); //Digital configuration
digitalWrite(Q05,LOW); //Digital configuration
analogWrite(Q06,0); //Analog 0-10Vdc configuration
digitalWrite(Q07,LOW); //Digital configuration
digitalWrite(Q08,LOW); //Digital configuration
digitalWrite(Q09,LOW); //Digital configuration


}
void loop() {

if (I03==HIGH){   //Program is running when AUTO/MANUAL Selector is ON (AUTO)
  digitalWrite(Q02,digitalRead(I01)); // Recieve and send when the level of Gravity tank is in max lebel
  
  //---- Auto PROCESSING MACHINE alimentation----
  if (I04 == HIGH && I09>=MinStorageTank) { //Processing plant send us if it need waste water for run. and if the level of storage tank is ok put the instalation to work
    digitalWrite(Q04,HIGH); //Put Filling pump to processing machine running
    digitalWrite(Q09,HIGH); //Switch on the green light
    digitalWrite(Q08,LOW);  //Switch off the red light
    analogWrite(Q03,digitalRead(I07)); //Put Floculant dosing PUMP running (It is adjusting by manual regulator)
  } else { //If the installation can not work for incorrect level of storage tank or the processing machine don't need waste water 
    digitalWrite(Q04,LOW);  //Put Filling pump to processing machine in mode OFF
    digitalWrite(Q09,LOW);  //Switch off the green light
    digitalWrite(Q08,HIGH); //Switch on the red light
    digitalWrite(Q03,0);  //Put Floculant dosing PUMP not running.
  }
  
  //---- Auto Fill of Storage Tank----
  if (I09 < MinStorageTank){ 
    digitalWrite(Q05,HIGH);
    analogWrite (Q06, analogRead(I08)/4); //Put ACID dosing PUMP running (It is adjusting by manual regulator)
  } else{
    digitalWrite(Q05,LOW);
    analogWrite(Q06,0);  //Put ACID dosing PUMP not running.
    
  }
}
//desconectar-ho tot al principi.

}


// Industrial Shields share these project for training purposes. We are not responsible for the use.
// Creative Commons register. Open Source mind
    


  

