We're lazy. There have been times when I wanted gains. There have been times when I wanted to lose weight. Counting calories is the easiest way to change body weight, but it's pretty annoying to have to constantly be looking up the calories of everything you eat. I've given up on diets because I didn't want to take the time to constantly track my calories.

What it does

Scale Up solves the dilemma of having to constantly manually calculate and count calories. It is an IoT connected smart food scale that automatically looks up and records the calories of whatever fruit you weigh. We decided to prioritize fruits during this hackathon because fruits don't come with nutrition labels. The calories of the weighed food are sent to a Google spreadsheet and the iOS health app so you can easily track what you've been eating.

How we built it

We hacked a $5 food scale to be able to send weight data to a Raspberry Pi using the HX711 load cell amplifier. Using the Pi Camera and Google Cloud Vision API, we can detect the type of food that is on the scale. We then look up the calories per gram of the food item using the USDA Food Nutrition API. A few simple calculations yields the calories sitting on the food scale. Using Webhooks on IFTTT, the caloric data can be recorded in the iOS Health app and a Google sheet. Of course, Scale Up still functions as a regular food scale with an LCD that displays the weight and calories after processing is completed.

Challenges we ran into

We were challenged by the accuracy of Google Vision to correctly determine the food item. We currently limited our food type to only common fruits to make sure food labels stay accurate. Because we used multi-threading in the python script, the Raspberry Pi's CPU is constantly saturated which makes some of the code run slowly. The load cell values also fluctuate at +/- 1gram. This is a hardware restriction that we could not overcome. On the API side, we had many API options to choose from. Another API we considered didn't seem to provide us the exact information we needed: calories per gram of raw fruit. So we ultimately chose to use the USDA FDC API, and that's the one that Google uses when showing the nutrition information of some kind of food that's Google searched. The USDA FDC API requires a POST request to search by the name of the fruit and a GET request to search by a specific USDA food ID; there was a challenge in getting the POST request to work, specifically in sending the API key as a part of the request header and not the body.

Accomplishments that we're proud of

It works! Apple thinks I ate like 30 apples today. In all seriousness, this is Enoch's second hackathon and Rebecca's first time building an IoT hack, and we're happy that we got all the hardware to work together with the software without any big hiccups. We have a prototype that can be demoed from start to finish.

What we learned

We learned about how to connect a sensor, collect data, and send this data up to the cloud. We learned about interfacing hardware with Raspberry Pi using RPI.GPIO to control the pins. We also learned about HTTP GET requests to the USDA Food Nutrition API and IFTTT. Rebecca learned more about POST requests and that Python has a couple library functions that can handle HTTP requests -- some better than others! In order to preserve functionality of the food scale, we learned to use multi-threading in Python to make sure all buttons worked consistently.

What's next for Scale Up

We want to improve the accuracy of food detection by training our own machine learning model. We also want to expand the idea to more whole foods besides fruits. We also want to create a better user interface. Ideally, we would set up a back end to record caloric data and make this data available to users via a website or app. We would also like to optimize some of the code to make it less CPU intensive.

Built With

Share this project: