Most of the times, when I want to buy it from grocery I can't remember which cooking ingredient (onion, garlic, chili etc.) is running low and some cases I buy wrong item such as garlic instead of onion. When I reach at my kitchen I observe that, I have a plenty of onion but no garlic. How will you feel in such a situation?
To get rid from such situation I built a Smart Pantry and now I can monitor the amount of every ingredients of my pantry with my smart phone when I am in grocery shop or anywhere out of my kitchen. Busy life, easy solution!!!
In this instructable I will show the recipe of my Smart Pantry. Before going to the details recipe enjoy my demo video.
Step 1: You Need...
1. Arduino UNO (Sparkfun) : Arduino uno will take analog input from the sensors, calculate weight, humidity and temperature. After calculation arduino will send the data to raspberry pi using serial port. If you have an Arduino MKR1000 or Arduino wifi 101 shield then you don't need to use raspberry pi.
2. Raspberry Pi (Sparkfun) : Raspberry pi receives the data from arduino and sends all data to Samasung Artik cloud using WebSocket protocol. Node.js will be used to implement WebSocket protocol in raspberry pi.
3. Force Sensitive Resistor (Sparkfun) : Main sensors for our project. Arduino calculates approximate amount of an ingredient in the pantry with the help of these sensors.
4. Grove Temperature and Humidity Sensor (SeeedStudio) : This is optional. If you want to monitor temperature and humidity of the pantry then you need this.
5. 10k Resistor
For the project you will be required some previous experience on Android application development in Android Studio. You will also require some experience on working with Raspberry Pi.
Step 2: Attaching Sensors (FSR)
FSR: FSRs are sensors that allow you to detect physical pressure, squeezing and weight. They are simple to use and low cost. FSR's are basically a resistor that changes its resistive value (in ohms Ω) depending on how much its pressed. These sensors are fairly low cost, and easy to use but they're rarely accurate. They also vary some from sensor to sensor perhaps 10%. So basically when you use FSR's you should only expect to get ranges of response. While FSRs can detect weight, they're a bad choice for detecting exactly how many pounds of weight are on them.The FSR used here is a force sensitive resistor with a round, 0.5" diameter, sensing area. and its resistance will be larger than 1MΩ. This FSR can sense applied force anywhere in the range of 100g-10kg.
I took a 3 compartment box for my demo project and it can house three different ingredients into it's three separate box. So, for measuring weight of each ingredient three force sensitive resistors are required. Though FSR is not very accurate for weight measurement but for this project very precise weight measurement is not required.
Photos attached here shows how I placed fsr in the box. I placed one fsr below each compartment and tried to put it at the center of the compartment. Using mini drill I made two holes for every sensor to bring out the pin of the sensor out of the box. Then I soldered jumper wire to each pin of the sensors to connect it with Arduino.
Step 3: Attaching Sensors (cont...)
Do the same thing for all three sensors I explained in previous step. Then place all three inner boxes to the base box.
Step 4: Preparing Pantry
Force sensitive resistor change its value when a force is applied to it. Pressure from a hard surface is not good for FSR and you will not get accurate result. For better output I place a small piece of foam on the bottom of every inner box using double sided tape. Place it in such position that it exactly be on the sensor.
Step 5: Connecting Arduino & Raspberry Pi
Output of the FSRs are analog so arduino analog pi is required to read the value from the sensors. Arduino calculates weight in grams from the sensor reading. For remote access of any value you have to put it in a server. For the purpose I will upload all values to Artik Cloud. For uploading the data to the cloud Raspberry Pi was used. Arduino sends data to raspberry pi using serial port. Raspberry pi then upload the data to Artik cloud using WebSocket protocol.
For reading sensor values and sending to raspberry pi upload the attached sketch to your arduino board.
Step 6: Setup Raspberry Pi
To work with the project you need some previous experience working with Raspberry Pi.
1. Install Node.js and NPM to your raspberry pi using the following command.
sudo apt-get install nodejs npm
2. Install WebSocket module to your raspberry pi using following command
npm install --save ws
3. Install serialport module to your raspberry pi using following command
sudo npm install serialport --unsafe-perm --build-from-source
4. Download smart-pantry.js and open with any text editor. Replace device id and device token with your own device id and device token and save it. Upload the modified file to your raspberry pi using any ftp client. Follow next step to get your own device id and device token.
Step 7: Getting Device ID and Token From Artik Cloud
First, you need to create an account to https://accounts.artik.cloud/. After creating an account login to the account. You will get following interface.
First you have to create a new Device type in Artik Cloud server. To do so follow the steps
1. Click on Device Types
2. Give a device display name (smart-pantry in my case), unique name (com.smart.pantry) and then click on CREATE DEVICE TYPE
3. Then, click on NEW MANIFEST
4. Give a field name (the data field or variable for your data received from raspberry pi), select a data type and unit of measurement. Now, click on SAVE
5. Click on NEW FIELD and add as many field as your requirement
6. After creating all data field as your requirement now, click DEVICE ACTION
7. Ignore this step (no action is required for this project), just click on ACTIVE MANIFEST
8. Again click on ACTIVE MANIFEST. Be sure you have created all the necessary field. Manifest is not editable.
9. After activating manifest you will observe following information about your created device. You just created a new device and now you have to connect the device to your account. To connect the device follow the next steps.
10. From your cloud account, click on Devices
11. Click to Add Another Device. This interface may different in your case as it is the first time you are connecting a device. I already connected a deice named raspberry-pi.
12. Type the name of your device created earlier and select your device from drop down.
13. Then click on CONNECT DEVICE
14. My device smart-pantry is now connected. Probably you are also connected like me. Click on the connected device to get device id and device token.
15. You will get following window. You device id is ready. To get device token click on GENERATE DEVICE TOKEN. Your device id and device token is very important and will be required to upload data to cloud and we will use this id in our program used in raspberry pi.
16. Click on SAVE CHANGES.
17. Congratulation!!!, Artik cloud is now ready to receive our data and we have device id and device token to access Artik cloud.
Copy the device id and device token. Replace DEVICE ID & DEVICE TOKEN in the smart-pantry.js file with your own device ID and device token you just copied from your Artik device. Now, you are ready to run the code in raspberry pi using following command.
sudo node smart-pantry.js
After successfully publishing the data to your artik device you will see your data in json format from Artik DATA LOGS menu like following.
Step 8: Create an Application to Artik Cloud
Before going to develop an Android application we will be required to create an application to Artik cloud. After creating an application we will get a client id which will be used to read data from artik cloud using Android app.So, let's create an application in artik cloud. Login to artik cloud and follow the steps below.
1. From the developer console select Application.
2. Click on NEW APPLICATION
3. Give an APP NAME. Description section is optional. Fill another options according as image and click to SAVE APPLICATION.
4. Select Read from PERMISSION. Type your device name into DEVICE PERMISSION box and select your device.
5. Set Read permission for your device and then click to SAVE.
6. To get client id click on SHOW CLIENT ID & SECRET button. Client id is important and will be required at the time of android app development.
7. Note your client ID from the Client ID & Secret window.
We are now ready to develop android application with our own client ID. So, go to the next step.
Step 9: Developing Android App
I designed the android application in Android Studio Environment. Full source code with Artik SDK is attached in below. You need some previous experience in Android application development to work with source code. Build APK is also attached for testing.
1. Download Android Studio from Android Developer page.
2. Unzip the zip archive and open with Android Studio. You can modify the user interface if you like.
3. From the MessageActivity.java replace RDEVICE_ID with your own device id and ACCESS_TOKEN with your own access token.
4. From the MainActivity.java replace CLIENT_ID with your own client id.
Save all, build apk and install it to your smart phone.