Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Servo.h>
  4. #include "HX711.h"
  5. #define DOUT 3
  6. #define CLK 2
  7. float scaless;
  8. HX711 scale(DOUT, CLK);
  9. LiquidCrystal_I2C lcd(0x3F);
  10. float calibration_factor = 128950;
  11. Servo rightServo;
  12. Servo leftServo;
  13.  
  14.  
  15. int pulsePin = 5;
  16. int dirPin = 6;
  17. int enblPin = 7;
  18. int ikot = 0;
  19.  
  20. int startButton = 8;
  21. int stopButton = 9;
  22.  
  23. int stateStart = 0;
  24. int stateStop = 0;
  25.  
  26. int threshStart = 0;
  27. int threshStop = 0;
  28.  
  29. int lastThreshStart = 0;
  30. int lastThreshStop = 0;
  31.  
  32. int startt = 0;
  33. int stopp = 0;
  34. int resett = 0;
  35.  
  36. int upSwitch = 31;
  37. int downSwitch = 33;
  38.  
  39. int bottle300H;
  40. int bottle500H;
  41. int bottle1000H;
  42. int bottle1500H;
  43. int bottle300S;
  44. int bottle500S;
  45. int bottle1000S;
  46. int bottle1500S;
  47.  
  48. int threshBottle300H;
  49. int threshBottle500H;
  50. int threshBottle1000H;
  51. int threshBottle1500H;
  52. int threshBottle300S;
  53. int threshBottle500S;
  54. int threshBottle1000S;
  55. int threshBottle1500S;
  56.  
  57. int ctr = 0;
  58. int lastThresh1 = 0;
  59. int lastThresh2 = 0;
  60. int lastThresh3 = 0;
  61. int lastThresh4 = 0;
  62. int lastThresh5 = 0;
  63. int lastThresh6 = 0;
  64. int lastThresh7 = 0;
  65. int lastThresh8 = 0;
  66. float perKilo = 12;
  67. float maxLimit = 2;
  68. float totalPhp = 0;
  69. float percErr = 0;
  70. float totalError = 0;
  71. float percErr1 = 0;
  72.  
  73. void setup()
  74. {
  75. rightServo.attach(11);
  76. leftServo.attach(12);
  77. pinMode(startButton, INPUT);
  78. pinMode(stopButton, INPUT);
  79. Serial.begin(9600);
  80. lcd.begin(16, 2);
  81. lcd.backlight();
  82. lcd.setCursor(1, 0);
  83. lcd.print("WELCOME TO");
  84. Serial.println("Welcome to Ejunkshop");
  85. lcd.setCursor(0, 1);
  86. lcd.println("E-JUNKSHOP");
  87. scale.set_scale();
  88. scale.tare();
  89. }
  90.  
  91. void loop()
  92. {
  93.  
  94. stateStart = digitalRead(startButton);
  95. stateStop = digitalRead(stopButton);
  96.  
  97. if (stateStart != lastThreshStart) {
  98. startt = startt + 1;
  99. lcd.clear();
  100. lcd.setCursor(1, 0);
  101. lcd.print("PLEASE INSERT");
  102. Serial.println("Please Insert");
  103. }
  104. if (start == 1) {
  105. bottleSensor();
  106. if (threshBottle300H != lastThresh1 || threshBottle500H != lastThresh2 || threshBottle1000H != lastThresh3 || threshBottle1500H != lastThresh4 || threshBottle300S != lastThresh5 || threshBottle500S != lastThresh6 || threshBottle1000S != lastThresh7 || threshBottle1500S != lastThresh7) {
  107. if (threshBottle300H == 1 || threshBottle500H == 1 || threshBottle1000H == 1 || threshBottle1500H == 1 || threshBottle300S == 1 || threshBottle500S == 1 || threshBottle1000S == 1 || threshBottle1500S == 1 )
  108. {
  109. ctr = ctr + 1;
  110. lcd.setCursor(1, 0);
  111. lcd.print("Bottle Count: ");
  112. Serial.print("Bottle Count: ");
  113. Serial.println(ctr);
  114. lcd.print(ctr);
  115. lcd.setCursor(0, 1);
  116. lcd.print("Kilo: ");
  117. lcd.print(scaless);
  118. lcd.print("Php: ");
  119. lcd.print(totalPhp);
  120. delay(5);
  121. Serial.print("counter : ");
  122. Serial.println(ctr);
  123. Serial.println((scaless * -1), 4);
  124. totalPhp = scaless * perKilo;
  125. percErr = (scaless * ctr) * 0.20;
  126. percErr1 = percErr + scaless;
  127. if (scaless >= maxLimit ) {
  128. lcd.clear();
  129. lcd.setCursor(1, 0);
  130. lcd.print("Overload");
  131. Serial.println("OVERLOAD NIGGA");
  132. }
  133. if (scaless >= percErr1) {
  134. Serial.print(percErr1);
  135. }
  136. }
  137. }
  138. }
  139.  
  140. lastThresh1 = threshBottle300H;
  141. lastThresh2 = threshBottle500H;
  142. lastThresh3 = threshBottle1000H;
  143. lastThresh4 = threshBottle1500H;
  144. lastThresh5 = threshBottle300S;
  145. lastThresh6 = threshBottle500S;
  146. lastThresh7 = threshBottle1000S;
  147. lastThresh8 = threshBottle1500S;
  148. stateStart = lastThreshStart;
  149. lastThreshStop = threshStop;
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement