Coin Sort Bot

Overview
 

Coin Sort Bot's cover image
Coin-sort-bot is a physical robot that I co-designed and wrote software for to automatically align and sort coins based on their physical features like year, date, and mint location. It is designed mostly with fusion360 for CAD and Python driver software, and is an IOT device that connects to a separate Django webserver. It is still in development, and currently has a basic 3d printed prototype and driver software to control the hardware.
academicfeatured

Inspiration

Coin scanner app images
Coin scanner app images

A while back I was sifting through some older coins that my grandma had saved from many years ago, looking up their values one by one. Some US coins are worth more money based how many were made that year, the denomination and composition, and various other factors. As I laboriously sifted the coins, the idea donned on me: couldn't I build some sort of tool to help me process the change? Looking at "coin identifying" apps on the app store, I found that there were already various different apps to identify coins, which acted as essentially a specialized reverse image search. They were all proprietary though, and I couldn't find a good API for the process.

Additionally, though these apps presented a software solution to make manually sifting through the coins more streamlined, I still found it tedious to have to lay down each coin on the table one by one, and snap photos of each side. I decided then, that, in addition to making a tool like that of the apps to convert an image of the coin to a dollar valuation, it would also be handy to have a robot lay out the coins, and physically move the coins into appropriate rolls based on their year and/or value.

Think[box] Grant

At my university (Case Western) there is a campus makerspace called "Thinkbox." Each year they award various project ideas up to $2.5k to bring the ideas to fruition, through the Thinkbox project fund. Their grant page lists projects eligible as ones that are:

  • Individual and team-based extracurricular and personal projects.
  • Projects related to a competition.
  • Entrepreneurial projects that require prototypes.

Which my automatic coin sorter was a perfect match for. I applied for the grant, writing up the concept and creating a list of materials that I thought we'd need for the robot, like 3d printer filament, cameras, various sensors, and a raspberry pi. I invited a friend to help join me for the project, thinking that two people would increase the chance of approval. After a few weeks, we were approved for a $650 grant! I began ordering supplies, and got to work.

Senior project fair

Coin identifyer senior project
Coin identifyer senior project
Coin identifyer senior project
Coin identifyer senior project

Towards the end of my first semester, I attended our senior project fair, and, after hearing from my logic design professor about the projects her students were working on, decided to check them out. It turned out that there were some groups in our electrical engineering department working on designing the software for identifying coin years and denominations, which was very similar to what I was working on. I noted their contacts at the time, and plan on reaching out when we get around to actually implementing the image identification for the device.

The project

Parts & Design

Coin aligner mechanismrub Coin chute component

