Advertisement
Maderdash

Bottle checker

Apr 26th, 2022
1,394
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. //states of gb and rb  declaration
  7. int state_prox;
  8. int state_GB;
  9. int state_RB;
  10. int state_test_button;
  11.  
  12. //declration for mapping the delau potentiometer
  13. float s1;
  14. float s2;
  15. float s3;
  16. float s4;
  17. float s5;
  18. float s6;
  19. float s7;
  20.  
  21. //  declaration of  "reading of delay"
  22. float Reading_Headup;
  23. float Reading_Headdown;
  24. float Reading_Holder;
  25. float Reading_Rej;
  26. float Reading_vblowon;
  27. float Reading_vblowoff;
  28. float Reading_ps;
  29. //declare the values
  30. float max_rej;
  31. float max_accept;
  32. float normal_value;
  33.  
  34.  
  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.  
  43.  
  44. int GB                  = 7;
  45. int RB                  = 9;
  46. int test_button         = 6;
  47.  
  48. //pressure sensor Declearation
  49. int Ps                  = A7;
  50.  
  51. //Delays Declatartion
  52. float DELAY_Headup      = A4;
  53. float DELAY_Headdown    = A1;
  54. float DELAY_Holder      = A2;
  55. float DELAY_Rej         = A3;
  56. float DELAY_vblowon     = A5;
  57. float DELAY_vblowoff    = A6;
  58. // valves Declearation
  59.  
  60. int V_Rej               = 22;
  61. int V_Head              = 26;
  62. int V_Holder            = 28;
  63. int V_Blow              = 30;
  64.  
  65. //status LED Declearation
  66. int Fail_LED            = 32;
  67. int Pass_LED            = 34;
  68. int Rec_LED             = 35;
  69.  
  70. // proximity declaration
  71. int prox                = 36;
  72.  
  73. // Belt conveyor break
  74. int Belt_break          = 38;
  75.  
  76.  
  77. void setup() {
  78.   pinMode(Ps, INPUT);
  79.   pinMode(DELAY_Headdown, INPUT);  //potentiometer 1
  80.   pinMode(DELAY_Headup, INPUT);    //potentiometer 2
  81.   pinMode(DELAY_Holder, INPUT);    //potentiometer 3
  82.   pinMode(DELAY_Rej, INPUT);       //potentiometer 4
  83.   pinMode(prox, INPUT);
  84.   pinMode(DELAY_vblowon, INPUT);   //potentiometer 5
  85.   pinMode(DELAY_vblowoff, INPUT);  //potentiometer 6
  86.   pinMode(GB, INPUT);
  87.   pinMode(RB, INPUT);
  88.   pinMode(test_button, INPUT);
  89.   pinMode(Belt_break, OUTPUT);
  90.   pinMode(Fail_LED, OUTPUT);
  91.   pinMode(Pass_LED, OUTPUT);
  92.   pinMode(Rec_LED, OUTPUT);
  93.   Serial.begin(9600);
  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.   state_GB = digitalRead(GB);
  114.   state_RB = digitalRead(RB);
  115.   state_prox = digitalRead(prox);
  116.   state_test_button = digitalRead(test_button);
  117.   state_prox == digitalRead(prox); //////////////////// <<<<<<<<<<<<<<<BAD ERROR!!!!!!!!!
  118.   s1 = map(Reading_Headup, 0, 1023, 0, 10000);  // max delay 10sec
  119.   s2 = map(Reading_Headdown, 0, 1023, 0, 10000);  // max delay 10sec
  120.   s3 = map(Reading_Holder, 0, 1023, 0, 10000);  // max delay 10sec
  121.   s4 = map(Reading_Rej, 0, 1023, 0, 10000);  // max delay 10sec
  122.   s5 = map(Reading_vblowon, 0, 1023, 0, 10000);  // max delay 10sec
  123.   s6 = map(Reading_vblowoff, 0, 1023, 0, 10000);  // max delay 10sec
  124.   s7 = map(Reading_ps, 0, 0.025, 0, 10);
  125.   Reading_Headup = analogRead(DELAY_Headup);
  126.   Reading_Headdown = analogRead(DELAY_Headdown);
  127.   Reading_Holder = analogRead(DELAY_Holder);
  128.   Reading_Rej = analogRead(DELAY_Rej);
  129.   Reading_vblowon = analogRead(DELAY_vblowon);
  130.   Reading_vblowoff = analogRead(DELAY_vblowoff);
  131.   Reading_ps = analogRead(Ps);
  132.   Serial.println("HEAD UP DELAY");
  133.   Serial.println(s1);
  134.   delay(10);
  135.   if (state_GB == HIGH && state_prox == HIGH) {
  136.     Serial.println("REC_GOOD_MODE");
  137.     digitalWrite(Pass_LED, HIGH);
  138.     digitalWrite(Rec_LED, HIGH);
  139.     delay(Reading_Headdown);
  140.     digitalWrite(Belt_break, HIGH);
  141.     digitalWrite(V_Head, HIGH);
  142.     delay(Reading_Headup);
  143.     delay(Reading_vblowon);
  144.     digitalWrite(V_Blow, HIGH);
  145.     delay(Reading_vblowoff);
  146.     digitalWrite(V_Blow, LOW);
  147.     delay(p);
  148.     //max function has been added lately new adjustment date 27.4.2022
  149.     digitalWrite(V_Head, LOW);
  150.     digitalWrite(Belt_break, LOW);
  151.   }
  152.     //MODE2 RECORDING REJ BOTTLE
  153.   if (state_RB == HIGH && state_prox == HIGH) {
  154.     Serial.print("REC_REJ_MODE");
  155.     digitalWrite(Fail_LED, HIGH);
  156.     digitalWrite(Rec_LED, HIGH);
  157.     delay(Reading_Headdown);
  158.     digitalWrite(Belt_break, HIGH);
  159.     digitalWrite(V_Head, HIGH);
  160.     delay(Reading_Headup);
  161.     delay(Reading_vblowon);
  162.     digitalWrite(V_Blow, HIGH);
  163.     delay(Reading_vblowoff);
  164.     digitalWrite(V_Blow, LOW);
  165.     //max function has been added lately new adjustment date 27.4.2022
  166.     delay(Reading_vblowoff);
  167.     digitalWrite(V_Head, LOW);
  168.     digitalWrite(Belt_break, LOW);
  169.     delay(Reading_Rej);
  170.     digitalWrite(V_Rej, HIGH);
  171.     delay(100);
  172.     digitalWrite(V_Rej, LOW);
  173.   }
  174.     //MODE3 TESTING
  175.   if (state_test_button == HIGH && state_prox == HIGH) {
  176.     Serial.println("testing");
  177.     delay(Reading_Headdown);
  178.     digitalWrite(Belt_break, HIGH);
  179.     digitalWrite(V_Head, HIGH);
  180.     delay(Reading_Headup);
  181.     delay(Reading_vblowon);
  182.     digitalWrite(V_Blow, HIGH);
  183.     //max function has been added lately new adjustment date 27.4.2022 hoping i doen't get the 3 values the same
  184.     normal_value == Reading_ps;
  185.     delay(Reading_vblowoff);
  186.     digitalWrite(V_Blow, LOW);
  187.     if (normal_value >= max_accept || max_rej < normal_value <= max_accept) {
  188.       digitalWrite(Pass_LED, HIGH);
  189.       digitalWrite(V_Head, LOW);
  190.       digitalWrite(Belt_break, LOW);
  191.     } else if (normal_value <= max_rej){
  192.       digitalWrite(Fail_LED, HIGH);
  193.       digitalWrite(V_Head, LOW);
  194.       digitalWrite(Belt_break, LOW);
  195.       delay(Reading_Rej);
  196.       digitalWrite(V_Rej, HIGH);
  197.       delay(100);
  198.       digitalWrite(V_Rej, LOW);
  199.     }
  200.   }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement