ESP32 Publish Sensor Readings to Google Sheets (ESP8266 Compatible)

In this tutorial we’re going to show you how to publish sensor readings to Google Sheets using ESP32 or ESP8266 board. As an example, we’ll publish temperature, humidity, and pressure readings using the BME280 sensor to a Google Sheets spreadsheet every 30 minutes – we’ll be using IFTTT.

You can use IFTTT to integrate with Google Sheets, but at the moment we recommend integrating with Google Sheets using a Google Service Account instead. We recommend following this tutorial: ESP32 Datalogging to Google Sheets (using Google Service Account).

Project Overview

The following figure shows an overview of what you’ll achieve by the end of this project.

  • First, the ESP connects to your Wi-Fi network;
  • Then, the BME280 takes the temperature, humidity, and pressure readings;
  • Your ESP32 or ESP8266 communicates with the IFTTT Webhooks service that publishes the readings to a spreadsheet on Google Sheets that is saved in your Google Drive’s folder;
  • After publishing the readings, the ESP goes into deep sleep mode for 30 minutes;
  • After 30 minutes the ESP wakes up;
  • After waking up, the ESP connects to Wi-Fi, and the process repeats.

Creating Your IFTTT Account

For this project we’ll be using IFTTT to integrate with Google Sheets. So, the first step is creating an account on IFTTT if you don’t have one. Creating an account on IFTTT is free!

Go the official site: ifttt.com and enter your email to get started.

Creating an Applet

Next, you need to create a new applet. Follow the next steps to create a new applet:

1) Go to “My Applets”and create a new applet by clicking the “New Applet” button.

2) Click on the “this” word that is in a blue color – as highlighted in the figure below.


3) Search for the “Webhooks” service and select the Webhooks icon.

4) Choose the “Receive a web request” trigger.

5) Give a name to the event. In this case “bme280_readings” as shown in the figure below. Then, click the “Create trigger” button.

6) Click the “that” word to proceed.

7) Search for the “Google Sheets” service, and select the Google Sheets icon.

8) If you haven’t connected with the Google Sheets service yet, you need to click the “Connect” button.

9) Choose the “Add a row to spreadsheet” action.

10) Then, complete the action fields. Give the spreadsheet a name, leave the “Formatted row” field as default, and then, choose a Google Drive folder path. If you leave this field empty, IFTTT will create a folder called “IFTTT” in your Google Drive folder to save the spreadsheet. Finally, click the “Create action” button.

11) Your applet should be created after you press the “Finish” button.

Testing Your Applet

Before proceeding with the project, it is very important to test your applet first. Follow the next steps to test your applet.

1) Go to the Webhooks Service page, and click the “Documentation” button.

2) A page as shown in the following figure will appear. The page shows your unique API key. You shouldn’t share your unique API key with anyone.

Fill the “To trigger an Event” section as shown below – it is highlighted with red rectangles. Then, click the “Test it” button.

3) The event should be successfully triggered, and you’ll get a green message as shown below saying “Event has been triggered”.

4) Go to your Google Drive. The IFTTT service should have created a folder called “IFTTT” with the “BME280_Readings” spreadsheet inside.

5) Open the spreadsheet, and you should see the values you’ve filled previously to test the applet.

Continue reading this post to see how to integrate the IFTTT Google Sheets service with your ESP32 or ESP8266.

Parts Required

For this example we’ll take sensor readings from the BME280 sensor. Here’s a list of parts you need to build the circuit for this project:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Schematics

The BME280 sensor we’re using in this example can communicate with the ESP32/ESP8266 using I2C communication protocol. So, we’re going to use the ESP I2C pins.

BME280 with ESP32

Follow the next schematic diagram to wire the BME280 sensor if you’re using an ESP32.

(This schematic uses the ESP32 DEVKIT V1 module version with 36 GPIOs – if you’re using another model, please check the pinout for the board you’re using.)

Recommended reading: ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)

BME280 with ESP8266

Follow the next schematic diagram if you’re using an ESP8266 12E.

Note: to use deep sleep with the ESP8266, you need to wire D0 (GPIO16) to the RST pin.

Recommended reading: ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)

Installing the BME280 library

To take readings from the BME280 sensor module we’ll use the Adafruit_BME280 library. Follow the next steps to install the library in your Arduino IDE:

Open your Arduino IDE and go to Sketch Include Library > Manage Libraries. The Library Manager should open.

Search for “adafruit bme280 ” on the Search box and install the library.

Installing the BME280 library Arduino IDE

Installing the Adafruit_Sensor library

To use the BME280 library, you also need to install the Adafruit_Sensor library. Follow the next steps to install the library in your Arduino IDE:

Go to Sketch Include Library > Manage Libraries and type “Adafruit Unified Sensor” in the search box. Scroll all the way down to find the library and install it.

Installing Adafruit Unified Sensor library Arduino IDE

After installing the libraries, restart your Arduino IDE.

Code

There’s an add-on for the Arduino IDE allows you to program the ESP32 using the Arduino IDE and its programming language. Follow one of the next tutorials to prepare your Arduino IDE, if you haven’t already.

