Advertisement
pleasedontcode

"Smart Dustbin" rev_01

Jan 27th, 2024
112
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: "Smart Dustbin"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-28 02:45:57
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* two ultrasonic sensors for a smart dustbin process */
  21.     /* the sensor data one ultrasonic sensor connect with */
  22.     /* servo motor and one ultrasonic sensor check the */
  23.     /* dustbin is full and connet esp module */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Arduino.h>
  28. #include <Ultrasonic.h>
  29. #include <Servo.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t Ultra_HC_SR04_Echo_PIN_D3 = 3;
  37. const uint8_t Ultra_2_HC_SR04_Echo_PIN_D6 = 6;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t Ultra_HC_SR04_Trigger_PIN_D2 = 2;
  41. const uint8_t Ultra_2_HC_SR04_Trigger_PIN_D4 = 4;
  42.  
  43. /***** DEFINITION OF PWM OUTPUT PINS *****/
  44. const uint8_t servo_Servomotor_PWMSignal_PIN_D5 = 5;
  45.  
  46. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  47. Ultrasonic ultrasonic1(Ultra_HC_SR04_Trigger_PIN_D2, Ultra_HC_SR04_Echo_PIN_D3);
  48. Ultrasonic ultrasonic2(Ultra_2_HC_SR04_Trigger_PIN_D4, Ultra_2_HC_SR04_Echo_PIN_D6);
  49. Servo servo1;
  50.  
  51. void setup(void)
  52. {
  53.   // put your setup code here, to run once:
  54.   pinMode(Ultra_HC_SR04_Echo_PIN_D3, INPUT);
  55.   pinMode(Ultra_2_HC_SR04_Echo_PIN_D6, INPUT);
  56.  
  57.   pinMode(Ultra_HC_SR04_Trigger_PIN_D2, OUTPUT);
  58.   pinMode(Ultra_2_HC_SR04_Trigger_PIN_D4, OUTPUT);
  59.   pinMode(servo_Servomotor_PWMSignal_PIN_D5, OUTPUT);
  60.  
  61.   servo1.attach(servo_Servomotor_PWMSignal_PIN_D5);
  62.  
  63.   // Additional setup code for the ESP module connection
  64. }
  65.  
  66. void loop(void)
  67. {
  68.   // put your main code here, to run repeatedly:
  69.  
  70.   // Check if the dustbin is full using ultrasonic2
  71.   unsigned int distance = ultrasonic2.read();
  72.   if (distance < 10) {
  73.     // Dustbin is full, trigger servo motor to open the lid
  74.     servo1.write(90); // Set the servo to 90 degrees (open position)
  75.     delay(2000); // Wait for 2 seconds
  76.     servo1.write(0); // Set the servo to 0 degrees (closed position)
  77.   }
  78.  
  79.   // Additional code for the smart dustbin process using ultrasonic1
  80.  
  81.   delay(1000); // Delay for 1 second before repeating the loop
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement