For more on microcontrollers and wearables, check out Make: Volume 43. Don't have this issue? Get it in the Maker Shed.

For more on microcontrollers and wearables, check out Make: Volume 43.
Don’t have this issue? Get it in the Maker Shed.

Does your makerspace have a sink that is always full of dirty dishes? Or do you yourself require better discipline around the home to stay on top of your chores? To automate your home, office, or workshop, one of the first things you’ll require is some kind of vision system to detect motion or objects. A small computer capable of running OpenCV could be just the tool you need.

The Dirty Dish Detector combines a BeagleBone Black & Logitech webcam – along with plenty of open-source software – to tackle the annoying activity of tracking when dishes get left in the sink.

DDD_above-sink
1-DSC00177

This project is built sequentially, in the following order:

  • Update the BeagleBone Black to be running the latest image of Debian, which includes OpenCV and Python libraries, among others.
  • Configure the BeagleBone Black to automatically connect with your WiFi network.
  • 3-D print and modify an enclosure for the BeagleBone Black to accommodate additional elements (webcam, USB hub, etc.).
  • Install the Dirty Dish Detector above your kitchen sink.
  • Use the Cloud9 IDE to interface with your Detector, programming the project using readymade Python scripts.
  • Get notifications whenever dishes pile up! Or likewise whenever the dishes get done!

This project assumes some familiarity with the command line, along with the ability to administer your local area network. A comfort with coding in general (be it Python, PHP, or even HTML) will get you very far with this project. All of the necessary code is supplied below and documented, but opportunities for you to customize the code to your liking will arise.

The project’s code will also be assembled sequentially. Once the physical project is built and installed above your sink, we will first take a ‘camera-test’ photo using a simple script. Once confirmed, we will calibrate an empty sink image. That will give OpenCV a reference image upon which to compare against when it processes images, looking for culprit cups and dirty dishes.

sink-latest-circles
sink-latest-edges

Once the system knows what to compare against – a clean sink – we’ll implement the ability to send an email and/or MMS when an unclean sink is detected. These notifications will not happen all the time, but rather with every ‘status change’ in the sink. Thus when the sink goes from ‘clean’ to ‘dirty’ you will get a notification; and likewise when it goes from ‘dirty’ to ‘clean’ you will get a notification! Thus the Dirty Dish Detector is primarily a detector, and it will notify you accordingly. Lastly, automate the system to take a photo every 5 minutes. The webcam’s status LED will alight whenever the script runs, like so:


Lens Angle and Your Sink/s

DDD_distance

You’ll want to locate the Dirty Dish Detector at an adequate distance to cover as much of your sink or sinks as possible. Since kitchen cabinet installations follow somewhat of a standard, I found the immediate underside of my cabinets to be ideal for the webcam’s field of view. With the lens 23 1/2″ from the base of the sink, I was able to see an area approximately 16″ x 12″. Experiment with the webcam’s lens before you install your Detector if you’re unsure exactly what it will see.


3-D Print Your Enclosure

Print an enclosure case for your BeagleBone Black while you’re reading the steps below in anticipation of assembling your Dirty Dish Detector. I used Logic Supply’s enclosure available on Github. Print the enclosure in your favorite color/s or assemble your Detector with a different design altogether – if you do leave a note below in the comments because I’d like to see your mod!


As With All-Things-Vision

Simply because a lens will capture images of your sink doesn’t mean it will be a 100% guarantee against dirty dishes. Culprits include low-light and the software itself. The sink where I tested the Detector gets plenty of indirect sunlight. So the Detector operates pretty good from dawn to dusk. After that it’s a gamble, given the interior lighting available. Even during the day, overcast days or sudden cloud coverage could produce fluctuations in light levels and errant results. Some slight tweaking of the software to suit your environment is almost a given. In the final Dirty-Dish-Detective.py file look for the #match circles with drains comment and the tolerance variable; adjust the tolerance as needed. A lower number will increase the likelihood of false-positives, whereas a higher number will let the system be more ‘tolerant’ with what it defines as a dirty dish.


WiFi caveat

During the making of this project, configuring WiFi on the BeagleBone Black was a headache, and the most time-consuming aspect of the build. Even now, the wireless adapter only powers on and connects with my wireless network once in every three boot-ups. I can’t figure out why; the 3.6A power adapter supplies more than enough current. I tested operations with several Netgear adapters but eventually chose the G54 for the low-profile of the adapter package.

TIP: Never plug a wireless adapter directly into the BeagleBone Black’s USB port, not even during prototyping. It will likely conflict with signals from the board’s PCB. Always use a hub.


Browser caveat

As with most projects that involve web browsers, there’s a caveat. This project is tested with Chrome and Safari (on Windows and Mac respectively). Other browsers – specifically IE – will likely not work.


Code Copy+Paste

DDD_view-raw

In the steps below, wherever you see code meant to be copied in bulk to the Cloud9 IDE, I have embedded the necessary code using gists. I recommend right-clicking on the ‘view raw’ link in the bottom-right of the embed and clicking ‘Open link in new tab.’ This will give you the ‘raw’, un-formatted text to copy to the Cloud9 IDE for making your own Python files.


I am indebted to Jason Kridner for the bulk of the code powering this build, who in turn would like to thank Tom from London Hackerspace for sharing his solution from several years ago.