Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Servo.h>
- #include "HX711.h"
- #define DOUT 3
- #define CLK 2
- float scaless;
- HX711 scale(DOUT, CLK);
- LiquidCrystal_I2C lcd(0x3F);
- float calibration_factor = 128950;
- Servo rightServo;
- Servo leftServo;
- int pulsePin = 5;
- int dirPin = 6;
- int enblPin = 7;
- int ikot = 0;
- int startButton = 8;
- int stopButton = 9;
- int stateStart = 0;
- int stateStop = 0;
- int threshStart = 0;
- int threshStop = 0;
- int lastThreshStart = 0;
- int lastThreshStop = 0;
- int startt = 0;
- int stopp = 0;
- int resett = 0;
- int upSwitch = 31;
- int downSwitch = 33;
- int bottle300H;
- int bottle500H;
- int bottle1000H;
- int bottle1500H;
- int bottle300S;
- int bottle500S;
- int bottle1000S;
- int bottle1500S;
- int threshBottle300H;
- int threshBottle500H;
- int threshBottle1000H;
- int threshBottle1500H;
- int threshBottle300S;
- int threshBottle500S;
- int threshBottle1000S;
- int threshBottle1500S;
- int ctr = 0;
- int lastThresh1 = 0;
- int lastThresh2 = 0;
- int lastThresh3 = 0;
- int lastThresh4 = 0;
- int lastThresh5 = 0;
- int lastThresh6 = 0;
- int lastThresh7 = 0;
- int lastThresh8 = 0;
- float perKilo = 12;
- float maxLimit = 2;
- float totalPhp = 0;
- float percErr = 0;
- float totalError = 0;
- float percErr1 = 0;
- void setup()
- {
- rightServo.attach(11);
- leftServo.attach(12);
- pinMode(startButton, INPUT);
- pinMode(stopButton, INPUT);
- Serial.begin(9600);
- lcd.begin(16, 2);
- lcd.backlight();
- lcd.setCursor(1, 0);
- lcd.print("WELCOME TO");
- Serial.println("Welcome to Ejunkshop");
- lcd.setCursor(0, 1);
- lcd.println("E-JUNKSHOP");
- scale.set_scale();
- scale.tare();
- }
- void loop()
- {
- stateStart = digitalRead(startButton);
- stateStop = digitalRead(stopButton);
- if (stateStart != lastThreshStart) {
- startt = startt + 1;
- lcd.clear();
- lcd.setCursor(1, 0);
- lcd.print("PLEASE INSERT");
- Serial.println("Please Insert");
- }
- if (start == 1) {
- bottleSensor();
- if (threshBottle300H != lastThresh1 || threshBottle500H != lastThresh2 || threshBottle1000H != lastThresh3 || threshBottle1500H != lastThresh4 || threshBottle300S != lastThresh5 || threshBottle500S != lastThresh6 || threshBottle1000S != lastThresh7 || threshBottle1500S != lastThresh7) {
- if (threshBottle300H == 1 || threshBottle500H == 1 || threshBottle1000H == 1 || threshBottle1500H == 1 || threshBottle300S == 1 || threshBottle500S == 1 || threshBottle1000S == 1 || threshBottle1500S == 1 )
- {
- ctr = ctr + 1;
- lcd.setCursor(1, 0);
- lcd.print("Bottle Count: ");
- Serial.print("Bottle Count: ");
- Serial.println(ctr);
- lcd.print(ctr);
- lcd.setCursor(0, 1);
- lcd.print("Kilo: ");
- lcd.print(scaless);
- lcd.print("Php: ");
- lcd.print(totalPhp);
- delay(5);
- Serial.print("counter : ");
- Serial.println(ctr);
- Serial.println((scaless * -1), 4);
- totalPhp = scaless * perKilo;
- percErr = (scaless * ctr) * 0.20;
- percErr1 = percErr + scaless;
- if (scaless >= maxLimit ) {
- lcd.clear();
- lcd.setCursor(1, 0);
- lcd.print("Overload");
- Serial.println("OVERLOAD NIGGA");
- }
- if (scaless >= percErr1) {
- Serial.print(percErr1);
- }
- }
- }
- }
- lastThresh1 = threshBottle300H;
- lastThresh2 = threshBottle500H;
- lastThresh3 = threshBottle1000H;
- lastThresh4 = threshBottle1500H;
- lastThresh5 = threshBottle300S;
- lastThresh6 = threshBottle500S;
- lastThresh7 = threshBottle1000S;
- lastThresh8 = threshBottle1500S;
- stateStart = lastThreshStart;
- lastThreshStop = threshStop;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement