Ship It Day how-to: Empty coffee can detector

As you could read in one of our previous posts, a few weeks ago Foreach organised a two-day period where employees could pick projects they wanted to work on. The only requirements were that it had to be useful and ‘shippable’ after two days. 

Because nobody likes an empty or almost empty coffee can and we were tired of the discussions when the coffee has to be refilled, we decided to build a detector that tells us when exactly we need to make new coffee. 

This post describes how we did it. 

Tools and tech

In this tutorial we will not cover the inner workings of a load cell. There are some very good explanations on the internet that explain it better than we can (

In a few words, it measures the difference in resistance between four resistors on the load cell. When pressure is applied on one side, it creates a tension in the middle part of the load cell and then the electrical resistance changes.

Building a base for the loadcell

The first thing we started with was hardware. We needed a base for the load cell to rest on. We did not want to spend a lot of money, so we went to the local hardware store and got some leftover pieces of wood. 

The base is just a wooden plate with holes drilled in the middle to fit the bolts. The load cell we bought had standard M4 and, of course only discovered after the first trip to the hardware store, M5 size holes. As with every decent hardware project, we made several trips.

For the base it does not really matter where the holes are drilled, as long as the center of gravity is above the support center of the base. You don’t want your construction to tip over while it contains hot coffee. Be sure that the arrow on the load cell is facing downwards, otherwise your readings will be in reverse. A tip when connecting the wood to the load cell: use the biggest washers you can find. This will help balance the plates. For the plate on top we used some leftover fibreboard. Because the bolts and nuts pop out of the top, we needed some extra padding to make the coffee machine ‘float’. You’ll see what we mean on the picture below. 

It looks cheap - it was, but it did the job perfectly. In fact, this is all you need for the load cell to work. Our primary objective - the base - was reached. Because we still had time left, we used flooring wood to create a casing and build a container for the LCD screen.

The software

Then it was time to start building the real machine. When you use the same amplifier as ours, you’ll need to solder the breakout pins onto the amplifier. 

After soldering the amp, it is time to connect all the pieces. Because we were racing against the clock, we simply connected them with jumper wires. If you want a more robust build we suggest soldering these cables as well. 

Connect the RED, WHITE, GREEN and BLACK to the corresponding cables on the load cell. The other side goes to the Arduino. 

  • VCC connects to the 5-volt on the Arduino
  • DAT (DATA) connects to digital pin 2
  • CLK (CLOCK) connects to digital pin 3
  • GND (GROUND) connects to ground

To test if everything is working as it should, try to load the following little program to calibrate the readings.

After you got the calibration code to work, it is time to start writing down some numbers. 

Write down the weight of the empty and full coffee can. It doesn't really matter that the weight is totally wrong, provided that the same calibration is used in the final code. When you have both numbers, you need the delta. However, this is only the case when the same weight is placed on the scale each time the Arduino reboots. As the power of the coffee can is turned off nightly in our HQ, we simply decided to use our empty coffee can as the zero-value for our calculations. 

Then it’s finally time to put all the parts together. Our build has an lcd to display the current status of the coffee can in percentage. You can easily replace this with a buzzer, a led or any other system to warn you when the coffee runs out. When you want to use an LCD like we did, you can use the following diagram to connect the lcd to your arduino. 

As you can tell from the diagram the lcd also uses digital pins 2 and 3. We chose to change the pins from the amplifier to pins 6 & 7 as you can see in our code. 

When everything is connected, it’s time to write the code for the empty coffee can detector. If you can’t wait to try it out yourself, feel free to use our empty-coffee-can-detector-program. The only thing you will need the change, is the net weight of the coffee can (the difference between the numbers you just wrote down) and the digital pins you used for the amplifier and the display. When you use something different than a lcd screen, you’ll need to add that code as well. 

#include <HX711.h> //scale

#include <LiquidCrystal.h> //display

#include <math.h> //rounding numbers etc.

#define DOUT  3

#define CLK  2

// initialize the scale library

HX711 scale(DOUT, CLK);

// initialize the display library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 9, 8);

float calibration_factor = 8000; //-7050 worked for my 440lb max scale setup

const float full_weight = 30.8;

const float empty_weight = 0;

const String coffee_percent_message = "% coffee left";

const String msg_coffee_one = "You're chosen!";

const String msg_coffee_two = "Make more coffee";

float total_coffee_weight = full_weight - empty_weight;

void setup() {



  scale.tare();  //Reset the scale to 0

  // set up the LCD's number of columns and rows:

  lcd.begin(16, 2);

  // Print a message to the LCD.



void loop() {

  scale.set_scale(calibration_factor); //Adjust to this calibration factor

  Serial.print("Reading: ");

  Serial.print(scale.get_units(1), 1);

  //Serial.print(" KG"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person


  float percent = getPercentage();





void printDisplay(float percent){


  char temp[10];

  if (percent > 100){

    percent = 100;


  if (percent < 0){

    percent = 0;



  String percentAsString = String(temp);

  Serial.print(percentAsString + coffee_percent_message);

  if(percent > 17 ) {    

    lcd.print(percentAsString + coffee_percent_message);

    lcd.setCursor(0, 1);



  else {


    lcd.setCursor(0, 1);




float getPercentage(){

  float actual_weight = scale.get_units();

  float actual_coffee_weight = actual_weight - empty_weight;

  float percent = (actual_coffee_weight / total_coffee_weight) * 100;

  return percent;


void drawPercentageBar(float percent) {

  int number_of_bars = round(16 * percent * 0.01);

  for(int i = 1; i <= number_of_bars; i++) {





Final result

We had a lot of fun building our "Empty Coffee Can Detector", and we're very glad to see it's actually being used at the office every single day. If you have any questions, suggestions or other comments, don't hesitate to get in touch through the comments.

Category: Miscellaneous

Tags: Ship It Day Arduino

February 3, 2016 by Jens Steppe