Introduction: OpenTrashCan: a Smart Internet Connected Trash Can That Talks

About: My name is Matthew and I attend the University of Pittsburgh. Currently I am a senior, going for a bachelors in Information Science with a minor in CS. Current interests include augmented reality, virtual real…

OpenTrashCan connects to your wifi network and sends you an email when its full, talks to you, and can even be controlled from the OpenTrashCan App for Android phones. See it in action here:

Want to buy one? Sign up for the preorder list here: OpenTrashCan

This project started out serious, then I kept thinking of funny things I wanted to make it do. The only way I could think to present it was a corny infomercial style video. Open Trash Can uses the Arduino Leonardo micro-controller. The trash can uses one range sensor in the front that opens the lid when it detects motion. There is a second range sensor in the back that detects the fill level of the trash can. Speech is played using an mp3 shield, through computer speakers. Emails are sent using a wifi shield shied and Temboo.

You need:

A cheap trash can (this one is from Target)

Computer Speakers

An Arduino Leonardo

An Iduino Yun Shield

An Elechouse MP3 Shield

Googly Eyes (don't skimp on these, get the good ones)

A 4GB SD Card

A Micro Servo Motor

2 HC-Sr04 Range Sensors

Some Jumper Wires

A Hot Glue Gun

A drill

Some wire cutters or heavy duty scissors

A Mini Breadboard

An HC-06 Bluetooth Module

A 9V battery or Wall Adapter (to power the Arduino board)

Step 1: Setup the Servo Motor

The lid moves up and down with a micro servo motor. The first step is to set the servo motor into the correct position before it is attached to the trash can. In this case we want to set it to 180 degrees.

Follow the connections in the first picture. Using male to male jumper wires connect the servo ground (black or purple) to the ground on the Arduino board, the power wire (red) to the 5v pin, and the control wire (yellow or orange) to pin 9 on the board.

Open up the Arduino IDE and upload this code to your Arduino board:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {

myservo.write(180);  // sets servo to 180 degree position

}

Step 2: Prepare the Lid

Now that your servo is set to 180 degrees you can unplug everything and we are going to attach it to the trash can lid.

We are aiming for the setup in the first picture.

In the second picture you can see a small nub/axle thing on the left side. You need to remove that small axle on the RIGHT side with either scissors or wire cutters.

Cut a small square in the area where the servo sits in the second and third picture, so that it can sit flat.

Make sure the orientation is the same as the pictures, and hot glue the servo into place.

Feed the servo horn through the hole in the lid and attach it to the servo as shown in the pictures.

Carefully attach the googly eyes EXACTLY as shown.

Step 3: Prepare the Body of the Trash Can

Using a hot glue gun, glue the computer speakers to the side of the can.

Trace the ultrasonic range sensor with a pen on the trash can, and drill out the two holes to fit the sensor.

Do the same on the backside to add the second range sensor (this one is for detecting the fill level).

Use the double sided tape on your mini breadboard to stick to the can.

Use two screws to attach the Arduino Leonardo.

**Ignore the two holes I put in the back side, originally I wanted to put the rear fill sensor there but did not anticipate the lid swinging in front of it. **

Step 4: Connect Your Can to Your Wifi Network.

Connect all 3 of your shields, and lets connect them to your wifi network.

If you are using a Yun board follow this link to get connected to your network:

Connect Arduino Yun to WIFI

For the Leonardo and Iduino shield follow these instructions:

Connect Arduino Leonardo and Wifi Shield

Step 5: Make the Connections.

Use the diagram above to make all the connections. You will need male to male and male to female wires to make long enough connections from the sensors to the board.

Tape the wires coming from the front sensor to the inside of the trash can to keep them out of the way (shown in the last picture).

Step 6: Load the SD Card.

To make this trash can talk we are using a method called speech store and forward. Simply put, speech snippets are store on an SD card in .mp3 format which are then played through the computer speakers.

Here I have attached the 3 speech snippets I used in the demo video. Load these onto your SD card and plug the SD card into the mp3 shield.

Step 7: Upload This Code to Your Boards

Now before we upload the Arduino sketch you need to sign up for a Temboo Account and get your credentials. Temboo is a service that makes using API's extremely quick and easy. This script makes calls to Temboo in order to send the email when the trash can is full.

Sign up for a Temboo Account and navigate to the "APPLICATIONS" section to get your

- Temboo account name

- App key name

- App key

Upload this code to your Arduino board:

//Trash Can
#include 
#include 
#include "TembooAccount.h"
#include 
#include 
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial portOne(10, 11);
SoftwareSerial Geno(7,8); // Rx , Tx

Servo trashServo;
int trigPin = 2;
int echoPin = 4;
long duration, cm, inches;

unsigned char Data[10];
unsigned char i;

int counter = 0;

int trigPin1 = 5;
int echoPin1 = 6;
long duration1, cm1, inches1;

void setup() {
  portOne.begin(9600);
  Serial.begin (9600);
  Serial.println("bridge opening...");
  Bridge.begin();
  Serial.println("bridge OPEN!!");
  Geno.begin(9600);
  SetVolume(25); 
       
  trashServo.attach(9);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
    pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  delay(5000);
  Serial.println("Initiate Smart Trash Can...");

}


void playTrack(int track){

  delay(1000); 
    Data[0] = 0x7E; 
    Data[1] = 0x04; 
    Data[2] = 0xA0; 
    Data[3] = 0x00;
    Data[4] = 0x00 + track; 
    Data[5] = 0x7E; 
   Command(Data,5);
  play_pause();
  delay(3000);
  
}

void playTrackFULL(int track){

  delay(1000); 
    Data[0] = 0x7E; 
    Data[1] = 0x04; 
    Data[2] = 0xA0; 
    Data[3] = 0x00;
    Data[4] = 0x00 + track; 
    Data[5] = 0x7E; 
   Command(Data,5);
  
    trashServo.write(160);       
    play_pause();
    delay(300);
    trashServo.write(180);
    delay(200);
    trashServo.write(160);
    delay(100);
    trashServo.write(180);
    delay(100);
    trashServo.write(160);
    delay(200);
    trashServo.write(180);
    delay(100);
    trashServo.write(160);
    delay(100);
    trashServo.write(180);
    delay(600);
    trashServo.write(160);
    delay(200);
    trashServo.write(180);
    delay(100);
    trashServo.write(160);
    delay(100);
    trashServo.write(180);
    delay(100);
    trashServo.write(160);
    delay(200);
    trashServo.write(180);
    delay(200);
    trashServo.write(160);
    delay(100);
    trashServo.write(180);
    delay(200);
    trashServo.write(160);
    delay(300);
    trashServo.write(180);
    delay(200);
    trashServo.write(160);
    delay(100);
    trashServo.write(180);
    delay(200);
    trashServo.write(160);
    delay(300);
    trashServo.write(180);
    delay(200);

}

void playTrackHEY(int track){

  delay(1000); 
    Data[0] = 0x7E; 
    Data[1] = 0x04; 
    Data[2] = 0xA0; 
    Data[3] = 0x00;
    Data[4] = 0x00 + track; 
    Data[5] = 0x7E; 
   Command(Data,5);
  
    trashServo.write(150);       
    play_pause();
    delay(400);
    trashServo.write(180);
    delay(300);
    trashServo.write(160);
    delay(100);
    trashServo.write(180);
    delay(100);
    trashServo.write(160);
    delay(200);
    trashServo.write(180);
    delay(200);
    trashServo.write(160);
    delay(400);
    trashServo.write(180);
    delay(400);
}


void playTrackHI(int track){

  delay(1000); 
    Data[0] = 0x7E; 
    Data[1] = 0x04; 
    Data[2] = 0xA0; 
    Data[3] = 0x00;
    Data[4] = 0x00 + track; 
    Data[5] = 0x7E; 
   Command(Data,5);
  
    trashServo.write(150);       
    play_pause();
    delay(400);
    trashServo.write(180);
    delay(300);
    trashServo.write(160);
    delay(100);
    trashServo.write(180);
    delay(100);
    trashServo.write(160);
    delay(200);
    trashServo.write(180);
    delay(200);
    trashServo.write(160);
    delay(100);
    trashServo.write(180);
    delay(300);
    trashServo.write(160);
    delay(400);
    trashServo.write(180);
}


void SetVolume( int vol){
   Data[0] = 0x7E;          // START
   Data[1] = 0x03;          // Length Not 0x02
   Data[2] = 0xA7;          // Command
   Data[3] = vol;          // new volume
   Data[4] = 0x7E;          // END
   Command(Data,5);
}

void Command(unsigned char *Data, int length){
    for(int i=0; i 1000) {
  trashServo.write(80); //Lid open
  delay(5000);
  }


  digitalWrite(trigPin1, LOW); //Inside Sensor
  delayMicroseconds(1);
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(2);
  digitalWrite(trigPin1, LOW);

  pinMode(echoPin1, INPUT);
  duration1 = pulseIn(echoPin1, HIGH);

  inches1 = (duration1 / 2) / 74;
  
  Serial.println(inches1); 
  
  if (inches1 < 3 && counter == 0) {
       counter ++;
       playTrackFULL(2);
       Serial.println("Sending Email...");
       TembooChoreo SendEmailChoreo;

    // Invoke the Temboo client
    SendEmailChoreo.begin();
  
    // Set Temboo account credentials
    SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
    SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);
    
    // Set profile to use for execution
    SendEmailChoreo.setProfile("EmailTest");
    
    // Identify the Choreo to run
    SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
    
    // Run the Choreo; when results are available, print them to serial
    SendEmailChoreo.run();
    
    while(SendEmailChoreo.available()) {
      char c = SendEmailChoreo.read();
      Serial.print(c);
    }
    SendEmailChoreo.close();
    Serial.println("Email Sent...");
  }                       



  //Serial.println(incoming);
  if (incoming == 111){    //Open Lid from App
  trashServo.write(80);
  delay(2000);
  }

   //Serial.println(incoming);
  if (incoming == 49){ 
  playTrackFULL(2);               //I have reached capacity 
  }

   //Serial.println(incoming);
  if (incoming == 50){ 
  playTrackHEY(1);                //hey get out of there
  }

   //Serial.println(incoming);
  if (incoming == 51){
      playTrackHI(3);            //Hi, I am open Trash Can
  }

  


}//ends loop

In the Arduino IDE click to add a new tab and create a header file called: TembooAccount.h Add this code to your header file and fill it in with your Temboo credentials.

//header file


/*
IMPORTANT NOTE about TembooAccount.h

TembooAccount.h contains your Temboo account information and must be included
alongside your sketch. To do so, make a new tab in Arduino, call it TembooAccount.h,
and copy this content into it. 
*/

#define TEMBOO_ACCOUNT "********"  // Your Temboo account name 
#define TEMBOO_APP_KEY_NAME "*******"  // Your Temboo app key name
#define TEMBOO_APP_KEY "******************************"  // Your Temboo app key

/* 
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.  
Keeping your account information in a separate file means you can share the 
main .ino file without worrying that you forgot to delete your credentials.
*/

Step 8: FINALLY!

Plug your computer speakers into the mp3 shield, power the Arduino board, and the speakers and you should be good to go.

The OpenTrashCan App for Android phones can be downloaded here:

http://wirebeings.com/open-trash-can.html

You may need to enable installation of apps from unknown developers in the settings of your Android phone in order for it to install.

Step 9:

Hack Your Day Contest

Participated in the
Hack Your Day Contest

Hand Tools Only Contest 2016

Participated in the
Hand Tools Only Contest 2016

Big or Small Challenge

Participated in the
Big or Small Challenge