Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Smart Dustbin"
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-01-28 02:45:57
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* two ultrasonic sensors for a smart dustbin process */
- /* the sensor data one ultrasonic sensor connect with */
- /* servo motor and one ultrasonic sensor check the */
- /* dustbin is full and connet esp module */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <Ultrasonic.h>
- #include <Servo.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Ultra_HC_SR04_Echo_PIN_D3 = 3;
- const uint8_t Ultra_2_HC_SR04_Echo_PIN_D6 = 6;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Ultra_HC_SR04_Trigger_PIN_D2 = 2;
- const uint8_t Ultra_2_HC_SR04_Trigger_PIN_D4 = 4;
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t servo_Servomotor_PWMSignal_PIN_D5 = 5;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Ultrasonic ultrasonic1(Ultra_HC_SR04_Trigger_PIN_D2, Ultra_HC_SR04_Echo_PIN_D3);
- Ultrasonic ultrasonic2(Ultra_2_HC_SR04_Trigger_PIN_D4, Ultra_2_HC_SR04_Echo_PIN_D6);
- Servo servo1;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Ultra_HC_SR04_Echo_PIN_D3, INPUT);
- pinMode(Ultra_2_HC_SR04_Echo_PIN_D6, INPUT);
- pinMode(Ultra_HC_SR04_Trigger_PIN_D2, OUTPUT);
- pinMode(Ultra_2_HC_SR04_Trigger_PIN_D4, OUTPUT);
- pinMode(servo_Servomotor_PWMSignal_PIN_D5, OUTPUT);
- servo1.attach(servo_Servomotor_PWMSignal_PIN_D5);
- // Additional setup code for the ESP module connection
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // Check if the dustbin is full using ultrasonic2
- unsigned int distance = ultrasonic2.read();
- if (distance < 10) {
- // Dustbin is full, trigger servo motor to open the lid
- servo1.write(90); // Set the servo to 90 degrees (open position)
- delay(2000); // Wait for 2 seconds
- servo1.write(0); // Set the servo to 0 degrees (closed position)
- }
- // Additional code for the smart dustbin process using ultrasonic1
- delay(1000); // Delay for 1 second before repeating the loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement