Save Arduino data to spreadsheets


We'll show you how to make your Arduino add rows of data to a Google spreadsheet. You can use this to log data from sensors connected to your Arduino, like temperature readings over time, or other instances where your Arduino is receiving information you'd like to record.

This sketch uses our Google > Sheets > AppendValues Choreo.

Get Set Up

1Make sure you have a Temboo account. If you don't already have one, you can register for free.

2Make sure that you have the latest version of the Arduino IDE. You should also check that you have the newest version of the Temboo Library by checking the Arduino Library Manager

3Since this sketch uses a Google spreadsheet, you'll also need a Google account.

4Login to Google's Developer Console, and create a new Project if you haven't done so already.

5Under the API Manager section, select Library and make sure you've enabled API Access for the Google Sheets API.

6Select Credentials in the API Manager section, and create a new Client ID specifying Web application for the Application Type.

7When configuring the Consent Screen, make sure you fill out the Email Address and Product Name fields.

8Save the Consent Screen details and specify the callback URL below as the Authorized Redirect URI. Make sure to replace ACCOUNT_NAME with your Temboo account name.

https://ACCOUNT_NAME.temboolive.com/callback/google

9Go to the Google > OAuth > InitializeOAuth Choreo page, and fill in the Client ID from the app you registered at Google and the following Scope: https://www.googleapis.com/auth/spreadsheets . Then click Generate Code to run the Choreo from our site.

Google OAuth Inputs

The InitializeOAuth choreo will return an authorization URL and a callback ID (required for the FinalizeOAuth step).

10Open a new web browser, navigate to the authorization URL returned by the InitializeOAuth Choreo, and click "Accept" to grant the app access to your Google account.

Google OAuth Accept

11Go to the Google > OAuth > FinalizeOAuth Choreo page and fill in the callback ID returned earlier by the InitializeOAuth Choreo. Then, click Generate Code to run the Choreo from our site. This process will return a Refresh Token which can be used along with the Client ID and Client Secret to authenticate with Google.

12Create a Google Spreadsheet. When viewing your spreadsheet, you'll see a spreadsheet ID in your browser's URL bar. Copy this ID because you'll need it when running the AppendValues Choreo. In the example below, the highlighted part is the Spreadsheet ID.

Google Spreadsheet

Auto-Generate the Sketch

13Go to the Google > Sheets > AppendValues in our Library.

14Select Arduino from the drop down menu at the top of the Choreo page, then choose your Arduino device. Make sure that you've added details about how your Arduino will connect to the internet.

Selecting your Arduino configuration

15Click Generate Code to test out the Choreo from our website and confirm that your Google Spreadsheet was updated successfully.

Google Spreadsheets Inputs

Testing the AppendValues Choreo from our website

16When you've confirmed that the Choreo runs successfully, you can copy the auto-generated Arduino code from the Code section and paste it into your Arduino IDE.

17The auto-generated sketch references the TembooAccount.h header file, which contains your Temboo account information and internet shield details. You'll find the code for this file beneath your generated sketch. Create a new tab in the Arduino IDE called TembooAccount.h and copy in the header file information.

Run The Sketch

18With both files in place you are ready to upload the sketch and start adding data to your spreadsheet. Time to get logging!

Extending The Sketch

You'll notice that your sketch always sends the same value to your spreadsheet. Of course, it's far more interesting to send dynamic values i.e., sensor values. Here's an example of what you need to do to make that happen.

19Add the follow line of code to your setup() method so that you're reading the value on pin A0:

pinMode(A0, INPUT);

20Next, replace the line of code that currently adds data to your spreadsheet with the following three lines so that your sketch reads the value on pin A0 and adds it to the spreadsheet instead:

String sensorValue = String(analogRead(A0));
String ValuesValue = "[[\"" + sensorValue + "\"]]";
AppendValuesChoreo.addInput("Values", ValuesValue);

21That's it! Now your sketch should be generating dynamic values and adding them to your Google Spreadsheet.

What's Next?

Now that you've mastered working with Google Spreadsheets, why not check out the rest of the 2000+ Choreos in our Library and get inspired for your next project.

Need Help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.


Back