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
110 Comments
4 years ago
This seems to not work anymore. I've been trying all day to replicate a project I did 4 years ago. Not sure why, but it seems to have something to do with the now google forms update. Using an old google forms works perfectly.
Any ideas why?
Reply 2 years ago
No idea... I have had mine running for 7 years and have not had to change a thing.. Maybe go back and make sure you are doing all the steps correct?
7 years ago
Hi,
i could not find Device ID as you suggested, what i got is in the following picture
Reply 4 years ago
I got that too, Shakir. I'm not sure what goes into that "data" field yet, as it seems to be a required field. But if you go out and view all your Scenarios, you'll find your DeviceID.
Reply 7 years ago
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.
Reply 7 years ago
It didn't worked for me.
Even when I tried test scenario, it pinged on pushingbox but didn't send any data to spreadsheet.
Kindly help.
Thanks in advance :)
Reply 6 years ago
Look at the Arduino code:
change:
char devid = fskjfnfnvkjsdnf to char devid[] = "fskjfnfnvkjsdnf"
Note: this is not a real devid, just use the format. Give that a try and let me know if that works for you.
Reply 7 years ago
It didn't worked for me.
Even when I tried test scenario, it pinged on pushingbox but didn't send any data to spreadsheet.
Kindly help.
Thanks in advance :)
Reply 7 years ago
Please go back and verify all the data you have entered is correct. One typo will prevent the system from working. This is often the cause of errors from what I have seen below. I am assuming this because you are not dealing with the Arduino yet, this is just pushing box to google which should work no problem.
Reply 7 years ago
Reading through other comments, I figured out the problem.
Thanks a lot for this simple yet powerful intractable.
Reply 7 years ago
What was the issue you found?
Reply 7 years ago
I am using this url in my browser to test it : http://api.pushingbox.com/pushingbox?devid=v75503...
Still, on pushingbox dashboard it shows in history, but doesn't upload anything in spreadsheet.
Reply 7 years ago
Thanks for your prompt reply.
Ok, I'll try it out again, double checking my spells. And yes, till now I have not started with arduino and am only stuck at pushingbox.
Question 5 years ago
Hi, I followed the directions and the data is only showing up on the Arduino serial monitor as shown below...
connected
665
GET /pushingbox?devid=vB40D3F7E889C066 &status=665 HTTP/1.1
Host: api.pushingbox.com
Connection: close
disconnecting.
Instead of detecting temperature, we are detecting data from a potentiometer. The data is not showing up on PushingBox nor Google sheets/forms. Thanks in advance!
This is the code...
#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
//#undef DHT11;
//#define DHT11PIN 3
//int v8EEB24ECB8E7028 = A3;
///////////////////////////////
/// EDIT THIS STUFF //
///////////////////////////////
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Replace with your Ethernet shield MAC
byte ip[] = {129, 236, 9, 155}; // Your Arduino device IP address
char devid[] = "vB40D3F7E889C066"; // THIS IS THE DEVICE ID FROM PUSHINGBOX
// delay (10); // 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 chk = DHT11.read(DHT11PIN);
// int temp = Fahrenheit(DHT11.temperature);
// temp_av=temp_av+temp;
// delay(1000);
//}
//int avtemp=temp_av/(del);
//temp_av=0;
// Post to Google Form.............................................
if (client.connect(server, 80))
{
//k=0;
Serial.println("connected");
sprintf(postmsg,"GET /pushingbox?devid=vB40D3F7E889C066 &status=%d HTTP/1.1",analogRead(A3)); // 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.
Serial.println(analogRead(A3));
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;
}
}
double Fahrenheit(double celsius) // Function to convert to Fahrenheit
{
return 1.8 * celsius + 32;
}
6 years ago
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! :)
6 years ago
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);
}
Reply 6 years ago
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!
Reply 6 years ago
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.
Reply 6 years ago
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!
Reply 6 years ago
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.