Early on we decided to make the project mostly 3D printed, to make fabrication simple so that we could focus on the design of the bot. The primary components of the coin sorting machine are the main tub where the input coins go, the alignment system, and the chute which dispenses the coins into coin rolls (a unique facet of our design, where we decided we'd let hang off the table). Most of the components 3D printed were designed in Fusion360, because of how easy it is to collaborate, but also because I liked the interface. Being able to parameterize parts has been super helpful; for example, the funnel that the coins fall into that has a coin roll in it can be generated for any type of coin by simply changing the coin diameter value, and everything updates to make it work.

Adafruit makes coding for their controller boards super easy by providing libraries that 'just work.' Check out their motor controller board example code, for example...

1from adafruit_motorkit import MotorKit 2# Initialise the first hat on the default address 3kit1 = MotorKit() 4# Initialise the second hat on a different address 5kit2 = MotorKit(address=0x61)

What was annoying, however, was getting RPIO (the interface that lets you use the raspberry pi hardware via Python) to work on my local machine for testing. What I figured out, however, is that I could remotely program to the Pi over SSH using either a VSCode remote development extension, or, to my preference, Jetbrain's remote interpreter. With their remote interpreter add on, the code would automatically get shipped to the Pi's temp folder, and then would be executed on board, even though I'd be coding directly on my own computer.

Coinbot discord IP finder
Coinbot discord IP finder
Tailscale dashboard
Tailscale dashboard

To network to the Pi, originally I set up a simple cron job to automatically discord message me (using a discord webhook) the local IP of the device. However, configuring the IP address every time to be different was very annoying. Thankfully, I had recently learned about tailscale, which has been absolutely amazing and seamlessly let me hook up the Pi (along with all of my other devices) to a secure personal virtual network. To install tailscale on the Pi, it was as simple as a single curl command.

Digital microscope coin image
Digital microscope coin image

For the main board, we decided to go with a $50 Raspberry Pi 4 (which we were able to obtain from Adafruit quite easily), and for the electronics, we got 2 digital microscopes. The main issue with the cameras we got is that they need to be about 9 inches away from the coin to focus properly, but 3D printing a tube to hold them out at the proper distance should solve the problem. We purchased two LED lights to illuminate the sides of the coins, though we realized after receiving the cameras that they themselves also have lights built in. And, finally, we got 16 servos for controlling where to place the coins, along with a servo and motor controller.

Motor controller
Motor controller
Servo controller
Servo controller

The controllers were annoying to set up since they are designed to be "HATs" for the raspberry pi - that is, they are meant to literally sit on top of the board. To use multiple of them they had to be addressed (soldering binary IDs onto pads on the tops of them), and then right angle extenders needed to be soldered onto the bottom servo hat to allow the wires to stick out for the servos.

Initial design

Coin sorter inspiration
Coin sorter inspiration

For the during school year portion of the project, I decided to work specifically on the hardware portion of the project, and am planning to work on the software over the summer. For now, we started off by working on how we would align the coins so that we could photograph them, process them, and then move the coins to proper output coin rolls.

Coins on rubber wheel
Coins on rubber wheel
Rubberized wheel
Rubberized wheel

We took inspiration from the a classic metal coin sorter with a rotated wheel, which the coins friction slide along as the wheel rotates and eventually dispenses them aligned onto a track by stripping them off the wheel. After a lot of experimentation, we designed something similar for use with a stepper motor, which we 3D printed. What's cool about stepper motors is how precise control we'd have over them; it may not have been necessary for this project, but it wouldn't hurt to have the extra torque and speed. During one day while working on the project, I came across some rubber sheeting that was being discarded, and decided to also lasercut that and apply it to the wheel to add friction for the coins.

The original "drum to chute" design
The original "drum to chute" design

The next step for the spinning drum design was to "slice" the coins off the spinning wheel so that they could fall into a chute. We added a nib affixed to the side of the wheel to redirect the coins, and then added a pathway to allow the coins to eventually fall into a chute where we could then use servos to move them into view of a camera, and then, afterwards, separate them.

Beam break sensor
Beam break sensor

We quickly realized, though, that it was entirely possible that multiple coins could end up on top of one another in the chute, and that multiple coins could jam the system. The issue was that, while only one coin could "cling" to the rubber at a time, the coins could fall one after another if the wheel were continuously spinning, allowing coins to drop faster than we could process them. We thought one good solution to this problem would be to use a beam break sensor, and so we ordered this one from Adafruit. But before we even tested it, we realized that adding a new chamber to limit the flow of coins would be a whole new challenge in it of itself.

The chute
The chute

We decided to take a break from the drum design, and move on to designing the actual chute that the channel would eventually connect to. The idea was that there would be many chutes stacked on top of each other, and we'd know which coin was falling ahead of time. We could have a single chute have its respective servo move into position so as to redirect the current falling coin into a funnel, which would have an output coin roll in it. The system was very vertical, and would hang off the edge of the table, using gravity to move the coins along.

This system worked great! The servo was able to redirect the coin into the funnel, and the coin nicely fell into the bulbous shape of the funnel and aligned itself atop the other coins in the coin roll in the funnel. This system worked so well, in fact, that it inspired us to completely redesign our robot, and move away from the spinning drum method.

Redone design

New design dispensing coins one at a time

Instead of having a spinning drum with room for multiple coins to be dispensed at a time, we spent a while planning out new ideas, and came up with a different system that could allow a rotating motor arm to skimp off one coin at a time from a slightly elevated tube with a gap the size of a coin at the bottom. We reused the funnel design, but this time the funnel would redirect the coin into the chute. We considered that multiple coins could have different thicknesses, with some being even twice as thick as others (e.g. nickles and dimes), so we made the tube screw on to the main platform holding the controller, motor, platform, and funnel.

New design CAD
New design CAD

The new design clamps on to the corner of a table, and the actual sorting chute is completely vertical. A friend mentioned that we could have it be at a slight diagonal to allow it to be slightly longer (since we're restricted to the height of the table), which is something we may consider later.

This design is still a work in progress, so check back for more about it soon!

Driver software

Although the actual processing of coin images is not something I plan on working on until the summer, I have been making sure that the hardware components that we use are able to be controlled with our Pythonic on-board software. The software for this project is two-part: software that will live on the board itself, and a backend web server to control the board. The on board software at its current stage provides a very easy to use API interface for driving the various components, so that I can write code like this to control it.

1async def main(): 2 coinbot = CoinBot() 3 await coinbot.setup() 4 5 photo1 = await coinbot.cameras.camera1.capture() 6 7 await coinbot.servos.toggle(2) 8 await coinbot.motor.start(speed=40)

Adafruit makes implementing the software quite simple, since they have packages for using the servo and motor controller boards. What I've done is added another layer of abstraction, so that we can control exactly what we need. For the cameras, I'm using opencv, which is a library for processing images, that also has the ability to interface with the OS to capture images. I experimented with ffmeg to capture the images by shelling out of my Python code, and was able to get it to work, but to keep the lights on the cameras on so that the cameras stay focused it made more sense to go with opencv.

Next steps

I'm currently brainstorming how to go about controlling the board remotely, and am toying with the idea of using MTQQ, RabbitMQ, or a simple webhook system with on-board flask endpoints to control the various components. Eventually, the machine will intake coins, send the photo data to the webserver, and then will wait until it is instructed to manipulate its servers to allow the coins to fall down the proper chute.

In the future, the plan is to actually implement OCR to scan the dates off of the coins and basic machine learning to identify denomination. I'm not entirely sure how I'll go about doing this, but it will likely involve image classification to determine the denomination and perhaps other details (such as whether or not the coin is a D-mark coin), and then either hosted OCR using an open source library like tesseract on the webserver controlling the raspberry pi, or an API like those that Amazon or Google offers to perform the text analysis.

Reflection

Ultimately, the prototyping and iterative design required for this project has been a lot more extensive than I expected. We've gone through a ton of rolls of filament to get a working prototype, and there's still more work that we could do. 3D printing has been great though, and allowed us to rapidly test out designs. I've also grown to really like Fusion360 (though, not it's cloud based model, and licensing model).