Introduction: Cap It: Interactive Bottle Cap Sorter

This instructable was created in fulfillment of the project requirement of the 2018 Makecourse at the University of South Florida (

Every now and again, I enjoy coming home and having a few beers to relax after a long day of living life. Unfortunately, my bottle caps have started to pile up and I figured something needed to be done to fix that. Which is why I have created this utterly ridiculous yet semi-sensibe bottle cap sorter. Now I know what you're thinking, "couldn't you throw the bottle caps away" or "aren't the bottle caps going to pile up regardless?". Well...yes, but I wanted to get more familiar with Arduino and this gave me the excuse and motivation to do it!!!

And who wouldn't want one of these in their own ManCave or SheShed?!?!

In this Instructable, I will be showing you step by step how I created this tacky and overall useless device!

(Please drink responsibly)

If you have any questions about this build or need help with troubleshooting, please leave a comment below and I'll be happy to help you out!

Step 1: Gathering the Parts

Hardware for the Circuitry

To build this device you are going to need the following parts. Some of which are optional as they make the build a bit more durable.

Not to worry, I'll provide the links to the products I bought off of But see what all you can scrap from your broken/old electronics around the house!



  • Wire Cutters / Scissors
  • Handheld Dremel and or 220 grit sandpaper
  • Heat gun
  • Philips Head Screwdriver
  • Flat Head Screwdriver
  • Hot Glue Gun (for the smart & lazy)

Step 2: Building the Bottle

Quick Note

Originally the housing was going to be a simple box similar to the color sorter that HowToMechatronics had built for one of his projects. However, one night laying in bed I occurred to me that I have the tools and the knowledge to do more! Luckily at the University of South Florida we have a 3D printing lab that is available to the students and the printing is essentially at cost. This gives us the freedom to 3D print to our hearts desires at minimal cost to us. Soon thereafter, I came up with the general idea to create the bottle design that you can see in the finished product!

NOTE: Now you're probably going to hate me but in order to maintain some amount of originality to my creation, I will not be posting the CAD files for the bottle, shaft, or Decider. I truly believe that creativity, imagination as well as ingenuity are very important skills that young and old minds alike need to flex and continue to grow. However, feel free to work off of the images that I post and design your own version (it's really not too difficult)!
Also, if this is your first time modeling something of this nature, I strongly advise against 3D printing your design! (Mistakes in a project with a print this large can be very costly to reprint!)
Although it won't look as flashy, foam board is much more forgiving of a material to start with. See this example project created by HowToMechatronics.

Key Design Considerations

The bottle was originally designed to allow the user to open their bottle and deposit the cap into the mechanism in one smooth motion (note the open neck design). The shaft had to be wide enough to allow the bottle cap to slide down with ease in a fast yet controlled manner to allow the Decider to catch the cap.

The shaft was also designed to be integrated into the bottle through the use of notches. This is a huge advantage over gluing it in place as precision is of the utmost importance with a device of this nature. The TCS3200 color sensor module was also kept in mind when designing the shaft. Because the shaft has a place for the color sensor to be screwed on, the distance from the Decider to the color sensor remained constant which allowed for a precise and consistent reading of the bottle caps color.

The Decider was to be printed black to aid in the color sensor's accuracy, as any other color would have interfered with the reading if the color sensor was slightly off it's mark or the cap was sitting in the Decider in an awkward position.

The return slot was actually an afterthought. Before I sent the design out for printing, I realized that calibrating the device would be a tedious activity especially if I would have to tilt the bottle upside down after each reading.

My Design Was Not Perfect!

As much as I would love to bask in the triumph of how this project turned out, it wasn't always a walk in the park.
I've never been very good at tolerancing my 3D prints. Actually, I don't tolerance my prints at all. I add additional shells (4 instead of the default 2) to my print profile. I prefer to start the tedious sanding process to get my parts to fit together from the get go.

Step 3: Wiring It All Up!

The wiring aspect of this build is pretty straight forward, just follow the Fritzing schematic and you should be good to go! As with the majority of Arduino projects, if one wire is incorrect, most likely this circuit won't function properly!

To ensure the whole circuit is correct, I strongly advise wiring up each component one by one and checking that they function correctly by using the examples I posted above.

Step 4: The Code

If you are new to Arduino, this WILL be overwhelming! But bear with me, in an effort to keep this as simple as possible, I will be breaking down my code with comments as well as showing you where I found the example codes which I used to build my master code. Remember, at the start of this project I had no clue what I was doing either. A good start is to take a look at the decision flowchart to get a feel for what the goal of the program is, then try and break down my code and when you get lost check out the examples that I built my code off of.

Libraries to download
(Click here to learn how to install libraries on your Arduino)

  1. ServoTimer2 - The Servos use Timer2 as the Wav Player is hogging Timer 1
  2. LiquidCrystal_I2C
  3. Library for the SD Card Reader Module
  4. TMRpcm (The Wav/Mp3 Player Library)

Key Concepts of the Code
(Linked below are the codes that I used to build my master code)

  1. The Color Sensor
  2. The LCD Screen (lines 24 - 33)
  3. The Servo (File -> Examples -> ServoTimer2 -> Sweep)
  4. SD Card Module (File -> Examples -> SD -> CardInfo)
  5. Wav Player (File -> Examples -> )

The Master Code

Take a deep breath and go through my posted code and their adjacent comments line by line to get a feel for what's happening as the Arduino works through the code.

Soon I will be posting a detailed video walk-through of my code.

Step 5: Formatting Your SD Card to FAT32

So in order for your Arduino to work properly with your Micro SD card, the memory card must be formatted to FAT32. For SD Card under 32Gb this isn't an issue and it's easy to convert them from it's default format exFAT to FAT32.

However, if you're like me and saw a 64GB Micro SD card on Amazon for $13 and couldn't help but buy it. The solution is still pretty quick and painless.

Go to, and download the "fat32format".
DO NOT click on the large green buttons. The file itself is safe, I've scanned it for viruses and you can too, however if you click on the green button don't say I didn't warn you!

Also, make sure you're choose the right drive that your SD card is in. You don't want to format the wrong one, although I'm moderately sure the program will not allow it to happen.

That's all it takes! Your SD card is now ready to be used with the Arduino!

Step 6: Wav Player

In order for your program to successfully call up your .Wav audio files from your newly formatted Micro SD card, your MP3 files must be converted to the proper .Wav audio format.

Go to and simply follow the instructions show in the image below.

Set the Bit Resolution to 8-bit
Set the Sampling Rate to 16000 Hz
Change the Audio Channel to Mono
Change the PCM Format to PCM 8-bit Unsigned

Then once you have your .Wav files downloaded, simply put them in the main folder located in your SD Card.
Take note of the exact file names as you will be calling them up later in your code!

First Time Author

Participated in the
First Time Author