Optimus Prime Smart Trash Can Bin

How to Create an Optimus Prime Smart Trash Bin

Creating a smart trash bin that opens and closes automatically and plays an audio clip of Optimus Prime is a fun and practical project. This tutorial will guide you through the steps to build your own smart trash bin using an Arduino, a servo motor, an ultrasonic sensor, and a DFPlayer Mini MP3 player.

Materials Needed:

  1. Arduino Uno
  2. Servo motor (SG90 or similar)
  3. Ultrasonic sensor (HC-SR04)
  4. DFPlayer Mini MP3 player
  5. Speaker
  6. Jumper wires
  7. Breadboard
  8. External power supply (if necessary)
  9. Trash bin (to mount the components)

Circuit Diagram:

  1. Ultrasonic Sensor:
  • Trig pin to Arduino pin 8
  • Echo pin to Arduino pin 9
  • VCC to 5V
  • GND to GND
  1. Servo Motor:
  • Signal pin to Arduino pin 3
  • VCC to 5V
  • GND to GND
  1. DFPlayer Mini:
  • RX to Arduino pin 11
  • TX to Arduino pin 10
  • VCC to 5V
  • GND to GND
  • Speaker connected to the speaker pins on the DFPlayer Mini

Step-by-Step Instructions:

  1. Setup Arduino IDE:
  • Install the necessary libraries: Servo and DFRobotDFPlayerMini.
    bash Sketch -> Include Library -> Manage Libraries...
  • Search for and install the DFRobotDFPlayerMini and Servo libraries.
  1. Upload the Code:
   #include <Servo.h>
   #include <SoftwareSerial.h>
   #include <DFRobotDFPlayerMini.h>

   // Pin definisi
   const int trigPin = 8;
   const int echoPin = 9;
   const int servoPin = 3;

   // Servo instance
   Servo myservo;

   // SoftwareSerial untuk DFPlayer Mini
   SoftwareSerial mySerial(11, 10); // RX, TX

   // DFPlayer Mini instance
   DFRobotDFPlayerMini myDFPlayer;

   // Variabel lainnya
   long duration;
   int distance;
   int servoOpenAngle = 180;
   int servoCloseAngle = 0;

   void setup() {
     // Inisialisasi pin
     pinMode(trigPin, OUTPUT);
     pinMode(echoPin, INPUT);

     // Inisialisasi servo
     myservo.attach(servoPin);
     myservo.write(servoCloseAngle); // Servo pada posisi tertutup

     // Inisialisasi komunikasi serial
     Serial.begin(9600);
     mySerial.begin(9600);

     // Inisialisasi DFPlayer Mini
     if (!myDFPlayer.begin(mySerial)) {
       Serial.println(F("DFPlayer Mini tidak terdeteksi!"));
       while(true);
     }
     Serial.println(F("DFPlayer Mini siap."));
     myDFPlayer.volume(30); // Set volume, bisa disesuaikan 0-30
   }

   void loop() {
     // Mengukur jarak
     digitalWrite(trigPin, LOW);
     delayMicroseconds(2);
     digitalWrite(trigPin, HIGH);
     delayMicroseconds(10);
     digitalWrite(trigPin, LOW);

     duration = pulseIn(echoPin, HIGH);
     distance = duration * 0.034 / 2; // Menghitung jarak

     // Debugging, print jarak ke Serial Monitor
     Serial.print("Distance: ");
     Serial.print(distance);
     Serial.println(" cm");

     // Jika jarak kurang atau sama dengan 50cm, buka tutup tempat sampah
     if (distance <= 50) {
       myservo.write(servoOpenAngle);
       Serial.println("Tutup terbuka");
       delay(5000); // Tahan posisi terbuka selama 5 detik

       // Putar audio
       myDFPlayer.play(1); // Putar audio, file pertama
       Serial.println("Memutar audio...");
       delay(3000); // Menunggu audio selesai diputar (3 detik, sesuaikan dengan durasi audio)

       // Tutup tutup tempat sampah
       myservo.write(servoCloseAngle);
       Serial.println("Tutup tertutup");
     }

     delay(500); // Penundaan sebelum pengukuran berikutnya
   }
  1. Prepare the Audio File:
  • Download or create an Optimus Prime audio clip.
  • Save it as 0001.mp3 on a microSD card.
  • Insert the microSD card into the DFPlayer Mini.
  1. Assembly:
  • Mount the components on the breadboard.
  • Connect the servo motor to the lid of the trash bin.
  • Ensure the ultrasonic sensor is positioned to detect approaching objects.
  1. Power Up and Test:
  • Connect the Arduino to a power source.
  • Upload the code.
  • Test the setup by approaching the ultrasonic sensor and watching the servo open the lid and play the audio.

Conclusion:

Congratulations! You have successfully built a smart trash bin that opens automatically and plays an Optimus Prime audio clip. This project not only enhances the functionality of a regular trash bin but also adds a touch of fun with the audio feature. Enjoy your new smart trash bin!

Leave a Reply

Your email address will not be published. Required fields are marked *

Ghazza