Advertisement
Guest User

Untitled

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