Post to Google Docs With Arduino

50,526

91

106

Published

Introduction: Post to Google Docs With Arduino

Lets get right into this. I was logging temperature of a room to an Excel sheet via Serial.print commands, then importing CSV files and yada yada. I couldn't get to the data unless I was at home, and also I had to leave my computer running in order to log the data. I needed a better way to log temperature (or anything for that matter) and be able to access it from anywhere.

Google Docs is a great free service that fits the bill perfect. There are tons of tutorials showing how to do this HOWEVER they are all out of date due to Google changing things up on their forms. So I am here to re-write everything I learned to help you get started and logging real time to the internet.

You will need:

Arduino R3

Ethernet shield (probably can be done with a YUN or WiFi, but I used Ethernet.)

** I added a screen shot of my dashboard which displays all the data that I am collecting. This is all based on 3 temperature sensors.**

Step 1: Get Accounts (FREE)

Get the required accounts:

1. Google. Get a google account. its 2014, you should probably have one by now. FREE

2. Get a pushingbox account via pushingbox.com. FREE and it uses you google account for user info.

Step 2: Create a Google Form and Get FORM KEY

Inside of google Drive you can create a 'Form' . For the sake of making this simple. I will create a single question TEXT response form as shown. When that is complete, click send form.

A screen will pop up which will have the option to show URL. Click that then Copy the URL that it spits out. Paste that into your web browser and you will find yourself at the form you created.

From here you will need to right click and select 'Inspect Elements'. This will load the HTML code for the form. You are looking for the line of code that is defining the Text input box. You will find a section of the code that is "entry.12734623852784" (numbers are dependent on your form, I typed nonsense) Take note of this. I will be referring to this as "FORM KEY"

Step 3: Pushingbox, Service and Scenarios

Head over to pushingbox.com and log in with the same google information that you created the form with.

Go to My Services and create a new custom service. You will need to go to your google form and submit a response. This will load the response page of your form. Copy this URL and paste it into the pushingbox Service URL field. Name it whatever you want and set method to GET.

Done.

Now go to my scenarios. This is where the FORM KEY will be used. Following my template, past this into the scenarios field to add:

?entry.1917223082=$status$&submit=Submit Change the bold text with your FORM KEY that you gathered in step 2. Leave the ? and the other stuff, just replace the bold with your stuff. Now copy that whole string and past into the add scenario field. Now click ADD. Then it will say nice job! or something positive like that. Click ADD AN ACTION. Then select the Service you created only moments ago.

This will give you a DEVICE ID remember this, in fact. write it down or copy and paste it into a notepad doc. This will be used in the Arduino code.

Congrats, you are done with that and now its time to code the Arduino.

Step 4: CODE THE ARDUINO

I have attached my very simple code to run this example. You will find a section of things to be edited. This code will send responses to the form you created in the form of data. You will see google then creates a spreadsheet and logs all the responses WITH time stamps! Use this to create data logs of temperature, light levels, humidity, motion whatever you want! The example attached uses a DHT11 thermo/humidity sensor. Can easily be modified for something else.

I hope this lets you walk through the steps and get some data posted to the web.

