Software apps and online services
Hand tools and fabrication machines
Breakfast is arguably the most important meal of the day. Nearly a quarter of individuals in the U.S do not eat breakfast and this mainly due to not having enough time in the mornings. I believe that time is not the issue robbing us of our sweet sustenance and is a simple fact that cereal boxes are too heavy. I wanted to create a machine that would use Artificial Intelligence to detect specific people and pour the cereal they like for them to conserve the critical energy that is needed to tackle the day. Picking up a cereal box has gotten more and more difficult throughout the years with the increase in cereal box size. To combat the strain to muscles that daily cereal box pouring can cause, my device makes it easy to keep your weak muscles safe and nourished.
The concept for this project is to create a device that contains cereal and opens a flap to release a portion of the cereal and then shuts the flap to prevent cereal to oversaturate the bowl. Users would put their bowl underneath the cereal that they prefer the most and an artificial intelligence algorithm will detect the face and release the correct cereal to them.
The fundamentals of this project is a stepper motor connected to a wood or plastic dowel of some sort in order to create a hinge that will allow the bottoms of the containers to open up and release the cereal. The containers should be plastic containers that can have a slot cut out of them to allow the cereal to pass through.
The material used to prevent the cereal from seeping out of the hole in the bottom of the containers should be something light enough to be able to open and close easily but also strong enough to hold the cereal's gravity pushing down on it. I'd recommend a light piece of plywood but Styrofoam should be fine.
All four stepper motors should be attached to a piece of foam and placed underneath the suspended containers. I have my containers flipped at an angle to help the pouring of the cereal however this is not necessary.
The Containers should then be wired up to the Pi
The circuitry for the device is a little complicated due to needing to wire four different stepper motors. The required electrical components for this project are:
- 5V DC Stepper Motor x4
- ULN2003 Stepper Motor Driver Board x4
- Raspberry Pi model 2 B (model 2+ will work)
- Raspberry Pi camera module
This microcontroller is important because Raspberry Pi's have a large storing capacity as well as a stronger and faster processing unit which will allow us to use artificial intelligence in our project.
The camera module is slotted into the camera port on the Pi with the blue piece of the ribbon facing towards the IO ports.
The 5V DC stepper motor with pre-routed wires is slotted into the ULN2003 stepper motor driver board. Pins 1-4 of the driver board are then connected to the GPIO pins of the Raspberry Pi which can be referenced in either the wiring diagram or step.py to see the order of the pins (order is important!). The 5V(+) power pin and GND pin are connected to the power rails of the breadboard to supply power to the machine.
After everything is wired up and suspended we finish the physical part of the project and can now move on to setting up the Raspberry Pi with the proper software to allow us the get the motors moving correctly.Raspberry Pi and AI
Using a Raspberry Pi is crucial for allowing us to use the facial recognition aspect of this project as I said before due to the access to more space as well as processing power which makes it a great option as opposed to other microcontrollers.
I'm using a Raspberry Pi 2 Model B for this project but any Pi after the two should work great. Before we can start using the Pi we will need to download the Raspbian operating system first. Visit the Raspberry Pi OS download page and use a flashing tool such as balenaEtcher to flash the OS to an inserted SD card.
Once the flashing is done, configure your Pi with the initial steps and we can begin working on downloading the necessary software.Setting Up The Pi
Once initial setup is completed check to see if Python 3.7 is downloaded on your device by opening up the terminal and typing python3.
Python 3.7 should be downloaded by default on your device but if it is not type sudoaptupdate and sudoaptinstallpython3idle3 to install and update python3 for this project.
Once Python is installed we will need to install OpenCV to our Pi by using this command in our terminal. OpenCV is an open source Artificial Intelligence library optimized for vision and will have the key methods we need to not only track our face but also recognize different faces to create specific orders for different people.
sudo apt-get install build-essential cmake pkg-config -y && sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev -y && sudo apt-get install libgtk2.0-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libv4l-0 libv4l-dev -y && sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y && sudo apt-get install libxvidcore-dev libx264-dev -y && sudo apt-get install libatlas-base-dev gfortran -y && sudo apt-get install python-numpy python-scipy python-matplotlib -y && sudo apt-get install default-jdk ant -y && sudo apt-get install libgtkglext1-dev -y && sudo apt-get install v4l-utils -y && sudo apt-get install python2.7-dev -y && sudo pip install numpy && cd ~ && wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip && unzip opencv.zip && wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.2.0.zip && unzip opencv_contrib.zip && cd opencv-3.2.0 && mkdir build && cd build && cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules -D BUILD_EXAMPLES=ON -D ENABLE_NEON=ON .. && sudo make -j$(nproc) && sudo make install && sudo ldconfig && sudo echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf && sudo echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" >> /etc/bash.bashrc && sudo echo "export PKG_CONFIG_PATH" >> /etc/bash.bashrc
This process might take a up to several hours so leave go drink some milk and come back after its done.
After OpenCV is installed we can download our other two libraries we will be using for this project. To download the libraries open the terminal and type pip3 install face_recognition after that is done downloading type pip3 install imutils.
Once all libraries finish downloading we will need to connect the Pi to internet via wifi or ethernet. After connecting your Pi to the internet you can visit this Hackster page on Chromium and download all files under the code tab at the bottom of the project. A folder should be made in the pi folder which should be located in the HomeFolder and labeled FaceRecognition (spelling and capitalization is important).
All the files downloaded under the code section should be placed in this folder along with another folder labeled dataset where all our data for our model will be stored.
This is all the setup we need to begin collecting our data to train the model and actually begin using the device.Collecting Data
To start collecting data create a folder in the dataset folder labeled with your name. This folder will store all the photos we will take with the face_shot.py program and will allow us to train the model. Multiple folders can be created in the dataset folder labeled with multiple names to train the algorithm to identify between different people so that we can have a personalized order for each person.
After creating our folder(s) the face_shot.py should be opened in the Thonny Python IDE. Line 4 of the program:
name = 'Unknown' #replace with your name
should be altered so that the name written exactly how it is on your folder(s) is there.
The face_shot.py program can now be run and will open a camera viewer to adjust yourself in the frame. Press spacebar to begin taking pictures of yourself or someone else in the dataset folder. Press the escape key to finish taking photos. I'd recommend taking at least 1, 000 pictures to train the model to accurately distinguish between the faces in your dataset the more pictures taken the more accurate the model will be. Protip: To take a bunch of photos quickly to speed up data collection spacebar can be held. This will freeze the camera preview but I promise it is still taking photos. After you are satisfied with the quantity of photos there is a possibility the program will say its still taking pictures however this is not true, the print statements are just trying to keep up with the pictures already taken. To quit after holding spacebar press stop instead of escape or wait for the print statements to catch up (might take a minute).
Training the AI model is very simple all that needs to be done is to open train_model.py and run the program. This program will take every folder in the dataset folder and add it to the model with it appropriate name. This process might also take a while depending on how many pictures were taken so go grab some more milk and come back in a few hours to finally use the device.Cereal Time!
Now that the model is trained we can finally eat some sweet grain. Well there is one more step before we can devour our holy nutriment. The orders for every person in the dataset folder need to be set up. The orders are setup in the step.py program at the bottom of the code.
if name == "Unknown":
This if statement is the only thing keeping you from your wheatie treat and in order to make it work in put your name in the statement and create multiple if statements for the others in your dataset folder. Protip: if the line
is inserted in to the if statement you can open multiple motors and mix your cereal combinations together if you like consuming multiple cereals in one bowl. I do not judge. Testing for timings is recommended if you opt for this decision.
if name == "Your Name:
Now that our orders are setup we can finally run the face_rec.py program to release the yeast. No editing needs to be done to this file and should be ready to run. This file will call the step.py program every time it detects a face that matches to the model which will trigger the motors to open. Run the program and finally eat the cereal you so very much deserve.