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.
- Suitable forB.Tech/Diploma IoT/ESP32 students
- Build time1-2 weeks
- LevelIntermediate
- Available atAjvika Labs, Kakinada
About this project
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:
Go to “My Applets”and create a new applet by clicking the “New Applet” button.
Click on the “this” word that is in a blue color – as highlighted in the figure below.
Search for the “Webhooks” service and select the Webhooks icon.
Choose the “Receive a web request” trigger.
Give a name to the event. In this case “
bme280_readings
” as shown in the figure below. Then, click the “Create trigger” button.
Click the “that” word to proceed.
Search for the “Google Sheets” service, and select the Google Sheets icon.
If you haven’t connected with the Google Sheets service yet, you need to click the “Connect” button.
Choose the “Add a row to spreadsheet” action.
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.
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.
Go to the
Webhooks Service page
, and click the “Documentation” button.
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.
The event should be successfully triggered, and you’ll get a green message as shown below saying “Event has been triggered”.
Go to your Google Drive. The IFTTT service should have created a folder called “IFTTT” with the “BME280_Readings” spreadsheet inside.
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:
ESP32 board
(read
Best ESP32 development boards comparison
)
Alternative –
ESP8266
board (read
Best ESP8266 dev boards
)
BME280 sensor
Jumper wires
Breadboard
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 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.
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.
Windows
instructions – ESP32 Board in Arduino IDE
Mac and Linux
instructions – ESP32 Board in Arduino IDE
ESP8266 Board in Arduino IDE
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.
/*
* Complete Project Details https://ajvikalabs.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 3
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:
Go to “My Applets”and create a new applet by clicking the “New Applet” button.
Click on the “this” word that is in a blue color – as highlighted in the figure below.
Search for the “Webhooks” service and select the Webhooks icon.
Choose the “Receive a web request” trigger.
Give a name to the event. In this case “
bme280_readings
” as shown in the figure below. Then, click the “Create trigger” button.
Click the “that” word to proceed.
Search for the “Google Sheets” service, and select the Google Sheets icon.
If you haven’t connected with the Google Sheets service yet, you need to click the “Connect” button.
Choose the “Add a row to spreadsheet” action.
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.
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.
Go to the
Webhooks Service page
, and click the “Documentation” button.
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.
The event should be successfully triggered, and you’ll get a green message as shown below saying “Event has been triggered”.
Go to your Google Drive. The IFTTT service should have created a folder called “IFTTT” with the “BME280_Readings” spreadsheet inside.
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:
ESP32 board
(read
Best ESP32 development boards comparison
)
Alternative –
ESP8266
board (read
Best ESP8266 dev boards
)
BME280 sensor
Jumper wires
Breadboard
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 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.
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.
Windows
instructions – ESP32 Board in Arduino IDE
Mac and Linux
instructions – ESP32 Board in Arduino IDE
ESP8266 Board in Arduino IDE
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.
/*
* Complete Project Details https://ajvikalabs.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 3
Technologies used
Hardware components
- ESP32
- ESP8266
- Arduino
- BME280
Software & tools
- Arduino IDE
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.