Intro: Arduino Smart Trash Can
Making waste disposal more efficient can cut costs for cities while also keeping them cleaner overall. This tutorial will show you how to build your own smart trash cans that will send alerts when they are getting too full. When the volume of trash in a can reaches a certain threshold, the can will notify you by creating a Zendesk ticket. Then, when the can is emptied, it will create an event in a Google Calendar to log the activity so that you can visualize how quickly your trash fills up.
The app we're building is powered by Temboo and an Arduino Yún, but you can use other hardware like a Samsung ARTIK 10 if you'd prefer. It's also easy to mix and match web services for the app if, for example, you want the can to Tweet at you when it's full or email you when it's been emptied. The video shows you how to build the smart trash can, and how it works once it's all set up.
Step 1: Gather Your Parts
To build this app, we'll need:
- A trash can with a lid or lip
- An Arduino Yún
- An IR distance sensor
- A solderless breadboard and some wires
We'll also need a Temboo account to generate the Arduino code for the app. You can sign up for a free account here.
Step 2: Create Your Calendar
We need to set up a Google Calendar to log data on when the can is emptied. First, sign in to your Google account, or create one if you don't have one.
Then, create a new calendar and name it "bin status."
Step 3: Get Your Google Calendar Credentials
For this step, you'll want to head to Temboo and follow along with the steps listed for the smart trash can IoT application. This is because Temboo will store our API credentials as we create them, and then automatically add them to the Arduino sketch we'll be using.
First, go to the Google developers console and select "Create Project."
Then, enable Google's Calendar API for the application. This will allow our Arduino to post to the calendar when the trash is emptied.
Add an OAuth 2.0 client ID credential to give the application permission to access our Google Calendar. When you do this, you may be prompted to configure a consent screen where you'll need to save a Product Name. Specify "Web Application," and use the URL that Temboo has generated for you as your Redirect URI.
Now, go through the OAuth process. We can do this by supplying the Client ID and Client Secret we've just gotten from Google in the corresponding fields on Temboo's website.
Finally, save the Client ID, Client Secret, and newly retrieved Refresh Token as a Temboo Profile so that they will be included in your Arduino sketch later. By storing the keys in a Profile, we're decreasing the memory required to run our Arduino sketch, making it possible to remotely reprogram the sketch with new keys at any time, and making the keys more secure by moving them off the board.
Step 4: Get Your Zendesk Credentials
Now, sign up for a Zendesk account. We'll have Zendesk send alerts when the trash is half full, three-quarters full, and completely full.
Once you've signed up, save the Zendesk credentials in a Temboo Profile, as you did with your Google Calendar keys.
Step 5: Save Your API Inputs
Now that we have Google Calendar and Zendesk set up, we need to save the inputs that we'll be passing to their respective APIs. First, retrieve the Calendar ID of the calendar we made earlier by finding "Calendar Settings" in the "Calendar Address" section.
Save that Calendar ID, along with what you want to name the event, in a Temboo Profile.
Save the subject line that you want for the Zendesk alerts you'll be receiving in a Profile as well.
Step 6: Build Your Circuit
Now it's time to set up our hardware. Connect the IR distance sensor to the Arduino's 5v power, ground, and analog 0 pins, as shown in the diagram. Then, secure the sensor to the underside of the lid or lip of your trash can so that it is pointing down into the can; this will allow it to accurately read trash levels as the can fills up.
Step 7: Run Your Sketch
Since we already saved all our API keys as Profiles, all of that information has been pre-populated in the Arduino sketch that has been generated by Temboo. Download the sketch from Temboo, paste it into the Arduino IDE along with the header file included in the download, and it should be ready to upload and run!