Advertisement
Maderdash

bottle machine

Apr 26th, 2022
1,361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //LED
  2. int fail;
  3. int pass;
  4. int recording;
  5. int p=500;
  6.  
  7. //declration for mapping the delau potentiometer
  8. float s1;
  9. float s2;
  10. float s3;
  11. float s4;
  12. float s5;
  13. float s6;
  14. float s7;
  15.  
  16. //  declaration of  "reading of delay"
  17. float Reading_Headup ;
  18. float Reading_Headdown ;  
  19. float Reading_Holder ;
  20. float Reading_Rej ;
  21. float Reading_vblowon ;
  22. float Reading_vblowoff ;
  23. float Reading_ps;
  24.  
  25. //declare the values
  26. float max_rej;
  27. float max_accept;
  28. float normal_value;
  29.  
  30. //states of gb and rb  declaration
  31. int state_prox;
  32. int state_GB;
  33. int state_RB;
  34. int state_test_button;
  35.  
  36. //detect bottle
  37. //Scan for button
  38. //Take pressure readings
  39. //Pass fail test
  40. //flow, or kickout.
  41. // Record button Decleration
  42. int GB=7;
  43. int RB=9;
  44. int test_button=6;
  45.  
  46. //pressure sensor Declearation
  47.  int Ps = A7;
  48.  
  49. //Delays Declatartion
  50. float DELAY_Headup =A4;
  51. float DELAY_Headdown =A1;  
  52. float DELAY_Holder =A2;
  53. float DELAY_Rej =A3;
  54. float DELAY_vblowon =A5;
  55. float DELAY_vblowoff =A6;
  56. // valves Declearation
  57.  
  58. int V_Rej = 22;
  59. int V_Head = 26;
  60. int V_Holder =28;
  61. int V_Blow =30;
  62.  
  63. //status LED Declearation
  64. int Fail_LED=32;
  65. int Pass_LED=34;
  66. int Rec_LED=35;
  67.  
  68. // proximity declaration
  69. int prox = 36 ;
  70.  
  71. // Belt conveyor break
  72. int Belt_break = 38 ;
  73.  
  74.  
  75. void setup() {
  76. pinMode( Ps ,INPUT);
  77. pinMode( DELAY_Headdown ,INPUT); //potentiometer 1
  78. pinMode( DELAY_Headup ,INPUT); //potentiometer 2
  79. pinMode( DELAY_Holder ,INPUT);//potentiometer 3
  80. pinMode( DELAY_Rej ,INPUT);//potentiometer 4
  81. pinMode( prox ,INPUT);
  82. pinMode( DELAY_vblowon ,INPUT);//potentiometer 5
  83. pinMode( DELAY_vblowoff ,INPUT);//potentiometer 6
  84. pinMode( GB ,INPUT);
  85. pinMode( RB ,INPUT);
  86. pinMode (test_button,INPUT);
  87. pinMode ( Belt_break,OUTPUT);
  88. pinMode (Fail_LED,OUTPUT);
  89. pinMode (Pass_LED,OUTPUT);
  90. pinMode (Rec_LED,OUTPUT);
  91.  
  92. }
  93.  
  94.  
  95.  
  96. // Clear the currently stored maximum
  97. void clearReading(){
  98.   prevReading = 0;
  99. }
  100.  
  101. // Check for the current maximum and store it
  102. void updateReading(int curReading){
  103.   if(prevReading < curReading)
  104.     prevReading = curReading;
  105. }
  106.  
  107. // Display the currently stored maximum
  108. void displayReading(){
  109.   Serial.println(prevReading)
  110. }
  111.  
  112. void loop() {
  113.   Serial.begin(9600);
  114.  
  115.  
  116. state_GB = digitalRead(GB);
  117. state_RB = digitalRead(RB);
  118.  state_prox=digitalRead (prox);
  119.  state_test_button=digitalRead (test_button);
  120.  state_prox==digitalRead (prox);
  121. clearReading();
  122.  s1=  map (Reading_Headup, 0 ,1023 ,0 , 10000); // max delay 10sec
  123.  
  124.  s2=map (Reading_Headdown, 0 ,1023 ,0 , 10000); // max delay 10sec
  125.  
  126.  s3= map (Reading_Holder, 0 ,1023 ,0  , 10000); // max delay 10sec
  127.  
  128.  s4=map (Reading_Rej, 0 ,1023,  0   , 10000); // max delay 10sec
  129.  
  130.  s5= map (Reading_vblowon, 0 ,1023, 0   , 10000);// max delay 10sec
  131.  
  132.  s6 = map(Reading_vblowoff ,0 ,1023 ,0,10000);// max delay 10sec
  133.  
  134.  s7=map (Reading_ps, 0 , 0.025 , 0,10);
  135.  
  136.  Reading_Headup = analogRead(DELAY_Headup) ;
  137.  Reading_Headdown= analogRead(DELAY_Headdown) ;  
  138.  Reading_Holder= analogRead(DELAY_Holder) ;
  139.  Reading_Rej= analogRead(DELAY_Rej) ;
  140.  Reading_vblowon= analogRead(DELAY_vblowon) ;
  141.  Reading_vblowoff= analogRead(DELAY_vblowoff) ;
  142.  
  143.  Reading_ps=analogRead(Ps);
  144.  updateReading(Reading_ps);
  145.  
  146.  Serial.println("HEAD UP DELAY" ) ;
  147.  Serial.println (s1);
  148.  delay(10);
  149.  
  150.  
  151. //Serial.println("pressurereading=" ) ;
  152. //Serial.println ( s7);
  153.  
  154.  
  155. /*
  156.   if(state_GB==HIGH)
  157.  
  158.  
  159. {
  160.   Serial.println("GB ON");
  161. delay(p);
  162. }
  163.  
  164.   else {Serial.println("GB off");
  165.   delay(p);
  166.   }
  167.  
  168.   if(state_prox==HIGH)
  169.  
  170.  
  171. {
  172.   Serial.println("prox ON");
  173.   delay(p);
  174.   }
  175.   else {Serial.println("prox off");
  176.   delay(p);
  177.   }
  178.  
  179.  
  180.   if(state_RB==HIGH)
  181.  
  182.  
  183. {Serial.println("RB ON");
  184. delay(p);
  185. }
  186.   else {Serial.println("RB off");
  187.   delay(p);
  188.   }
  189.  
  190.  
  191. if(state_test_button==HIGH)
  192.  
  193.  
  194. {Serial.println("testing button on ");
  195. delay(p);
  196. }
  197.  else {Serial.println("testing button off");
  198.  
  199.  delay(p);
  200.  }
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.   */
  208.  
  209.  
  210.  //MODE "1" RECORDING GOOD BOTTLE
  211.  
  212.  
  213.  
  214.  
  215.   if (state_GB==HIGH && state_prox==HIGH )
  216.  {
  217.  
  218.  
  219.   Serial.println("REC_GOOD_MODE");
  220.   digitalWrite (Pass_LED,HIGH);
  221.  
  222.   digitalWrite (Rec_LED,HIGH);
  223.   delay(Reading_Headdown);
  224.   digitalWrite(Belt_break,HIGH);
  225.   digitalWrite( V_Head , HIGH);
  226.   delay(Reading_Headup);
  227.   delay( Reading_vblowon);
  228.   digitalWrite( V_Blow , HIGH);
  229.  
  230.     delay(Reading_vblowoff);
  231.  
  232.    digitalWrite( V_Blow , LOW);
  233.    delay(p);
  234.    //max function has been added lately new adjustment date 27.4.2022  
  235.    max_accept=max(Reading_ps);
  236.  
  237.   if (reading_ps > oldReading){
  238.     oldReading = Reading_ps;
  239.   }
  240.   if (digitalRead(A1)){
  241.     Serial.println(oldReading);
  242.     oldReading = 0;
  243.   }
  244.  
  245.  
  246.   digitalWrite( V_Head , LOW);
  247.       digitalWrite(Belt_break,LOW);
  248.  
  249.  }
  250.  
  251.  
  252.  //MODE2 RECORDING REJ BOTTLE  
  253.  
  254.  if   (state_RB==HIGH && state_prox==HIGH )
  255.  {
  256.   Serial.print("REC_REJ_MODE");
  257. digitalWrite(Fail_LED,HIGH);
  258.  
  259. digitalWrite (Rec_LED,HIGH);
  260.    
  261.    
  262.    delay(Reading_Headdown);
  263.  digitalWrite(Belt_break,HIGH);
  264.  digitalWrite( V_Head , HIGH);
  265.    delay(Reading_Headup);
  266.    delay( Reading_vblowon);
  267.  digitalWrite( V_Blow , HIGH);
  268.    delay(Reading_vblowoff);
  269.   digitalWrite( V_Blow , LOW);
  270.    //max function has been added lately new adjustment date 27.4.2022
  271. max_rej=max(Reading_ps);
  272.    displayReading()
  273.    delay(  Reading_vblowoff);
  274.    
  275.  
  276.  
  277.  
  278.  digitalWrite( V_Head , LOW);
  279.  
  280.       digitalWrite(Belt_break,LOW);
  281.    delay( Reading_Rej);
  282.  
  283.   digitalWrite( V_Rej , HIGH);
  284.   delay(100);
  285.  
  286. digitalWrite( V_Rej ,LOW);
  287.  
  288.   }
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297. //MODE3 TESTING  
  298.  
  299.  
  300.  if ( state_test_button ==HIGH  &&   state_prox ==HIGH)
  301.  {
  302.   Serial.println("testing");
  303.  
  304.     delay(Reading_Headdown);
  305.  digitalWrite(Belt_break,HIGH);
  306.  digitalWrite( V_Head , HIGH);
  307.    delay(Reading_Headup);
  308.    delay( Reading_vblowon);
  309.  digitalWrite( V_Blow , HIGH);
  310.    //max function has been added lately new adjustment date 27.4.2022 hoping i doen't get the 3 values the same
  311.  normal_value==Reading_ps;
  312.    
  313.    
  314.    
  315.    delay(Reading_vblowoff);
  316.    
  317.   digitalWrite( V_Blow , LOW);
  318.  
  319.   if( normal_value>=max_accept   ||  max_rej<normal_value <= max_accept  )                  
  320.   {
  321.    
  322.  digitalWrite (Pass_LED,HIGH);
  323.    
  324. digitalWrite( V_Head , LOW);
  325.  digitalWrite(Belt_break,LOW);
  326.    
  327.     }
  328.     else if(normal_value<=max_rej     )
  329.    
  330.     {
  331.    
  332.  digitalWrite(Fail_LED,HIGH);
  333.       digitalWrite( V_Head , LOW);
  334.       digitalWrite(Belt_break,LOW);
  335.        delay( Reading_Rej);
  336.  
  337.   digitalWrite( V_Rej , HIGH);
  338.   delay(100);
  339.  
  340. digitalWrite( V_Rej ,LOW);
  341.      
  342.       }
  343.  
  344.  
  345.  
  346.  
  347.  }
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement