Coffee Pot Monitor

Arduino on breadboard with 16x1 LCD and RGB LED for debugging, hooked up to home-made pressure sensor.

Arduino on breadboard with 16×1 LCD and RGB LED for debugging, hooked up to home-made pressure sensor.

We recently held a “Hackathon” where I work, a day of coding then a day of presentations.  Most of the teams worked on something  directly related to our company’s website in one way or another, but one of the other guys in my department wanted to know if there was some way to check the coffee pot levels remotely to possibly save a trip, or at least help him time the trips so he wouldn’t make a fruitless sojourn to the break area trying to fill his cup on the way to a meeting.  I thought about it for a moment then headed home to retrieve my box of electronic odds and ends.

I knew that I wanted to be measuring the weight of the remaining coffee, so I went with an Arduino for the front-end.  For temporary projects I have an Arduino Duemilenova bolted to the outside of a tacklebox with jumper wires, LEDs, and a few basic components like LEDs and common-value resistors.  It’s usually wired up to drive an HD44780-compatible textual LCD.  I also grabbed a chunk of conductive foam to make a crude pressure sensor from.  Lastly, I did pick up a Raspberry Pi but with less than a day to design, build, and code everything up, I didn’t have time to put that into play, but with a little more time on the project, it’s a small and inexpensive way to build the web interface to the Arduino sensor and code.

My first task was to get the sensor built and working.  I took a length of twisted-pair hookup wire and removed a bit over 6″ of the insulation from one end.  I made a squiggle from the bare ends by folding the stripped wire around a large ballpoint pen.  Finally, I made a sandwich with the foam in the middle, one bare wire on either side, and wrapped top and bottom in clear mylar packing tape.  To make it measurable by analog pin A0 on the Arduino, I made a simple voltage divider with one of the 220 ohm resistors in the parts bin (commonly used for current-limiting with a red, yellow, or green LED and a +5V power rail).  The exact value, more or less, isn’t a big deal, it just affects the specific values returned while taking a reading.  For more precise measurements, I probably would have directly measured the resistance of the sensor uncompressed and compressed under the approximate weight of a coffee pot full of water (later determined to be about 1K ohms loaded to 50K unloaded) and gone with . In this case, the low fixed resistor tied to ground was the preferred electrical path when the sensor was unloaded, keeping the “empty” value close to 0, but when the full weight was on the sensor, the ratio would plunge from 500:1 to 5:1, giving a nice wide range of values from no pot to full pot.

Since time was of the essence, I just whipped up a simple sketch that read the value returned from A0 (presented as a value from 0 to 1023 – Arduino A-to-D converters have 10 bits of precision) and recorded it with no pot, an empty pot, a pot with one cup of water in it, etc., up to a full pot.  Our coffee pots hold about 7 to 7.5 coffee mugs of liquid.  I’m sure they are sold as a “12 cup” pot, but being realistic, nobody in our office drinks a 6 oz or 8 oz cup of coffee.  Once I had my scale, I expanded my test sketch to not just display a raw value on the LCD, but to return a scaled value of 0-7 on the serial port (representing the approximate number of mugs of coffee remaining) and to light the red portion of my RGB debugging LED to indirectly report the current status of the coffee pot (off for no pot on the sensor, dim for little coffee remaining, bright for a full pot).

With the Arduino side of things in hand, I turned to building a web interface.  If I’d had another half-day to write code, I would definitely have done this on my Raspberry Pi.  With most of the afternoon gone, I focused on building a simple web page on the Ubuntu laptop I use for work since it already had Apache installed and set up for other things, and I had a full suite of tools including GIMP for making some coffee-themed web graphics.

animated-coffee-pot-cutawayTo visually represent the amount of coffee in the pot, I started with a simple image of a stainless steel pot. In GIMP, I selected the base, pulled the selection “in” about 20 pixels, then inverted the palette to give a faux cut-away look. Using layers to make generating multiple aligned images easy, I created “fills” from 0 to 7 parts up the total height of the cutaway mask (each one 27 pixels taller than its predecessor). If I’d had more time or if I were faster at using GIMP, I would have overlaid a fill count in bold white text over the coffee level for a more polished look. When I was satisfied with each of the images, I arranged each set of layers (outer view of the pot, current fill level, and cutway view) and saved them as seven individual files named carafe-X.png then went to work on the final piece to tie it all together.

With the Arduino sensing the weight of the pot and returning a scaled value over its serial interface and with a web server waiting to display whatever text and graphics were placed in the right directory, what remained was a short script to connect the two.  Perl is one of my favorite languages and was perfectly suited for the task.  The “coffee pot daemon” coffeepotd begins by using the Perl module Device::SerialPort to open the serial connection to the Arduino, then loops once per second forever as it reads a string, splits it on a comma, retains the scaled number of cups remaining (discarding the raw weight value from A0) and uses the cups-remaining value to generate the filename corresponding to the correct image to display and copies that specific image file to /var/www/carafe.png where the web server can serve it from. To view the coffee pot status, one points a web browser at http://localhost/coffee.html which is a simple web page with a small amount of Javascript to force the browser to refresh the image twice a second (it could go much slower but I wanted a quick response for my demo).

I was late to sign up for the Hackathon, so each of my presentations (a public one in the main lunch area and an individual one for the CEO and upper management) were half-way through the third hour. It was fortuitous timing – after a dozen complex and technical presentations, each audience was ready for a light-hearted, lightly-technical demo. I intentionally kept the projected presentation short (a title slide, a cartoon of someone getting the last drop from the pot to state the problem, a cartoon of a technologically-complex coffee pot to illustrate how an IT person would solve the problem, and a simple list of the elements of the solution) and let the hardware speak for itself. Everyone was delighted as I lifted the coffee pot off the sensor and the lights changed and the graphic changed as I poured cup after cup.

People at work were still talking about my project weeks later. They also wanted to know if I’d be deploying a permanent version. I have some ideas about how to make it waterproof (resistive force sensors are easily ruined by getting wet), and there’s always the Arduino+Raspberry Pi combo that I can work out if I don’t want to try a different approach like directly adding an Analog-to-Digital converter to the Pi. What I built in a day was a great hack, but it takes a bit of planning to really build a solid product that is just going to work all day, every day. Back to the drawing board.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s