pleasedontcode

Waste Management rev_01

Nov 6th, 2025
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Waste Management
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-11-06 13:18:22
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* This Smart Waste Segregation Bin uses an Arduino */
  21.     /* Uno, IR sensor, ultrasonic sensors,servo motors */
  22.     /* and detacts waste based on relection */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25.  
  26. /* START CODE */
  27.  
  28. // System Requirements: Control waste sorting system using IR sensor and ultrasonic sensors with servo motors
  29.  
  30. #include <Servo.h>  // Include servo library for controlling servo motors
  31.  
  32. // Define PWM output pin for servo
  33. const uint8_t kie_Servomotor_PWMSignal_PIN_D3 = 3;
  34.  
  35. // Define pins for IR sensor and ultrasonic sensors
  36. #define IR_SENSOR A0
  37. #define SERVO_1 3
  38. #define SERVO_2 5
  39. #define SERVO_3 6
  40.  
  41. #define ORGANIC_TRIG 8
  42. #define ORGANIC_ECHO 9
  43. #define RECYCLABLE_TRIG 10
  44. #define RECYCLABLE_ECHO 11
  45. #define OTHER_TRIG 12
  46. #define OTHER_ECHO 13
  47.  
  48. // Create servo objects
  49. Servo servo1;
  50. Servo servo2;
  51. Servo servo3;
  52.  
  53. // Variables to hold ultrasonic sensor readings
  54. int organicDistance;
  55. int recyclableDistance;
  56. int otherDistance;
  57.  
  58. // Threshold distance to determine if bin is full (in cm)
  59. int threshold = 5;
  60.  
  61. void setup() {
  62.   Serial.begin(9600); // Initialize serial communication
  63.  
  64.   // Attach servo objects to PWM pins
  65.   servo1.attach(SERVO_1);
  66.   servo2.attach(SERVO_2);
  67.   servo3.attach(SERVO_3);
  68.  
  69.   // Initialize ultrasonic sensor pins
  70.   pinMode(ORGANIC_TRIG, OUTPUT);
  71.   pinMode(ORGANIC_ECHO, INPUT);
  72.   pinMode(RECYCLABLE_TRIG, OUTPUT);
  73.   pinMode(RECYCLABLE_ECHO, INPUT);
  74.   pinMode(OTHER_TRIG, OUTPUT);
  75.   pinMode(OTHER_ECHO, INPUT);
  76. }
  77.  
  78. void loop() {
  79.   // Read IR sensor value
  80.   int reflectivity = analogRead(IR_SENSOR);
  81.  
  82.   // Determine waste category based on reflectivity
  83.   String wasteCategory;
  84.   if (reflectivity > 800) {
  85.     wasteCategory = "Organic";
  86.   } else if (reflectivity > 400) {
  87.     wasteCategory = "Recyclable";
  88.   } else {
  89.     wasteCategory = "Other";
  90.   }
  91.  
  92.   // Print waste category
  93.   Serial.print("Waste Category: ");
  94.   Serial.println(wasteCategory);
  95.  
  96.   // Process waste based on category
  97.   if (wasteCategory == "Organic") {
  98.     organicDistance = getDistance(ORGANIC_TRIG, ORGANIC_ECHO);
  99.     if (organicDistance > threshold) {
  100.       servo1.write(90); // Open lid
  101.       delay(2000); // Wait
  102.       servo1.write(0); // Close lid
  103.     } else {
  104.       Serial.println("Bin Full");
  105.     }
  106.   } else if (wasteCategory == "Recyclable") {
  107.     recyclableDistance = getDistance(RECYCLABLE_TRIG, RECYCLABLE_ECHO);
  108.     if (recyclableDistance > threshold) {
  109.       servo2.write(90);
  110.       delay(2000);
  111.       servo2.write(0);
  112.     } else {
  113.       Serial.println("Bin Full");
  114.     }
  115.   } else {
  116.     otherDistance = getDistance(OTHER_TRIG, OTHER_ECHO);
  117.     if (otherDistance > threshold) {
  118.       servo3.write(90);
  119.       delay(2000);
  120.       servo3.write(0);
  121.     } else {
  122.       Serial.println("Bin Full");
  123.     }
  124.   }
  125.   delay(100); // Small delay
  126. }
  127.  
  128. // Function to get distance from ultrasonic sensor
  129. int getDistance(int trigPin, int echoPin) {
  130.   digitalWrite(trigPin, LOW);
  131.   delayMicroseconds(2);
  132.   digitalWrite(trigPin, HIGH);
  133.   delayMicroseconds(10);
  134.   digitalWrite(trigPin, LOW);
  135.   long duration = pulseIn(echoPin, HIGH);
  136.   int distance = duration * 0.034 / 2;
  137.   return distance;
  138. }
  139.  
  140. /* END CODE */
  141.  
Advertisement
Add Comment
Please, Sign In to add comment