Looking to create ‘the next big thing’? Look no further than TI's Maker and DIY community! Launch your design with TI's low-cost, community-supported development platforms. Begin rapid prototyping applications in minutes with our microcontroller-based LaunchPad kits, Sitara™-processor-powered BeagleBoards and SimpleLink™ wireless connectivity SensorTags.
Have you ever found yourself mindlessly snacking not even realizing what, or how frequently you are eating? Even worse, have you ever had something in the fridge that you are excited to eat and when you go to take it out you realize someone else already beat you to it?
Consider these problems of the past with this new refrigerator alarm. By utilizing a Texas Instruments Launchpad™ development kit, SimpleLink™ Wi-Fi® CC3100 BoosterPack™, Educational BoosterPack MKII and services provided by Temboo, we will be able to track every time the refrigerator is opened and document it to a spreadsheet on Google Drive.
Demo of the finished product!
1. Get Temboo and Google talking:
The first step in getting our refrigerator monitor up and running is to register for a Temboo account. Temboo is a service that makes interacting with many APIs seamless and is great for Internet of Things (IoT) development. For our refrigerator monitor, we will be using the Google spreadsheet API which can be found by navigating to "Google" on the left pane and selecting "Spreadsheets". In order to use this Google Choreo there a few steps to set up OAuth so that Temboo can talk to the Google API. The steps for setting up OAuth are found on the Spreadsheets Choreo page (this requires a Google account). Make sure to take note of the ClientID, ClientSecret, and RefreshToken as you need all of these in the next step.
2. Create the Google Spreadsheet:
In the same Google account used to set up the API, navigate to the Google Drive page. Create a new Google Sheet and give it a title that is easy to remember (you are going to need it later). Open the spreadsheet to make a few changes. We are going to use the AppendRow Choreo, which adds information below the last full row using comma separated values and inserting information into only columns that have a title. Because of this, we want to set up our column titles so we know what our imported data is. For this example, we import a timestamp using epoch time (more about this later) in the first column and the LUX (measurement of light) value read by the sensor in the second column. The last step is to select the whole first column by clicking the letter 'A'. Go to Format --> Number and select "Date Time". This will cause Google to change the imported epoch time value into a readable date and time. Now the spreadsheet is ready to receive data and should look something like the image below.
3. Get The Choreo Running:
After finishing up the OAuth portion and spreadsheet set up, it is time to get our Choreo talking to Google. Navigate to the AppendRow Choreo from the Spreadsheets Choreo page. Fill in all the information obtained when running through the OAuth section. For "RowData", you can enter a place holder so that it can be edited in code later with the timestamp and LUX values. "SpreadsheetTitle" has to match the spreadsheet that we created in the previous section. Next, run the Choreo as a test. You should get a "success" return at this point and see the spreadsheet update with whatever was in "RowData". If it did not work, it is most likely an issue with the OAuth process that can be solved by running through the steps again. Once we have successfully run the Choreo on the web, it is time to get it set up on the LaunchPad kit.
4. Coding the LaunchPad kit:
At this point, Temboo provides the base code to append a row to an existing spreadsheet. This takes a lot of work out of setting up the API, but the fun of using Temboo to solve a problem still remains. In order to create this refrigerator monitor we are going to use the OPT3001 optical sensor on the Educational BoosterPack and Energia multitasking, which is new on the MSP432 LaucnhPad kit. Multitasking allows individual sketches to run simultaneously on the same LaunchPad kit and even allows different LaunchPad development kits to interact with each other. In this case we are going to have one tab called fridgeAlarm which is set up to monitor the optical sensor and append a row to the Google sheet on an event trigger. The other tab, called epochTime, is going to use Wi-Fi to ping a time server and return the current time in epoch time, which is the number of seconds that has passed since January 1, 1970.
The code below, called fridgeAlarm.ino, is the main function of the multitasked program. It initializes all of the variables and sets up the Wi-Fi connection as well as the optical sensor. Download and open the code or copy and paste it into a blank Energia sketch. Read through downloaded code and compare it to the code provided on the Temboo site. The code is very similar with a few exceptions, such as allowing the optical sensor to trigger the event and setting up the data to be appended to the spreadsheet.
The maxLux value may need to be changed based on how bright your refrigerator light is. Make sure that it doesn't trigger when it is closed and it does trigger when it is open. A value of 100 should work as long as the optical sensor is exposed to the light bulb.
Line 86 begins a block of variables that you will need to fill in using the values provided by the Temboo AppendRow Choreo page. The lines that need to be changed are clarified with an "Edit Needed" comment along the side.
Line 90 does math that converts epoch time to a value Google can use. Notice the variable timeZoneShift declared at the top of the page. This needs to be changed to match your difference from GMT (I used -5 for CDT).
Now it is time to initialize the second task called epochTime. First, create a new tab in the Energia sketch as shown below.
Rename the tab epochTime to keep everything straight as seen below:
Now we should have two separate tabs that can run side by side! Copy the code listed below epochTime.ino and paste it into this new tab. This code shouldn't need any changes, but if the time server is down the IP address can be changed to a different server. A list of servers can be found here.
Temboo uses a library to fill in your account information and communicate with your LaunchPad development kit. Make sure to copy TembooAccount.h to where your local Energia libraries are stored prior to running the code. Another example can be found here.
After getting both tabs set up the code should be ready to run! Flash your LaunchPad kit and set up your alarm in the refrigerator. Every time someone opens the refrigerator and the optical sensor triggers an event, a row will be appended to the Google spreadsheet containing the time that the refrigerator was opened as well as the LUX value detected when the refrigerator was opened. No more night time pests stealing all your favorite leftovers!
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.