Thanks

Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Make it Move Contest

      Make it Move Contest
    • Woodworking Contest

      Woodworking Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    106 Comments

    Thank you so much for the easy-to-follow instructable!

    I only have one single tiny question: Instead of pushing data into a spreadsheet, I need to read it. What should I change in the code to allow the arduino to read the spreadsheet?

    Thanks for your time! :)

    I asked a question earlier but deleted it because I found the answer below. However, I have a new question! LOL How do I go about submitting multiple entries? I want humidity, heat index, temperature, and lux to be sent. More will be added later. I don't fully understand the comment below asking about 3 entries. It would be fantastic if you spelled it out for me how you are using multiple commands as you mentioned, or how to go abou using one command? Either or is fine (if I can make it work on my end). If you could just show me how to go about sending my current variable, f, along with the variable h, I think I can take it further and apply it to all the variables I will ultimately be using. Thanks!


    Here is my code, by the way, as adapted for the WiFly library. I'm using an Uno and the Seeeduino WiFi Shield V2.0. This code works (for me) and is only sending one variable for one form question. As detailed in comments below, I am multiplying my float values by 100 and converting to int (for some reason it really didn't like using %f for float). I also made the necessary adjustments to devid and changing %c to %s for string. What you see below is an integration of four different modules, so far. I'm ultimately going to be adding 2 or 3 more sensors, as well as integrating the code with operation of a Relay Shield:

    #include <Adafruit_Sensor.h>

    #include "DHT.h"

    #include <SoftwareSerial.h>

    #include "WiFly.h"

    #include "WiFlyClient.h"

    #include <SPI.h>

    #undef int

    #undef abs

    #undef double

    #undef float

    #undef round

    #define DHTPIN 8 // Digital pin 8 does not conflict with wifi shield or relay shield

    #define DHTTYPE DHT22 // Digital Temp/Humidity Sensor

    #define SENSORPIN A0 // Analog Light Sensor Pin

    #define SSID "myssid"

    #define KEY "mypassword"

    #define AUTH WIFLY_AUTH_WPA2_PSK

    char devid[] = "XXXXXXXX"; // THIS IS THE DEVICE ID FROM PUSHINGBOX

    float rawRange = 1024; // 3.3v

    float logRange = 5.0; // 3.3v = 10^5 lux

    int k=0;

    char postmsg[100];

    char server[] = "api.pushingbox.com";

    SoftwareSerial wiflyUart(2, 3); // create a WiFi shield serial object

    WiFly wifly(&wiflyUart); // pass the wifi siheld serial object to the WiFly class

    DHT dht(DHTPIN, DHTTYPE);

    void setup()

    {

    analogReference(EXTERNAL);

    wiflyUart.begin(9600); // start wifi shield uart port

    Serial.begin(9600);

    Serial.println("Testing Integrations");

    // wait for initilization of wifly

    delay(1000);

    wifly.reset(); // reset the shield

    delay(1000);

    //set WiFly params

    wifly.sendCommand("set ip local 80\r"); // set the local comm port to 80

    delay(1000);

    wifly.sendCommand("set comm remote 0\r"); // do not send a default string when a connection opens

    delay(1000);

    wifly.sendCommand("set comm open *OPEN*\r"); // set the string that the wifi shield will output when a connection is opened

    delay(1000);

    Serial.println("Join " SSID );

    if (wifly.join(SSID, KEY, AUTH)) {

    Serial.println("OK");

    } else {

    Serial.println("Failed");

    }

    /*

    wifly.sendCommand("get ip\r");

    char c;

    while (wifly.receive((uint8_t *)&c, 1, 300) > 0) { // print the response from the get ip command

    delay(50);

    }

    wifly.sendCommand("get ip\r");

    while (wifly.receive((uint8_t *)&c, 1, 300) > 0) { // print the response from the get ip command

    Serial.print((char)c);

    delay(50);

    }

    */

    Serial.println("Web server ready");

    dht.begin();

    }

    void loop(){

    // read the raw value from the sensor twice to get 2000ms delay:

    int rawValue = analogRead(SENSORPIN);

    Serial.print("Raw = ");

    Serial.print(rawValue);

    Serial.print(" - Lux = ");

    Serial.println(RawToLux(rawValue));

    delay(1000);

    // Reading temperature or humidity takes about 250 milliseconds!

    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

    float h = dht.readHumidity();

    // Read temperature as Fahrenheit (isFahrenheit = true)

    float f = dht.readTemperature(true);

    // Check if any reads failed and exit early (to try again).

    if (isnan(h) || isnan(f)) {

    Serial.println("Failed to read from DHT sensor!");

    return;

    }

    // Compute heat index in Fahrenheit (the default)

    float hif = dht.computeHeatIndex(f, h);

    Serial.print("Humidity: ");

    Serial.print(h);

    Serial.print(" %\t");

    Serial.print("Temperature: ");

    Serial.print(f);

    Serial.print(" *F\t");

    Serial.print("Heat index: ");

    Serial.print(hif);

    Serial.println(" *F");

    // Post to Google Form.............................................

    Serial.println("Attempting to post data to form");

    if (wifly.connect(server, 80))

    {

    k=0;

    Serial.println("connected");

    sprintf(postmsg,"GET /pushingbox?devid=%s&status=%d HTTP/1.1",devid,int(f*100)); // NOTE** In this line of code you can see where the temperature value is inserted into the wed address. It follows 'status=' Change that value to whatever you want to post.

    wifly.println(postmsg);

    wifly.println("Host: api.pushingbox.com");

    wifly.println("Connection: close");

    wifly.println();

    Serial.println(postmsg);

    Serial.println("Host: api.pushingbox.com");

    Serial.println("Connection: close");

    Serial.println();

    delay(1000);

    } else {

    Serial.println("failed.");

    k=1;

    }

    delay(1000);

    }

    //function declarations

    float RawToLux(int raw)

    {

    float logLux = raw * logRange / rawRange;

    return pow(10, logLux);

    }

    4 replies

    Currently, I found a workaround where I use if else statements. I have it set up to check if number of iterations is 0. if yes, send humidity data. else, if number of iterations is 1, send temperature data. I end with an else statement that sets iterations back to 0 so that the iteration count resets once I've systematicaly sent all the data i wanted to send. It's a bit of a bear to look at code-wise, but it works. I'm sending data for 4 different questions. Still, I'd really like to know a concise way to go about this. Thanks!

    I have mine sending 3 commands currently at home. I will send you the code I used for that and show how I just copied the section of code 3 times and changed some variables.

    I actually figured it out. Thanks for posting this! My senior design project was quite successful, and I owe it to this Instructable and other open-source modules such as this. Thank you so much!

    If you set up enough variables to accept more sensors you can then set up a google form to ask for multiple questions. One question for each sensor input. So you would just repeak the same steps for each form question. Generate a new scenario in pushing box for each as if they were separate. Then in the Arduino code you just copy this section however many times you need:

    if (wifly.connect(server, 80))

    {

    k=0;

    Serial.println("connected");

    sprintf(postmsg,"GET /pushingbox?devid=%s&status=%d HTTP/1.1",devid,int(f*100)); // NOTE** In this line of code you can see where the temperature value is inserted into the wed address. It follows 'status=' Change that value to whatever you want to post.

    wifly.println(postmsg);

    wifly.println("Host: api.pushingbox.com");

    wifly.println("Connection: close");

    wifly.println();

    Serial.println(postmsg);

    Serial.println("Host: api.pushingbox.com");

    Serial.println("Connection: close");

    Serial.println();

    delay(1000);

    } else {

    Serial.println("failed.");

    k=1;

    }

    Might take some clean up but thats essentially how I have mine set up to run multiple. I saw some people below got it done with a single command but I didn't try that.

    user

    How would you change the code so that a moisture sensor can be used? Or which part of the code must be changed?

    7 replies

    You would change the temperature read section. Switch over to reading the moisture sensor and pass along the correct variables.

    user

    This is what I changed it to. Is it correct?

    #include <SPI.h>

    #include <Ethernet.h>

    #include <EthernetUdp.h>

    #include <SPI.h>

    #include <dht11.h>

    #undef int

    #undef abs

    #undef double

    #undef float

    #undef round

    dht11 DHT11;

    #define DHT11PIN 3

    ///////////////////////////////

    /// EDIT THIS STUFF //

    ///////////////////////////////

    byte mac[] = {b8:27:eb:4a:9e:87 }; //Replace with your Ethernet shield MAC

    byte ip[] = {123,456,7,890}; // Your Arduino device IP address

    char devid = v1A7BB8AE7429BCA // THIS IS THE DEVICE ID FROM PUSHINGBOX

    int del=300; // Amount of seconds delay between posting to google docs.

    ///////////////////////////////

    // DONE EDITING //

    ///////////////////////////////

    char postmsg[100];

    int k=0;

    int temp_av = 0;

    char server[] = "api.pushingbox.com";

    EthernetClient client;

    void setup()

    {

    Serial.begin(9600);

    Ethernet.begin(mac, ip);

    delay(1000);

    Serial.println("connecting...");

    }

    void loop(){

    // average temp reading for 'del' time.........................................

    for(int j=0; j<del;j++)

    {

    // Read local temp........................................

    int sensorPin = 0; // select the input pin for the potentiometerint sensorValue = 0; // variable to store the value coming from the sensorvoid setup() { // declare the ledPin as an OUTPUT: Serial.begin(9600); }void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin); delay(1000); Serial.print("sensor = " ); Serial.println(sensorValue); }

    // Post to Google Form.............................................

    if (client.connect(server, 80))

    {

    k=0;

    Serial.println("connected");

    sprintf(postmsg,"GET /pushingbox?devid=%c&status=%d HTTP/1.1",devid,sensorValue); // NOTE** In this line of code you can see where the temperature value is inserted into the wed address. It follows 'status=' Change that value to whatever you want to post.

    client.println(postmsg);

    client.println("Host: api.pushingbox.com");

    client.println("Connection: close");

    client.println();

    Serial.println(postmsg);

    Serial.println("Host: api.pushingbox.com");

    Serial.println("Connection: close");

    Serial.println();

    delay(1000);

    client.stop();

    }

    delay(1000);

    if (!client.connected())

    {

    Serial.println();

    Serial.println("disconnecting.");

    client.stop();

    k==1;

    return;

    }

    }

    You need to do some clean up, you have two setup() and loop() functions shown. The idea looks right if your moisture sensor is on pin 0. Just collect data from the moisture sensor and assign it to a variable. Then send that variable accross to pushing box. Looks like you replaced the avtemp variable with sensor variable so that's good. I say do a little clean up and give it a go.

    user

    I'm sorry for all the questions!

    char postmsg[100];

    int k=0;

    int temp_av = 0;

    char server[] = "api.pushingbox.com";

    EthernetClient client;

    void setup()

    {

    Serial.begin(9600);

    Ethernet.begin(mac, ip);

    delay(1000);

    Serial.println("connecting...");

    for(int j=0; j<del;j++)

    int sensorPin = 0; // select the input pin for the potentiometerint sensorValue = 0; // variable to store the value coming from the sensor }

    void loop(){

    // Read local temp........................................

    // read the value from the sensor:

    sensorValue = analogRead(sensorPin);

    delay(1000);

    Serial.print("sensor = " );

    Serial.println(sensorValue); }

    Is the setup okay?

    You need ethernet for the code to work.

    user

    What exactly is a arduino device IP?

    user

    Additionally, is an ethernet shield board required for the code to work?

    Thanks. Really well explained and has allowed me to add data logging to my home automation system.

    1 reply

    Glad it helped! thanks!

    Hi,

    I modified your code to work with my digital read sensor and the wifi client but when the sketch runs nothing gets entered into the spreadsheet (Pushingbox test inserts "$status$")

    Serial prints out:

    connected

    GET /pushingbox?devid=�&status=1 HTTP/1.1

    Host: api.pushingbox.com

    Connection: close

    My code:

    https://create.arduino.cc/editor/Bernstern/f785f94...

    Any help would be greatly appreciated!

    1 reply

    Your sendtopushingbox() function is messed up. Go back to the code I supplied and look how I have it set up during the push command. Try re-writting that section of code.

    Hi,

    i could not find Device ID as you suggested, what i got is in the following picture

    Capture.JPG
    1 reply

    Past this string in the Data field:

    ?entry.1917223082=$status$&submit=Submit

    Make sure you update it to match your data. This is the same string you used a few steps earlier. Let me know if this helps.