Last active
August 2, 2021 10:12
-
-
Save arn-ob/52a5885d6cf80c74c8c16c031b056309 to your computer and use it in GitHub Desktop.
Shaibal Final Project [Plastic Bottle Recycling]
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; | |
| void setup() { | |
| Serial.begin(9600); | |
| // Servo | |
| myservo.attach(servoPin); | |
| myservoCoin.attach(CservoPin); | |
| // 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() { | |
| // 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("in"); | |
| overweight_view(); | |
| delay(1500); | |
| } | |
| // 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) { | |
| 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 | |
| servo_open(CposStart, CposStop, 2); | |
| delay(2000); | |
| servo_close(CposStart, CposStop, 2); | |
| 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"); | |
| 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 | |
| } | |
| } | |
| } | |
| // =================== 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 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"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment