Google Sheet Data Storage using ESP32

Introduction

Google Sheets can be used as a free cloud database for IoT projects.

In this tutorial, ESP32 reads temperature and humidity from DHT11 sensor and stores data directly into Google Sheets using Google Apps Script.

Required Components

ComponentQuantity
ESP32 Board1
DHT11 Sensor1
WiFi Connection1
Jumper WiresFew

DHT11 Connection with ESP32

DHT11 PinESP32 Connection
VCC3.3V
GNDGND
DATAGPIO 4

ESP32 DHT11 Circuit

Create Google Sheet

Step 1:
Open Google Sheets and create a new sheet.

Step 2:
Add column names:

  • Time
  • Temperature
  • Humidity

Create Google Apps Script

Step 1:
Open:

Extensions > Apps Script

Step 2:
Delete existing code and paste the following script.

function doGet(e) {

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

  var time = new Date();

  var temperature = e.parameter.temperature;
  var humidity = e.parameter.humidity;

  sheet.appendRow([time, temperature, humidity]);

  return ContentService.createTextOutput("Data Stored");

}

Deploy the Apps Script

Step 1:
Click:

Deploy > New Deployment

Step 2:
Select:

Web App

Step 3:
Set:

  • Execute as → Me
  • Who has access → Anyone

Step 4:
Click Deploy and copy Web App URL.

Install Required Libraries

  • DHT Sensor Library
  • Adafruit Unified Sensor

Open:

Sketch > Include Library > Manage Libraries

ESP32 Google Sheet Program

#include <WiFi.h>
#include <HTTPClient.h>
#include "DHT.h"

#define DHTPIN 4
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

String scriptURL = "YOUR_GOOGLE_SCRIPT_URL";

void setup() {

  Serial.begin(115200);

  dht.begin();

  WiFi.begin(ssid, password);

  while(WiFi.status() != WL_CONNECTED){

    delay(1000);
    Serial.println("Connecting to WiFi...");

  }

  Serial.println("WiFi Connected");

}

void loop() {

  if(WiFi.status() == WL_CONNECTED){

    float temp = dht.readTemperature();
    float hum = dht.readHumidity();

    HTTPClient http;

    String url = scriptURL +
                 "?temperature=" + String(temp) +
                 "&humidity=" + String(hum);

    http.begin(url);

    int httpCode = http.GET();

    Serial.print("HTTP Response: ");
    Serial.println(httpCode);

    http.end();

  }

  delay(15000);

}

Program Explanation

CodePurpose
WiFi.begin()Connects ESP32 to WiFi
dht.readTemperature()Reads temperature value
dht.readHumidity()Reads humidity value
HTTPClientSends HTTP request
sheet.appendRow()Stores data into Google Sheet

Output

After uploading the code:

  • ESP32 connects to WiFi
  • DHT11 reads temperature and humidity
  • Sensor data is stored in Google Sheet automatically
  • New row is added every 15 seconds

Important Notes

  • Deploy Apps Script as Web App.
  • Set access permission to Anyone.
  • Use correct Web App URL in ESP32 code.
  • ESP32 must stay connected to internet.
Scroll to Top