Nutri-Manager: an Embedded System That Can Classify Different Foods to Map Them to Their Respective Nutritional Value
by shalok4813_be23 in Workshop > Science
39 Views, 0 Favorites, 0 Comments
Nutri-Manager: an Embedded System That Can Classify Different Foods to Map Them to Their Respective Nutritional Value
This is part of assignment submitted to Deakin University, School of IT, Unit SIT210/730 - Embedded Systems Development
As awareness of health and wellness grows, many individuals strive to track their daily nutritional intake to improve eating habits, address health concerns, or achieve fitness goals. Despite the plethora of programs and tools available, manually counting calories and nutrients for each meal may be laborious and time-consuming, leading to inconsistent data and incomplete records.
Despite the numerous advantages of monitoring meal consumption, accurately executing this task might be challenging. Historically, individuals were required to document their meals, estimate their food intake, and manually calculate their caloric and nutritional content. Although some applications include databases and other digital tools that facilitate this procedure, it still requires considerable time and work. Users frequently must go through extensive lists of foods to identify the appropriate items, accurately input portion proportions, and consistently record each meal in a uniform manner. This may result in missing records, hence diminishing the reliability of the information provided by these applications.
This unit has provided the chance to develop an embedded system based on specific assessment criteria and fault testing. This will aid in developing a system that is practical and its deployment may be considered viable. Fault tolerance will be essential for maintaining the project's functionality in the event of failures, hence enhancing the system's reliability. The evaluation criteria will provide a systematic examination of the system and its execution.
Why do we need this project?
Athletes and persons with particular dietary objectives face challenges in precisely monitoring their nutritional intake in dining halls, buffets, and sporting facilities. Manually documenting calories and nutrients in high-traffic settings is labor-intensive, susceptible to errors, and frequently inconsistent, resulting in imprecise data. This leads to inadequate dietary monitoring, impeding health and performance. A simplified, dependable solution is required to simplify nutrition tracking in these environments, delivering real-time, precise information with no effort.
Supplies
To accomplish the objective of this system. The four fundamental criteria are machine learning, weight detection, communication, and data visualization. The following hardware satisfies these requirements:
- Machine Learning: Raspberry Pi 5, Raspberry Pi Camera Module 3
- Weight Detection: Full Bridge Load Cell, H7X11 module
- Visual Output: LCD Display
- Communication: Arduino Nano 33 IoT
Installing Dependencies
Before going any further, it is important to create an environment for our program to be executed properly. Since, most of the libraries in raspberry pi use open source code which is continuously changing due to which there are several compatibility issues that are better dealt by creating a virtual environment. So,
Raspberry Pi 5
Step 1.1. Create a virtual environment in the root folder of raspberry pi where you will be writing your code.
Install the following libraries
Make sure that you go to the virtual environment and change the settings to include system packages and write true in front of that attribute.
Arduino Nano 33 IoT
Step 1.1: Go to the libraries section of Arduino IDE.
Step 1.2: Include the following libraries to you sketch as well your IDE:
Step 1.3: Make sure that you have selected the correct port for transferring the code and Arduino Nano is recognized by that port.
Connecting Hardware
Let's start with Raspberry PI 5
Raspberry Pi 5:
Step 1: Slightly pick the holder of the camera port and insert the camera module strip into it and close it. Make sure that the camera port is fully closed, if not it will not be able to read anything from the camera.
Load Sensor and HZX11 module:
Step 1: Do the following wiring connections:
HX711 Module Pins
- VCC: Connect to Arduino 3.3V
- GND: Connect to Arduino GND
- DT (Data): Connect to Arduino D2
- SCK (Clock): Connect to Arduino D3
Step 2: Connect the load cell wires to the HX711 as follows:
- Red (E+): Connect to E+ on HX711
- Black (E-): Connect to E- on HX711
- White (S+): Connect to A+ on HX711
- Green (S-): Connect to A- on HX711
Arduino Nano 33 IoT:
Step 1: Connect the A4 and A5 pin to SDA and SCL pin of LCD screen.
Step 2: Connect GND and VCC to GND and VCC of LCD screen.
Note: If the visibility of content on LCD screen is low, try tweaking the potentiometers behind the LCD screen to improve its sensitivity and brightness.
The given image describes a brief layout of what would the hardware setup would look like.
Write Code for Raspberry Pi 5
Before starting the steps of this code, first download the .tflite file of the model. This model is a tensor flow lite version which is much faster and efficient in resource management. You can find the link to the model on git hub here.
After downloading the model, you can move on to the next step. The model from which it was converted to TensorFlowLite had nearly 94% accuracy. It is expected to observe some decrease in its accuracy. Along with that the ML model used in this system is MobileNetV2 which is perfect for embedded systems and mobile applications.
Step 1: Declare all the libraries in the previously created virtual environment.
Step 2: Write code to connect to Arduino Nano using BLE
This method will take the device's mac address to connect to along with characteristics uuid which is a special unique identifier used to denote different characteristics. It initiates the machine learning model when the weight is detected on the scale.
Step 3: Setting up inference from ML model
This line of code would ensure the implementation of ML model whenever the pi demands to classify the food present on the tray. The working of this code starts by loading the image, starting the camera, running inference with preprocessed images. This process is done in a loop inside start_inference_loop for 50 times to get the most repeated value of the food item classified by the model.
Step 4: Setting up Firebase
This is another important part of the system that stores the data predicted by the raspberry pi after detecting weight on the tray. This data can be further accessed to create a responsive website that has dashboards in it.
Step 5: Since, the main parts of the code for raspberry pi are discussed above.
The rest of the complete code for raspberry pi can be found in this step. Make sure that you keep the structure of the database same and change the credentials to your own Firebase data credentials.
Downloads
Write Code for Arduino IDE
For Arduino Nano 33 IoT:
Step 1: Let's start with creating BLE setup.
This setup will include creating a service and associating two characteristics to it. These characteristics will be leveraged to establish communication between the two devices.
Step 2: Measure weight properly and at right time.
This code will measure weight and update the value of weight whenever, the weight is detected on the tray..
Step 3: Get total calories from weight and present food class.
Create a food class that has calories per g information, then build a get_calories method that finds out the calories after taking weight as an argument.
Step 4: Loop through the Bluetooth connection
Create a loop to maintain the Bluetooth connection with raspberry pi. This code will maintain when and how the data for characteristics will be updated in the Bluetooth service. This code also use MAC filtering to ensure that only authorized raspberry pi is connected to the Arduino Nano 33 IoT.
Step 5: Save and Verify it. Download the complete code from NutriManager_prot.ino.
Downloads
Save and Run It
Step 1: Save the code in both the devices
Step 2: First run the code on Arduino IDE and then run the python script on the virtual environment
Step 3: Watch serial monitor to monitor the output and state of both the devices.
Here are some things to consider while building this project:
- Should Arduino Nano have LCD attached to it or attached to a tray where the calories will be displayed?
- Object Detection model would be able to identify multiple food items in a tray. While the simple classification model used in this project can detect a single food item at a time.(Scope for modification)
- Scope for better design Ideas for feasible implementation of this project
The reason Raspberry Pi 5 is used for sending data to Firebase instead of Arduino Nano is because Arduino Nano has the same hardware that does the job for WiFi connection as well as Bluetooth connection. As a result, using Arduino Nano for sending data to Firebase would create a lot of interference in communication between both the devices.
Well that was it ! Hope it helps