After making sure you have the ESP32 add-on installed, you can copy the following code to your Arduino IDE. But don’t upload it yet! You need to make a few modifications to make it work for you.

Note: this code works both with the ESP32 and the ESP8266.

/*
 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com
 */
 
#ifdef ESP32
  #include <WiFi.h>
#else
  #include <ESP8266WiFi.h>
#endif

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// Replace with your SSID and Password
const char* ssid     = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Replace with your unique IFTTT URL resource
const char* resource = "REPLACE_WITH_YOUR_IFTTT_URL_RESOURCE";

// How your resource variable should look like, but with your own API KEY (that API KEY below is just an example):
//const char* resource = "/trigger/bme280_readings/with/key/nAZjOphL3d-ZO4N3k64-1A7gTlNSrxMJdmqy3";

// Maker Webhooks IFTTT
const char* server = "maker.ifttt.com";

// Time to sleep
uint64_t uS_TO_S_FACTOR = 1000000;  // Conversion factor for micro seconds to seconds
// sleep for 30 minutes = 1800 seconds
uint64_t TIME_TO_SLEEP = 1800;

// Uncomment to use BME280 SPI
/*#include <SPI.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10*/

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

void setup() {
  Serial.begin(115200); 
  delay(2000);

  // initialize BME280 sensor
  bool status;
  status = bme.begin(0x76);  
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  initWifi();
  makeIFTTTRequest();
    
  #ifdef ESP32
    // enable timer deep sleep
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);    
    Serial.println("Going to sleep now");
    // start deep sleep for 3600 seconds (60 minutes)
    esp_deep_sleep_start();
  #else
    // Deep sleep mode for 3600 seconds (60 minutes)
    Serial.println("Going to sleep now");
    ESP.deepSleep(TIME_TO_SLEEP * uS_TO_S_FACTOR); 
  #endif
}

void loop() {
  // sleeping so wont get here 
}

// Establish a Wi-Fi connection with your router
void initWifi() {
  Serial.print("Connecting to: "); 
  Serial.print(ssid);
  WiFi.begin(ssid, password);  

  int timeout = 10 * 4; // 10 seconds
  while(WiFi.status() != WL_CONNECTED  && (timeout-- > 0)) {
    delay(250);
    Serial.print(".");
  }
  Serial.println("");

  if(WiFi.status() != WL_CONNECTED) {
     Serial.println("Failed to connect, going back to sleep");
  }

  Serial.print("WiFi connected in: "); 
  Serial.print(millis());
  Serial.print(", IP address: "); 
  Serial.println(WiFi.localIP());
}

// Make an HTTP request to the IFTTT web service
void makeIFTTTRequest() {
  Serial.print("Connecting to "); 
  Serial.print(server);
  
  WiFiClient client;
  int retries = 5;
  while(!!!client.connect(server, 80) && (retries-- > 0)) {
    Serial.print(".");
  }
  Serial.println();
  if(!!!client.connected()) {
    Serial.println("Failed to connect...");
  }
  
  Serial.print("Request resource: "); 
  Serial.println(resource);

  // Temperature in Celsius
  String jsonObject = String("{\"value1\":\"") + bme.readTemperature() + "\",\"value2\":\"" + (bme.readPressure()/100.0F)
                      + "\",\"value3\":\"" + bme.readHumidity() + "\"}";
                      
  // Comment the previous line and uncomment the next line to publish temperature readings in Fahrenheit                    
  /*String jsonObject = String("{\"value1\":\"") + (1.8 * bme.readTemperature() + 32) + "\",\"value2\":\"" 
                      + (bme.readPressure()/100.0F) + "\",\"value3\":\"" + bme.readHumidity() + "\"}";*/
                      
  client.println(String("POST ") + resource + " HTTP/1.1");
  client.println(String("Host: ") + server); 
  client.println("Connection: close\r\nContent-Type: application/json");
  client.print("Content-Length: ");
  client.println(jsonObject.length());
  client.println();
  client.println(jsonObject);
        
  int timeout = 5 * 10; // 5 seconds             
  while(!!!client.available() && (timeout-- > 0)){
    delay(100);
  }
  if(!!!client.available()) {
    Serial.println("No response...");
  }
  while(client.available()){
    Serial.write(client.read());
  }
  
  Serial.println("\nclosing connection");
  client.stop(); 
}

View raw code

Including your SSID and password

The first thing you need to modify in the code is writing your network credentials: the SSID and password on the following lines:

// Replace with your SSID and Password
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

Including your unique IFTTT URL resource

Then, you need to write your unique IFTTT URL resource. Go back to “Testing your Applet” section bullet 2) to get your unique IFTTT URL resource.

// Replace with your unique IFTTT URL resource
const char* resource = "REPLACE_WITH_YOUR_IFTTT_URL_RESOURCE";

In my case, my resource is:

/trigger/bme280_readings/with/key/nAZjOphL3d-ZO4N3k64-1A7gTlNSrxMJdmqy3

So, that line in the code looks as follows:

const char* resource = "/trigger/bme280_readings/with/key/nAZjOphL3d-ZO4N3k64-1A7gTlNSrxMJdmqy3";

Setting the sleep time

In this example we’ve set the sleep time to 30 minutes. This means that every 30 minutes the ESP wakes up, takes the readings, and publishes in your Google Sheets spreadsheet. The sleep time is set in the TIME_TO_SLEEP variable in seconds:

// sleep for 30 minutes = 1800 seconds
uint64_t TIME_TO_SLEEP = 1800;

If you want to change the sleep time, you need to change the TIME_TO_SLEEP variable. Note that you should enter the sleep time in the TIME_TO_SLEEP variable in seconds.

Warning: be careful setting the sleep time. If you set a very short period, you may exceed the limit of requests imposed the IFTTT service.

Sending the BME280 readings

The BME280 sensor readings are sent using the jsonObject variable as shown in the following line:

String jsonObject = String("{\"value1\":\"") + bme.readTemperature() + "\",\"value2\":\"" + (bme.readPressure()/100.0F) + "\",\"value3\":\"" + bme.readHumidity() + "\"}";

Publish temperature in Fahrenheit

In order to publish the temperature in Fahrenheit, you need to comment and uncomment the code like this:

// Temperature in Celsius
/*String jsonObject = String("{\"value1\":\"") + bme.readTemperature() + "\",\"value2\":\"" + (bme.readPressure()/100.0F) + "\",\"value3\":\"" + bme.readHumidity() + "\"}";*/

// Comment the previous line and uncomment the next line to publish temperature readings in Fahrenheit 
String jsonObject = String("{\"value1\":\"") + (1.8 * bme.readTemperature() + 32) + "\",\"value2\":\"" + (bme.readPressure()/100.0F) + "\",\"value3\":\"" + bme.readHumidity() + "\"}";

Demonstration

After making all the necessary changes. Upload the code to your ESP32 or ESP8266. Make sure you select the right board and COM port.

Every 30 minutes, the ESP32 or ESP8266 wakes up to take sensor readings and publishes the readings in a spreadsheet on Google Sheets.

The ESP32 chip has a built-in clock, so the readings are very accurate and it publishes to the spreadsheet every 30 minutes. On the other hand, the ESP8266 publishes new readings approximately every 28 to 29 minutes.

Wrapping Up

In this post we’ve shown you how to publish your sensor readings with your ESP32 or ESP8266 to a spreadsheet on Google Sheets using the IFTTT platform. As an example, we’ve published readings from the BME280 sensor. We’ve also used the ESP deep sleep capabilities to save power. This way, the ESP is awake only when we need to take readings. You should be able to take this project example and apply it to your own projects.

Please note that this method has some limitations: first, it uses a third party service, and second, you need to be careful with the amount of requests you make in one day. However, this method works very well and it is easy to implement.

If you like ESP32 and you want to learn more, make sure you check our course exclusively dedicated to the ESP32: Learn ESP32 with Arduino IDE.

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

119 thoughts on “ESP32 Publish Sensor Readings to Google Sheets (ESP8266 Compatible)”

    • That’s a great question! Unfortunately the ESP8266 has very limited support for HTTPS requests, so you can’t easily use Google Scripts with the ESP8266. At least I wasn’t able to make a reliable connection.
      Regards,
      Rui

      Reply
          • if we upload the code, after every 30 mins is the values get updated even we off the data…?
            why we should take 30 mins time…?

          • Another small doubt please…after uploading what we should do…? is automatically values uploaded to drive or we should do anything to get uploaded..?

          • Hello, Sara, maybe you can help me here.
            Using ESP32 dev I have previously succeded in writing sensor (and other) data to a Google spreadsheet (used script.google.com/macros/s/AKfycbzUzOJFo234sEzFDP0g98MZDGovjbki-K4nqVT-ymTX1EpmJzuIHed7_0JojK4ZKAsrZQ/exec?&Dif=0.20&ActRiego=0). After that, I also made an ESP32 dev to read data from GSheets (at least one cell per sheet). I am now trying to include a write to GSheets function to the latter code for monitoring purposes, but found a problem.
            The problem is that despite the command line in a browser (i.e. the url printed in the serial monitor, cript.google.com/macros/s/XXXXXXXXXXXXXXXXXXX/exec?&Dif=0.20&ActRiego=0) does write to the Google sheet, the data are not written from the ESP32 and the printed “payload” in the serial monitor is a long string of html code (startying with “… and going on for long!).
            Any idea of what is happening?
            Saludos

  1. nice explanation step by step, but I am facing a little problem everything is going right till (Event has been triggered) but
    4) Go to your Google Drive. The IFTTT service should have created a folder called “IFTTT” with the “BME280_Readings” spreadsheet inside

    at this step I am not finding any folder named IFTTT on my google drive please reply me what’s going wrong?

    and my second query is that could I publish more than 3 readings?

    Thanks in advance

    Reply
    • Hi.
      If it says the Event has been triggered and nothing happens, it may be a temporary problem with IFTTT.
      In your IFTTT account, go yo “Activity” in the following link: ifttt.com/activity
      There, you can check if something went wrong and why.
      I hope this helps.

      Reply
  2. Thanks Sara Santos for your reply, there was a problem with my applet, my applet was turned off now I turned it on.
    but my second question is that can I post more than 3 readings? I want to post 30 readings on single sheet please reply me
    again thanks very much

    Reply
    • Hi.
      Unfortunately, this topic is poorly documented on IFTTT.
      I know there is a usage limit, because we happen to exceed the usage limit when we were testing some projects.
      However, I don’t know how much requests you can make. They have a daily limit. So, if you exceed the daily limit, you can make requests again on the following day.
      I think 30 readings on a day should be fine. But you have to experiment yourself.
      I hope this helps.
      Regards,
      Sara

      Reply
  3. Signed up, went to Webhooks page, see Trigers and Actions (after clicking on “Webhooks triggers and actions”), but nothing there is clickable – I can not get to enter a name, or do anything with those items. Ho can I proceed?

    Reply
  4. Very well done!
    I discover IFTTT folowing your steps… Thanks.
    Now, I would like to store more data on the Google Sheet!
    Unfortunately I cannot change these 3 values !!!
    Do you have an idea how to do that in Webhooks???

    Reply
  5. This tutorial is very helpful. I have it working with ESP32’s. Right now I have two units sending data to the Google Spreadsheet from different locations. I will add two more soon.

    I have tried to add more “Values” to send to the spreadsheet, but have not been successful. Here is what I tried to do: {{OccurredAt}} ||| {{EventName}} ||| {{Value1}} |||{{Value2}} ||| {{Value3}} ||| {{Value4}} |||. It fails with or without the three terminating characters as shown.I asked about this on the reddit ifttt area, but have had no replies.
    Do you know how to send more than three “Values” to the spreadsheet?

    Reply
    • I’m glad the tutorial is working now. Unfortunately IFTTT Webhooks service only supports a maximum of 3 values. You would need to create another Applet to publish more values

      Reply
    • Hello,

      You could send multiple readings in one value by comma separating them. (This assumes you can send strings).

      Just build the string up in code then send it in one go. It won’t look very pretty on the spread sheet but you could easily reformat it with some post processing to separate out the values to make it more presentable.

      Cheers

      Reply
      • Writing 4 variables to spread sheet(two values in single cell)

        String jsonObject = String(“{\”value1\”:\””) + bme.readTemperature()+”/”+ bme.readAltitude(SEALEVELPRESSURE_HPA)+ “\”,\”value2\”:\”” + (bme.readPressure()/100.0F) + “\”,\”value3\”:\”” + bme.readHumidity() + “\” }”;

        Reply
      • For anyone who found themselves here wondering how to process multiple valuesin one cell, enter this in another cell:

        =split(,”<delimiter character”)

        ex: If you have sent multiple sensor readings to cell C20 that are separated by a plus sign, enter this in another cell: =split(C20,”+”)

        All your values will be separated out into new columns.

        Reply
  6. Really nice tutorial!

    Based on the tutorial, I am trying to built something similar with a sim808 module on an Arduino uno, in stead of the ESP. So far, I manage to ‘trigger the event’ in my IFTTT location and it does add a line in the google sheets. This happens by a AT+HTTPARA = \”URL\”,\”https:// …(and so on) command and works fine. However, I did not manage to post the json string into the sheet. I fear I am missing out something here. but don’t know what exactly. How to send the values of for example temperature or other measurements? I assume it should be possible to also send a json object with three values, similar as you do in the Webhooks example. wouldn’t it? I would really appreciate your view on this. Thanks.

    Reply
  7. Hi. Thank you for the step by step instruction. I am a beginner and I find this site very helpful.
    4) Go to your Google Drive. The IFTTT service should have created a folder called “IFTTT” with the “BME280_Readings” spreadsheet inside

    at this step, I am not finding any folder named IFTTT on my google drive. I checked Activity. The Applet is created, Applet is turned on, but Applet failed. It says the Webhook service or its API is temporarily down. Is it any setting I need to change? please help me resolve this issue.

    Reply
  8. This was a solid tutorial. I substituted a DHT22 and BMP180 for the BME280, and I didn’t need the sleep functions so I cut those out, too. My point is, the tutorial was clear enough that even with changing out the hardware and sleep requirements, I was able to get it to work on the first try. Thanks again.

    -Anthony

    Reply
  9. Each +/- 25 measures, the system stops to connect my router, why???

    At that time, it says “failed to connect going back to sleep”.

    “Going Back to sleep means nn sec” => esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR).

    In your exemple, Time to Sleep is 60 minutes.
    Is it reasons why you were using 60 min and not 30 or 3 minutes?

    In my case, if I have from time to time connection prblms, I could have a time of (exemple) 1 minute before to retry.

    Do you agree?

    jlb

    Reply
    • Hi.
      There wasn’t any special reason to choose 30 minutes. It could have been any other value.
      It seems a good idea to add a timer to retry the connection after a minute or so.
      You have to try it out and see if it solves your problem.
      Regards,
      Sara

      Reply
  10. Add row to spreadsheet: the example in the tutorial shows the updating of three columns with sensor readings. What do I have to do if I want to update more than three columns? Your help will be greatly appreciated.

    Reply
    • Hi Rudi.
      After searching a bit about that subject, I’ve found that you can’t customize those fields on the IFTTT applet and you are limited to 3 values.
      If you want to send more thant 3 readings I suggest sending them all on value1, for example, and then, edit or add a formula to your google sheets to separate those values.
      Regards,
      Sara.
      P.S. I’ve seen your weather station on your contact. Congratulations! It looks great.

      Reply
  11. Hello, thank you very much for this tutorial.

    I’m trying it with an esp-01 module on an arduino one board,
    it connects to the wifi ap, I can see it in the client list of the router, and it responds to ping, but it does not connect to the host maker.ifttt.com
    ______________________________
    Join AP success
    IP: 192.168.178.8
    setup end
    Connecting to maker.ifttt.com
    ______________________________

    and nothing more…
    according to the arduino scketch should try the connection 5 times and print a point “.” every attempt via the serial port … but it does not.
    What do you think I’m doing wrong?
    Thank you!.

    Reply
    • If you open the IFTT URL in your web browser, can you see the success message? Does it publish the readings? It looks like you have either have the wrong API Key, the wrong event name, or something wrong with the IFTTT setup.
      Are you using my exact sketch? It looks like you’ve modified it, so I don’t know exactly what you’re doing.

      Reply
  12. Thanks for all this information. I got it to work although I modified/mangled the sketch to suit my needs. I would like to send up to 9 pieces of data each cycle. I understand the webhooks only accept 3. How do I send a further 3 data points to the same spread sheet. I would prefer not to have to analyses the cells on the sheet to split any csd. ant suggestions? For example can I send data to say column 456 and leave colums 234 empty

    Reply
  13. I have just tried sending some csv to a cell on sheets and I have found it is easy to parse the cell to separate the data.

    Reply
    • Hi Anthony.
      IFTTT allows you to send emails to Gmail when a certain condition is met.
      The request to send the email is very similar to the request of sending sensor readings to google sheets.
      In the “Choose action service” step search for Gmail. Then, follow the instructions to make a proper request.
      Regards,
      Sara

      Reply
  14. Very nice tutorial. I’m just having the same problem is some people here. I’m not receiving the sheet on my Google drive. Everything is like in the tutorial and everything is working without problems in the ifttt website, but I’m not receiving the sheet.

    Reply
    • Hi.
      I’m sorry about that.
      In your IFTTT account you can go to the “Activity” tab and try to understand what went wrong.
      You can also contact IFTTT and see if there’s some issue going on with the IFTTT services.
      Recently, they were having issues with the Gmail services and I don’t if that also applies to other Google integrations.
      Regards,
      Sara

      Reply
  15. Only one little questions.
    what is mean “if(!!!client.available())” ?
    i think is equivalent to “if(!client.available())”

    Reply
  16. Hi, thanks for the good tutorial. After little problems it works – but please tell me, what part – software, google, IFTTT – is responsible for the date and time entry!!!
    Problem is not only the format of the string, to work with in other programs – meanest thing is: It writes 12:xxAM during the hour after midnight instead of 00:xxAM, so I have trouble to convert it to 24h format and to convert all the stuff to “dd.mm.yyyy xx:xx”.
    Regards,
    Siegfried

    Reply
  17. Hi, on IFTTT I couldn’t find anything concerning the format of date and time.
    But finally I managed converting the string correctly with my own program last night.
    Thank you! 🙂

    Reply
  18. Hi, wonder if someone can please help me…I’m using the 8266 board from Adafruit, but the pinout is different. https://bit.ly/2Z63Fzs

    And I’m using Adafruit’s BME 280.

    Should I connect SCK from the BME 280 to the SCL (pin 5) of the board?
    And SDI from the BME 280 to the SDA (pin 4) of the board?

    Last question! How should I re define the pins correctly in the code here?

    // Uncomment to use BME280 SPI
    /*#include
    #define BME_SCK 13
    #define BME_MISO 12
    #define BME_MOSI 11
    #define BME_CS 10*/

    Thank you!

    Reply
    • Hi.
      Yes, connect SCK to GPIO5 and SDI to GPIO4.
      When using I2C protocol you don’t need to redefine the pins in the code.
      It is done automatically when you create a bme object.
      Adafruit_BME280 bme; // I2C
      Regards,
      Sara

      Reply
  19. Got it thanks!

    I realized my errors were not because of the pins. It was this line of code:
    status = bme.begin(0x76);

    I had to remove 0x76 in order for it to work on my board. Reads like this now:
    status = bme.begin();

    It works now. Thanks again!

    Reply
  20. For everyone having trouble with creating a google sheet.

    I started the applet creation process, but realized in the middle of it, I didn’t connect IFTTT to google first. After I realized my issue, I connected IFTTT to google, approved my security warning from google (check your email), logged out of google, logged back in, deleted my applet, then finally created a new one.

    After this, my spreadsheet was created by IFTTT and my test worked.

    Reply
    • Hi Gene.
      Thank you so much for sharing that information.
      That can be the problem of some of our readers that can’t make this example to work.
      I’ll point out your instructions if anyone has future issues with this project.
      Thank you.
      Regards,
      Sara

      Reply
  21. I just tried this tutorial and I’m really happy – it is working fine so far!
    I am using as ESP8266 running on a Lipo battery and I am reporting
    the battery voltage to my google spreadsheet.
    I’ll try temperature & humidity next, I have a DHT11 sensor.

    Thanks again !

    Reply
  22. Hi,
    I tried this project and it worked fine as it should.
    2 little question:
    1.When creating an applet on IFTTT , you got on one page the AP number (to trigger an event) and further down you filled in 3 figures “20, 90, 30”. What is this for ?
    2. Why it is not possible to rename i.e from “value1” to “Temp°C ” ?
    Regards speedy

    Reply
    • Hi Speedy.

      1. That’s just for demonstration purposes to test the applet.
      2. Unfortunately, I think IFTTT doesn’t allow you to do that, at least when we created the tutorial.
      Regards,
      Sara

      Reply
  23. Hi, works great. Now I’m trying to change the pressure reading to a Light reading using a LDR.
    I’ve changed the bme.readTemperature() with analogRead(15) but it’s returning a reading of 4095. I can’t work out why, any ideas?

    Thank you

    Reply
  24. Hi, before present my problem, I want to congratulate you for your tutorial. However, when I replicate your tutorial I get this from the Serial Monitor but it does not publish the values into google sheet.

    WiFi connected in: 3902, IP address:
    Connecting to maker.ifttt.com
    Request resource: /trigger/{dados}/with/key/bpECY-BScom0a7M4hxCbqR
    HTTP/1.1 200 OK
    Date: Fri, 08 Nov 2019 12:07:52 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 51
    Connection: close
    X-Top-SecreTTT: VG9vIGVhc3k/IElmIHlvdSBjYW4gcmVhZCB0aGlzLCBFbWFpbCB1cyBhdCBqb2JzK3NlY3JldEBpZnR0dC5jb20uIFdlIHdhbnQgTWFrZXJzLg==
    Server: web_server

    Congratulations! You’ve fired the %7Bdados%7D event
    closing connection
    Going to sleep now

    I check the activity and there is not indication that the applet was used. I tested the applet as you performed in the topic “Testing Your Applet” and I was able to put data on the spreedsheet. Sorry for the long question and Thank you in advance

    Reply
    • Hi João.
      Change your request resource from
      /trigger/{dados}/with/key/bpECY-BScom0a7M4hxCbqR

      to

      /trigger/dados/with/key/bpECY-BScom0a7M4hxCbqR

      Regards,
      Sara

      Reply
      • Hi.
        Thank you for the quick feedback. I will change it and will try again.
        Thank you once more

        Best regards
        João Marques

        Reply
  25. Hi,
    Sorry for bothering again. I managed to send one set of data but when the modulo leaves the sleep mode is unable to reconnect. Do you know the reason?
    Thank you in advance
    Best regards
    João Marques

    Reply
      • Hi,
        Thank you for the link. I think I managed to solve my problem. I am testing with a shorter interval (15min) only to ensure that the problem is solved.
        I replaced the if cycle for a while cycle
        while (WiFi.status() != WL_CONNECTED){
        Serial.println(“Connection Failed! Rebooting…”);
        delay(5000);
        ESP.restart();
        }
        // if(WiFi.status() != WL_CONNECTED) {
        // Serial.println(“Failed to connect, going back to sleep”);
        // }
        I leave it here to help people with the same problem.
        Once more thank you for the help

        Best regards
        João Marques

        Reply
  26. Hi, I tried to mix this code with another but in that case, the arduino presented an error message (initWifi() is not in the scope). Do you know why?
    Thank you in advance
    Best regards

    Reply
    • Hi.
      You’ve probably forget to copy the initWifi() library to your code:
      void initWifi() {
      Serial.print(“Connecting to: “);
      Serial.print(ssid);
      WiFi.begin(ssid, password);

      int timeout = 10 * 4; // 10 seconds
      while(WiFi.status() != WL_CONNECTED && (timeout– > 0)) {
      delay(250);
      Serial.print(“.”);
      }
      Serial.println(“”);

      if(WiFi.status() != WL_CONNECTED) {
      Serial.println(“Failed to connect, going back to sleep”);
      }

      Serial.print(“WiFi connected in: “);
      Serial.print(millis());
      Serial.print(“, IP address: “);
      Serial.println(WiFi.localIP());
      }
      Regards,
      Sara

      Reply
  27. Thanks for the post! It was very useful ♥

    For those who are having problems with how Google Sheet handles the data and especially the date, this link was very helpful:
    gist.github.com/oscarmorrison/bf14dab89854238d4cca

    Regards.

    Reply
  28. Apologies if this has already been said but if you created this project in IFTTT before Google closed Google plus, you will need to go back into your IFTTT account and remove any reference to plus.google.com and re-associate it otherwise it won’t work.

    Reply
  29. Hi
    wonderful tutorial, it’s working perfectly.
    Just one question: would it be possible to send multiple rows for each IFTTT request?
    Something like saving, let’s say 30 values, in an array and then sending them in 30 rows in just one IFTTT call?
    Thank you so much for any reply!

    Marco

    Reply
  30. Hi,

    You can cut out IFTTT by directly adding a webhook to your google table.
    levelup.gitconnected.com/turn-your-google-sheet-into-a-web-application-f766f1ff8b98

    You can even do some processing on google server side.

    Reply
  31. Hi I am new to pcb projects and I have a question. Can you power up the esp32 from the 3V3 pin and also the bme280 sesnor from an 3.3v output of a battery charger (aliexpress.com/item/1005001621882169.html?spm=a2g0o.productlist.0.0.5aba557eLdmKfc&algo_pvid=null&algo_expid=null&btsid=0bb0622916184066697991457e3e56&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_) to reduce power consumption? I already tried it and it doesn’t work. Did I made a mistake or it can’t be done this way?

    Reply
  32. I was using your example to send value to a Google sheet with IFTTT. It worked for many months but it suddenly stopped. In the Serial Monitor, I get the following message:

    HTTP/1.1 301 Moved Permanently

    Reply
    • Hi Eric. Did you figure this out? I see this was posted today. I too, had been sending data via IFTTT to Google Sheets for months and it suddenly stopped today (5/5/21) with the same message in the Serial Monitor.

      Reply
      • Hello
        I have the same problem (HTTP/1.1 301 Moved Permanently)
        on the 05/05/2021
        do you find solution ?
        thanks

        Reply
        • Hi, I thought I’d follow up. I did find a workaround. I used WiFiClientSecure and port 443 instead of port 80. That worked for me. But also, by the end of the day, it suddenly started working again with my old code and port 80 as usual. Since we all had this error on the same day, I suppose it may have been something temporary on ifttt’s side?

          Reply
  33. Hi, Awesome tutorial. Everything working.
    I’m trying to change to 2 x DS18B20 sensors to get some temperatures.
    Can you help with code for that as I keep getting mixed up and failing.
    Thanks in advance.

    Reply
  34. I need to combine multiple values in to comma separated format to get around the limit of three values in the IFTTT write to Google sheet. Specifically the syntax in the jsonObject statement:
    I used this
    String jsonObject = String(“{\”value1\”:\””) + ExtHumidity + “,\”” + ExtTemp + “,\”” + BattTemp + “\”}”;
    but I got the error : {“errors”:[{“message”:”Unexpected number in JSON at position 18″}]}
    Help I am new to coding with whatever this language is. is it C++?

    Reply
    • If you edit your IFTTT applet action and remove “EventName”, Value2, Value3. Only keep:
      OccurredAt ||| Value1
      You can then build your jsonObject=
      String(“{\”value1\”:\” “) + ExtHumidity + “|||” + ExtTemp + “|||” + BattTemp + “\”}”;
      You can add almost unlimited number of values. I’m currently recording over 40 values.

      Reply
    • String jsonObject = String(“{\”value1\”:\””) + bme.readTemperature()+”/”+ bme.readAltitude(SEALEVELPRESSURE_HPA)+ “\”,\”value2\”:\”” + (bme.readPressure()/100.0F) + “\”,\”value3\”:\”” + bme.readHumidity() + “\” }”;

      Reply
  35. I am working on this project and when I go to test the applet with the formatted rows the way that the tutorial lists it, the google sheet is not updated with the current date, time, event name, or values that I entered into the 3 test value boxes. Is there something I’m missing on how to insert information into the format row box when creating the applet?

    Reply
  36. Hi, I’d like to start by thanking you for the awesome tutorial and the awesome website!
    Unfortunately I’m having some trouble with this one and am getting a HTTP/1.1 404 Not Found error
    Please see the following from the serial monitor:

    Connecting to: TP-Link_
    WiFi connected in: 5297, IP address: 192.168.0.___
    Connecting to maker.ifttt.com
    Request resource: /Temperature_readings/json/with/key/jKcD0Sod1JFTSd0v8wyWR4LJhCEv1TviF_____X
    HTTP/1.1 404 Not Found
    Content-Type: text/html; charset=utf-8
    Content-Length: 218
    Connection: close
    Date: Wed, 27 Apr 2022 16:47:54 GMT
    X-Powered-By: Sad Unicorns
    X-Robots-Tag: none
    X-Top-SecreTTT: VG9vIGVhc3k/IElmIHlvdSBjYW4gcmVhZCB0aGlzLCBFbWFpbCB1cyBhdCBqb2JzK3NlY3JldEBpZnR0dC5jb20uIFdlIHdhbnQgTWFrZXJzLg==
    Content-Security-Policy: default-src ‘none’
    X-Content-Type-Options: nosniff
    X-Cache: Error from cloudfront
    Via: 1.1 c72fa7e0e95fc1891e9c9071fc71a3ea.cloudfront.net (CloudFront)
    X-Amz-Cf-Pop: JNB50-C1
    X-Amz-Cf-Id: rUO7As82FDYLnnUYjy4POI_SyoytzYKM3b4mK4Cb0KGuuLkKWf36DA==

    Error

    Cannot POST /Temperature_readings/json/with/key/jKcD0Sod1JFTSd0v8wyWR4LJhCEv1TviFZgEG7SLBPS

    closing connection
    Going to sleep now
    ets Jul 29 2019 12:21:46

    Do you have any advice for me?

    Reply
  37. Hi, done everything as above, the trigger works fine and my google sheet gets updated but instead of the sensor values I get the “{{Value1}}” , “{{Value2}}” labels without real the sensor readings.

    Serial printing the jsonObject string the values are there fine : {“Value1″:”26.50″,”Value2″:”64.20”}

    (I used a dht22 sensor). I suppose there is something wrong in the syntax of the above string ?

    thank you!

    Reply
  38. Hi, done everything as above, the trigger works fine and my google sheet gets updated but instead of the sensor values I get the “{{Value1}}” , “{{Value2}}” labels without real the sensor readings.
    I use the BME 280 sensor. I have tried both ESP32 and ESP8266 with the same result. Can someone tell me what the problem might be?
    Thank you

    Reply
    • Gents,
      I had the same problem, removing “json” in the trigger solved it.
      So
      const char* resource = “https://maker.ifttt.com/trigger/{fill in your event}/json/with/key/{fill in your key};
      should be
      const char* resource = “https://maker.ifttt.com/trigger/{fill in your event}/with/key/{fill in your key};

      Good luck

      Reply
  39. my question is can do same thing using n8n.io which similar to ifttt and opensource.
    in addition can you post tutorial using n8n.

    Reply
  40. Hi, Sarah. I have some connection problem. When I power my ESP first, it is working and sending data. But after 30 minutes, there is no connection. If I restart after 30 minutes, It is working. Could you please help me?

    Reply
    • Hi.
      Do you know what happens exactly after it disconnects?
      Can you have it connected to your computer and let the serial monitor opened to see if it reports any error?
      Regards,
      Sara

      Reply
      • Hello again. Yes, after first 30 minutes, there is a connection failed message on the serial monitor.
        My solar panel is producing 6V-300 mah. I added an external antenna to my ESP32 because of distance between router and the board.

        Do you think the reason is because of weak current?

        Reply
        • Hi again.
          It may be…
          However, if it’s always after 30 minutes, it might also be soemthing else…
          It’s hard to tell without having more information.
          Regards,
          Sara

          Reply
      • Hi Sara.
        After 3 hours without connection, it works this morning. So, it seems that the connection problem is because of weak solar panels.

        However, There is 3 working types in the bme’s datasheet. Could you please explain, how I use my bme280 in forced sleep mode?

        Reply
  41. Hi, actually, while updating values data to sheets, it’s just showing as :
    June 14, 2023 at 03:46PM dht_readings {{Value1}} {{Value2}} {{Value3}}
    I’m not getting the value but these {{Value1}} strings

    Reply
  42. I am having a similar problem to Himanshu’s post above. Would it be possible for you to supply an example of this line:
    String jsonObject = String(“{\”value1\”:\””) + bme.readTemperature() + “\”,\”value2\”:\”” + (bme.readPressure()/100.0F) + “\”,\”value3\”:\”” + bme.readHumidity() + “\”}”;
    which would write a simple integer variable to value 1? Lets say I have declared “int test =1” and want to write the value “1” to the first position of the spreadsheet.
    Also that line appears to have an unbalanced parenthesis. The “(” just after String has no matching close parenthesis. Would that make a difference?
    Thanks for any help you can give

    Reply
  43. Hi Sara, Hi Ruy,
    I follow your turials with great interest and in fact I have purchased two of your books. I need to save data from some sensors and, as a first test, I wanted to use Google Sheets.
    I followed your tutorial step by step “ESP32 Publish Sensor Readings to Google Sheets (ESP8266 Compatible)” but I can’t create the IFTTT service because I have the impression that it is only paid.
    Do you have any suggestions on this or am I doing something wrong?
    Thanks in advance
    Claudio

    Reply
      • Thanks so much Sarah.
        I successfully followed your advice.
        But now I can’t display the timestamp legibly.
        In the tutorial we recommend using the EPOCHTODATE() function.
        I tried replacing the string:
        valueRange.set(“values/[0]/[0]”, epochime);
        with
        valueRange.set(“values/[0]/[0]”, EPOCHTODATE(A5));
        (as per the example found at the indicated link)
        but the compiler gives the following error:
        “Compilation error: ‘EPOCHTODATE’ was not declared in this scope”

        can you help me please?
        Thank you
        claudio

        Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.