Last active
September 6, 2021 17:45
-
-
Save arn-ob/260b58002f4e7f24a8ab4e397abcb161 to your computer and use it in GitHub Desktop.
Shaibal Final Project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Servo.h> | |
| #include "HX711.h" | |
| #include <LiquidCrystal.h> | |
| // initialize the library by associating any needed LCD interface pin | |
| // with the arduino pin number it is connected to | |
| const int rs = 32, en = 30, d4 = 28, d5 = 26, d6 = 24, d7 = 22; | |
| LiquidCrystal lcd(rs, en, d4, d5, d6, d7); | |
| // Weight | |
| // HX711.DOUT - pin #5 | |
| // HX711.PD_SCK - pin #6 | |
| HX711 scale(5, 6); | |
| float units; | |
| float ounces; | |
| float weight_value = 0.00; | |
| boolean second_check = false; | |
| // Servo property | |
| Servo myservo; | |
| int pos = 0; | |
| int posStart = 0; | |
| int posStop = 167; | |
| int servoPin = 9; | |
| // Coin Servo | |
| Servo myservoCoin; | |
| int Cpos = 0; | |
| int CposStart = 0; | |
| int CposStop = 95; | |
| int CservoPin = 8; | |
| // metal | |
| int metal = 3; | |
| // buzzer | |
| int buzzer = 11; | |
| // pin for esp | |
| int smallesp = 53; | |
| int bigesp = 52; | |
| void setup() { | |
| Serial.begin(9600); | |
| lcd_display(0, 2, "System INI"); | |
| // Servo | |
| myservo.attach(servoPin); | |
| myservoCoin.attach(CservoPin); | |
| // pin Define | |
| pinMode(metal, INPUT); | |
| pinMode(buzzer, OUTPUT); | |
| // esp | |
| pinMode(smallesp, OUTPUT); | |
| pinMode(bigesp, OUTPUT); | |
| // Weight | |
| scale.set_scale(); | |
| scale.tare(); | |
| long zero_factor = scale.read_average(); | |
| lcd.begin(20, 4); | |
| servo_close(posStart, posStop, 1); | |
| weight_align(); | |
| } | |
| void loop() { | |
| bool met = digitalRead(metal); | |
| delay(500); | |
| if(met) | |
| { | |
| Serial.println("Matel Detected"); | |
| digitalWrite(buzzer, HIGH); | |
| delay(100); | |
| digitalWrite(buzzer, LOW); | |
| delay(200); | |
| metal_view(); | |
| delay(50); | |
| } | |
| else | |
| { | |
| // fix the value | |
| weight_align(); | |
| // store the weight value | |
| get_weight(); | |
| // check small bottol | |
| small(); | |
| // check big bottol | |
| big(); | |
| if(108.00 < weight_value){ | |
| Serial.println("Over Weight"); | |
| digitalWrite(buzzer, HIGH); | |
| delay(100); | |
| digitalWrite(buzzer, LOW); | |
| delay(200); | |
| overweight_view(); | |
| delay(50); | |
| } else { | |
| // Display View | |
| main_view(); | |
| } | |
| } | |
| } | |
| // =================== Weight ========================= | |
| // Weight | |
| float weight() | |
| { | |
| scale.set_scale(2560); //Adjust to this calibration factor | |
| units = scale.get_units(), 10; | |
| if (units < 0) | |
| { | |
| units = 0.00; | |
| } | |
| ounces = units * 0.335274; | |
| delay(200); | |
| return ounces + 100; | |
| } | |
| void weight_align() { | |
| weight(); | |
| weight(); | |
| weight(); | |
| weight(); | |
| weight(); | |
| } | |
| void get_weight() { | |
| weight_value = weight(); | |
| // lcd_display(0, 1, String(weight_value - 100)); | |
| Serial.println(weight_value); | |
| } | |
| // =================== END Weight ========================= | |
| // =================== Botol ========================= | |
| // Small Bottol Sence | |
| void small() { | |
| // small | |
| if (105.00 < weight_value) | |
| { | |
| Serial.println("Min"); | |
| if (weight_value < 106.00) { | |
| receiveBuz(); // receive bip | |
| small_view(); | |
| Serial.println("Max"); | |
| Serial.println("Giving Small"); | |
| // Big Servo Move | |
| servo_open(posStart, posStop, 1); | |
| delay(2000); | |
| servo_close(posStart, posStop, 1); | |
| delay(500); | |
| if (second_check) { | |
| small_Sec_view(); | |
| // coin give | |
| digitalWrite(smallesp, HIGH); | |
| servo_open(CposStart, CposStop, 2); | |
| delay(2000); | |
| servo_close(CposStart, CposStop, 2); | |
| digitalWrite(smallesp, LOW); | |
| delay(2000); | |
| // check again | |
| } | |
| if (!second_check) { | |
| check_small_again(); | |
| } | |
| second_check = false; | |
| } | |
| else | |
| { | |
| if (second_check) { | |
| second_check = false; | |
| small_No_Sec_view(); | |
| } | |
| } | |
| } | |
| else | |
| { | |
| if (second_check) { | |
| second_check = false; | |
| Serial.println("Thank you"); | |
| small_No_Sec_view(); | |
| delay(1000); | |
| } | |
| } | |
| } | |
| void check_small_again() { | |
| second_check = true; | |
| delay(3000); | |
| weight_align(); | |
| get_weight(); | |
| small(); | |
| } | |
| void big() { | |
| if (106.00 < weight_value) | |
| { | |
| Serial.println("Min"); | |
| if (weight_value < 107.00) { | |
| Serial.println("Max"); | |
| Serial.println("Giving Big"); | |
| receiveBuz(); // receive bip | |
| digitalWrite(bigesp, HIGH); | |
| big_view(); | |
| // Big Servo Move | |
| servo_open(posStart, posStop, 1); | |
| delay(2000); | |
| servo_close(posStart, posStop, 1); | |
| delay(500); | |
| // coin give | |
| servo_open(CposStart, CposStop, 2); | |
| delay(1000); | |
| servo_close(CposStart, CposStop, 2); | |
| delay(2000); | |
| // check again | |
| digitalWrite(bigesp, LOW); | |
| } | |
| } | |
| } | |
| // =================== END Botol ========================= | |
| // =================== Servo Function ========================= | |
| // Servo Function | |
| void servo_close(int Pstart, int Pstop, int i) { | |
| Serial.println("Servo Close"); | |
| for (int p = Pstart; p <= Pstop; p += 1) { | |
| if (i == 1) { | |
| myservo.write(p); | |
| } | |
| if (i == 2) { | |
| myservoCoin.write(p); | |
| } | |
| } | |
| } | |
| void servo_open(int Pstart, int Pstop, int i) { | |
| Serial.println("Servo Open"); | |
| for (int p = Pstop; p >= Pstart; p -= 1) { | |
| if (i == 1) { | |
| myservo.write(p); | |
| } | |
| if (i == 2) { | |
| myservoCoin.write(p); | |
| } | |
| } | |
| } | |
| // =================== END Servo Function ========================= | |
| void receiveBuz(){ | |
| digitalWrite(buzzer, HIGH); | |
| delay(300); | |
| digitalWrite(buzzer, LOW); | |
| } | |
| void lcd_display(int row, int col, String msg) { | |
| lcd.setCursor(row, col); | |
| lcd.print(msg); | |
| } | |
| void main_view() { | |
| lcd.clear(); | |
| lcd_display(0, 0, "Put Your Bottle Here"); | |
| lcd_display(3, 1, "Plastic Bottle"); | |
| lcd_display(0, 2, "1 Large :1 Tk "); | |
| lcd_display(0, 3, "2 Small :1 Tk "); | |
| } | |
| void big_view() { | |
| lcd.clear(); | |
| lcd_display(0, 0, "Put Your Bottle Here"); | |
| lcd_display(0, 1, "Size :1 Large"); | |
| lcd_display(0, 2, "Taka :1 Tk"); | |
| lcd_display(5, 3, "Thank you"); | |
| } | |
| void small_view() { | |
| lcd.clear(); | |
| lcd_display(0, 0, "Put Your Bottle Here"); | |
| lcd_display(0, 1, "Size :1 Small"); | |
| lcd_display(0, 2, "Taka :0 Tk"); | |
| lcd_display(3, 3, "Refill in 3 Sec"); | |
| } | |
| void small_Sec_view() { | |
| lcd.clear(); | |
| lcd_display(0, 0, "Put Your Bottle Here"); | |
| lcd_display(0, 1, "Size :2 Small"); | |
| lcd_display(0, 2, "Taka :1 Tk"); | |
| lcd_display(5, 3, "Thank you"); | |
| } | |
| void small_No_Sec_view() { | |
| lcd.clear(); | |
| lcd_display(0, 0, "Put Your Bottle Here"); | |
| lcd_display(0, 1, "Size :1 Small"); | |
| lcd_display(0, 2, "Taka :0 Tk"); | |
| lcd_display(5, 3, "Thank you"); | |
| } | |
| void overweight_view() { | |
| lcd.clear(); | |
| lcd_display(0, 0, "Put Your Bottle Here"); | |
| lcd_display(3, 1, "Plastic Bottle"); | |
| lcd_display(0, 2, "Not Accepted"); | |
| lcd_display(0, 3, "Over Weight"); | |
| } | |
| void metal_view() { | |
| lcd.clear(); | |
| lcd_display(0, 0, "Put Your Bottle Here"); | |
| lcd_display(3, 1, "Plastic Bottle"); | |
| lcd_display(0, 2, "Not Accepted"); | |
| lcd_display(0, 3, "Metal Detected"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment