ESP8266IOT Projects

Google Spreadsheet or Google Sheets with ESP8266 Nodemcu for Data Logging

ESP8266 and Google Spreadsheet

Google Spread Sheet with ESP8266, Description:


Google Spreadsheet or Google Sheets with ESP8266 Nodemcu for Data Logging, Temp & Hum DHT11- So far I have covered majority of the IoT platforms for monitoring different types of sensors and for controlling different types of electrical devices. Usually for the real-time sensors monitoring I display the sensors values on the Gauges and for this I mostly use Blynk IoT platform, Ubidots, and Thingspeak etc. In majority of the cases only displaying the sensor values is not enough. There are guys who are interested in the data logging for the post analysis. The sensors data logging service offered by majority of the IoT platforms isn’t as impressive as offered by the Google which is absolutely free, highly secured, fast, and reliable. In this article, I will be using Nodemcu ESP8266 WiFi module with Google Sheets for the sensor data logging. Google Sheets is a spreadsheet program included as part of the free, web-based Google Docs Editors suite offered by Google.

Read my latest Article on How to send data from Google Spreadsheet to ESP8266 or ESP32.

Since this is my first time using the Google sheets for the Sensors data logging; so, I will try my level best to explain each and every detail. I will be using DHT11 Temperature and Humidity sensor as this is the most basic and easily available sensor. Once you learn how to send the temperature and humidity values to the Google Spreadsheet then you can replace this sensor with any other sensor of your choice. So, before, I am going to explain the circuit diagram, programming, and how to get started with the Google sheets, first let me explain; how this projects works.

Google Spreadsheet

I am using my homemade 4S lithium Ion battery pack for powering up my Nodemcu ESP8266 Development board. Read my article on how to make 3S and 4S lithium Ion batteries pack, if you want to make the same battery pack. As soon as I powered my Nodemcu ESP8266 module, after a few seconds I started to receive the data. The temperature and humidity values are stored along with the date and time information. For the demonstration purposes I am using a short delay in the programming, if you want you can increase the delay time. It’s totally up to you whether you want to send data after every 1 minute or 10 minutes, or 1 hour.

Google Spreadsheet

Anyways, you can also open the Google spreadsheet using your laptop or computer; again it’s up to you whether you want to use your computer or your cell phone for the monitoring and post analysis. Since this is an IoT based project so, you can monitor the temperature and humidity values from anywhere in the world. One thing that I really liked about the Google sheets is that; if you share the same Google account with multiple users then all the users  can monitor the same sensor from anywhere in the world.

As this is a getting started tutorial, that’s why I only started with the DHT11 temperature and Humidity sensor, if you want you can use multiple sensors, just go ahead and give it a try and if you face any issues then let me know in a comment. Anyways, now you have got the idea of what exactly you are going to learn after reading this article. Without any further delay, let’s get started!!!

Amazon Links:

12v Adaptor:

Nodemcu ESP8266 WiFi Module:

DHT11 Temperature and Humidity Module:

LM7805 Voltage Regulator:

470uf capacitor:

330-ohm resistor:

DC Female Power Jack:

Female Headers:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

ESP8266 NodeMCU:

ESP8266 is a highly integrated chip designed for the needs of a new connected world. It offers a complete and self-contained Wi-Fi networking solution, allowing it to either host the application or to offload all Wi-Fi networking functions from another application processor.
ESP8266 has powerful on-board processing and storage capabilities that allow it to be integrated with the sensors and other application specific devices through its GPIOs with minimal development up-front and minimal loading during runtime. Its high degree of on-chip integration allows for minimal external circuitry, and the entire solution, including front-end module, is designed to occupy minimal PCB area.

Google Spreadsheet


Serial/UART baud rate: 115200 bps
Input power: 3.3V
I/O voltage tolerance: 3.6V Max
Flash Memory Size: 1MB (8Mbit)
WiFi security modes: WPA, WPA2

DHT11 Sensor:

  • DHT11 digital temperature and humidity sensor is a digital signal output with a calibrated temperature and humidity combined sensor.
  • It uses a dedicated digital modules and acquisition of temperature and humidity sensor technology to ensure that products with high reliability and excellent long term stability.
  • Sensor consists of a resistive element and a sense of wet NTC temperature measurement devices, and with a high-performance 8-bit microcontroller connected.
  • The product has excellent quality, fast response, anti-interference ability, high cost and other advantages.

The single-wire wiring scheme makes it easy to be integrated to other applications and the simple communication protocol greatly reduces the programming effort required.

Google Spreadsheet

Nodemcu ESP8266 and DHT11 Circuit Diagram:

Google Spreadsheet

If you are just getting started with the Nodemcu ESP8266 and DHT11 Temperature and Humidity sensor then these are the minimal connections which you will need for this project. You can power up your Nodemcu module using your laptop. Connect the VCC and GND pins of the DHT11 sensor with the 3.3V and GND pins of the Nodemcu Module; and connect the Data pin of the dht11 sensor with the digital pin D1 of the Nodemcu module. Don’t forget to add a 10k ohm resistor between the VCC and Data pins of the DHT11 sensor. Now, let’s take a look at the other circuit diagram.

Nodemcu esp8266 power supply Circuit Diagram:

Google Spreadsheet

This circuit diagram is for those guys who want to power up the Nodemcu module using an external power supply. As you can see the DHT11 sensor connections with the Nodemcu ESP8266 WiFi module remains exactly the same. On the left side is the regulated 5v power supply which is based on the 7805 voltage regulator. J1 is the DC female power jack and this is where we connect a 12v adaptor, battery, or a solar panel. Don’t forget to add these 470uF decoupling capacitors.

Google Spreadsheet

Here is my Nodemcu ESP8266 WiFi module based development board which I use for testing my IoT based projects. If you want to make the same development board then you can read my previous article. Anyways, I interfaced my DHT11 sensor with the Nodemcu module as per the circuit diagram. My connections are completed and now let’s start with the Google sheets, there is nothing complicated just follow the same exact steps.

Altium Designer:

altium designer sponsor

Altium Designer is the world’s most trusted PCB design system. Altium Designer enables engineers to effortlessly connect with every facet of the electronics design process. Over 35 years of innovation and development focused on a truly unified design environment makes it the most widely used PCB design solution. With Altium Designer you can create PCB designs with an intuitive and powerful interface that connects you to every aspect of the electronics design process. Route it your way through any angle, tune for the delay, Push, Slide, and Walkaround faster than ever. Interact and collaborate with mechanical designers like never before in a photo-realistic, 3D design environment. If you want to get started with the Altium designer, you can click on the get started.

Creating Google Spreadsheet:

First of all we will create the Google Spreadsheet for which we will click on the Google apps and in which we will click on the Sheets.

Google Spreadsheet

After that we will click on the blank in order to create a new spreadsheet.

Google Spreadsheet

After that we will give the title name of the project and then in columns we will write the date, time, temperature, and humidity.

Google Spreadsheet

In the date column which is “A” we will receive the date, in column “B” we will receive the time, in column “C” we will receive the temperature, and in the column “D” we will receive the humidity. After that we will open the script editor in the previous versions of spread sheet it was found in the tools but in the new versions of the spread sheet it is in the extensions with the name Apps Script click on it.

Google Spreadsheet

After that we will click on the untitled project and give the name to the project which is DHT_monitoring and click on the ok.

Google Spreadsheet

After that paste the following code in it.

function doGet(e) { 
Logger.log( JSON.stringify(e) );
var result = 'Ok';
if (e.parameter == 'undefined') {
result = 'No Parameters';
else {
var sheet_id = ''; // Spreadsheet ID
var sheet = SpreadsheetApp.openById(sheet_id).getActiveSheet();
var newRow = sheet.getLastRow() + 1; 
var rowData = [];
var Curr_Date = new Date();
rowData[0] = Curr_Date; // Date in column A
var Curr_Time = Utilities.formatDate(Curr_Date, "Asia/", 'HH:mm:ss');
rowData[1] = Curr_Time; // Time in column B
for (var param in e.parameter) {
Logger.log('In for loop, param=' + param);
var value = stripQuotes(e.parameter[param]);
Logger.log(param + ':' + e.parameter[param]);
switch (param) {
case 'temperature':
rowData[2] = value; // Temperature in column C
result = 'Temperature Written on column C'; 
case 'humidity':
rowData[3] = value; // Humidity in column D
result += ' ,Humidity Written on column D'; 
result = "unsupported parameter";
var newRange = sheet.getRange(newRow, 1, 1, rowData.length);
return ContentService.createTextOutput(result);
function stripQuotes( value ) {
return value.replace(/^["']|['"]$/g, "");

In the above code we will make several changes in the var_sheet id we will paste the code copied from the spread sheet main page which is shown below in the diagram.

Google Spreadsheet

We can change the time by changing the command

varCurr_Time = Utilities.formatDate(Curr_Date, "Asia/Karachi", 'HH:mm:ss');

As the Pakistan time is based on the Karachi so we will write Asia/Karachi. If you are living in India then you will write Asia/New Dehli. You can search the time zone of your country and replace it. After that we will click on the publish and then click on the deploy as web.

Google Spreadsheet

Then we will select the “anyone even anonymous” and click on the Deploy.

Google Spreadsheet

Then click on the review permission

Google Spreadsheet

Then choose the account the g-mail account with which you have created the spread sheet. After that we will click on the advance.

Google Spreadsheet

Then click on the go to dht_monitoring

Google Spreadsheet


After that we will click on the allow button.

Google Spreadsheet

After that we will copy the script url and click on the ok.

Google Spreadsheet

Now the process of the Google spreadsheet is completed and we will open the Arduino IDE. If this is your first time using the Nodemcu ESP8266 WiFi module then you will need to install the Nodemcu board. I have a very detailed article on how to install the Nodemcu board. You will also need to install the DHT11 library for this click on the Sketch Menu then go to the Include Library and then click on the Manage Libraries. Type dht in the search box and then install the dht sensor library.

Google Spreadsheet Nodemcu ESP8266 Code:

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include "DHT.h"
#define DHTTYPE DHT11 // type of the temperature sensor
const int DHTPin = 5; //--> The pin used for the DHT11 sensor is Pin D1 = GPIO5
DHT dht(DHTPin, DHTTYPE); //--> Initialize DHT sensor, DHT dht(Pin_used, Type_of_DHT_Sensor);

#define ON_Board_LED 2  //--> Defining an On Board LED, used for indicators when the process of connecting to a wifi router

const char* ssid = "AndroidAP3DEC"; //--> Your wifi name or SSID.
const char* password = "123456"; //--> Your wifi password.

//----------------------------------------Host & httpsPort
const char* host = "";
const int httpsPort = 443;

WiFiClientSecure client; //--> Create a WiFiClientSecure object.

String GAS_ID = "AKfycby8Lfzwu-5SBj9tHxbw3_j8ZPZy6P6_3e_BBISC0Jg7SstXLUed"; //--> spreadsheet script ID

void setup() {
  // put your setup code here, to run once:

  dht.begin();  //--> Start reading DHT11 sensors
  WiFi.begin(ssid, password); //--> Connect to your WiFi router
  pinMode(ON_Board_LED,OUTPUT); //--> On Board LED port Direction output
  digitalWrite(ON_Board_LED, HIGH); //--> Turn off Led On Board

  //----------------------------------------Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    //----------------------------------------Make the On Board Flashing LED on the process of connecting to the wifi router.
    digitalWrite(ON_Board_LED, LOW);
    digitalWrite(ON_Board_LED, HIGH);
  digitalWrite(ON_Board_LED, HIGH); //--> Turn off the On Board LED when it is connected to the wifi router.
  Serial.print("Successfully connected to : ");
  Serial.print("IP address: ");


void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor !");
  String Temp = "Temperature : " + String(t) + " °C";
  String Humi = "Humidity : " + String(h) + " %";
  sendData(t, h); //--> Calls the sendData Subroutine

// Subroutine for sending data to Google Sheets
void sendData(float tem, int hum) {
  Serial.print("connecting to ");
  //----------------------------------------Connect to Google host
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");

  //----------------------------------------Processing data and sending data
  String string_temperature =  String(tem);
  // String string_temperature =  String(tem, DEC); 
  String string_humidity =  String(hum, DEC); 
  String url = "/macros/s/" + GAS_ID + "/exec?temperature=" + string_temperature + "&humidity=" + string_humidity;
  Serial.print("requesting URL: ");

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
         "Host: " + host + "\r\n" +
         "User-Agent: BuildFailureDetectorESP8266\r\n" +
         "Connection: close\r\n\r\n");

  Serial.println("request sent");

  //----------------------------------------Checking whether the data was sent successfully or not
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
  String line = client.readStringUntil('\n');
  if (line.startsWith("{\"state\":\"success\"")) {
    Serial.println("esp8266/Arduino CI successfull!");
  } else {
    Serial.println("esp8266/Arduino CI has failed");
  Serial.print("reply was : ");
  Serial.println("closing connection");

Upload the above. Power up your Nodemcu ESP8266 module, next open your spreadsheet App on your cell phone or computer and you should be able to receive the temperature and humidity values along with the date and time information.

Google Spreadsheet

For detailed explanation and practical demonstration watch video given below.

Watch Video Tutorial:


Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...


  1. In the code for google script,there are many misleadingly concatenated words like dofunctionget, varsheet etc. Would be nice if the script worked out of box. Otherwise, great article.

  2. Great tutorial! Thank you for putting it together! I have modified parts of it to send RFID data from an RC522 to google sheets, but I keep getting the “esp8266/Arduino CI has failed” error. Any insight as to what usually causes that?

  3. Thanks for the nice and great tutorials.
    great article.
    I am from INDIA, i have tried this tutorial, working fine.
    Thank you

  4. I am having a problem that the code is not being able to fetch the headers but it is reding the data sucessfully but data is not going to sheet

  5. Excellent tutorial, I followed each step and received all values, but when i added more variables upto seven, google sheet only displayed five of them, can you please tell me about this problem?

  6. Initially got a “Cache-Control: private, max-age=0” error and then a “esp8266/Arduino CI has failed” error. never uploaded any data

  7. hello i am using the Arduino uno and sim800l GSM module to send data on google sheet using the GPRS how to send can anyone help me thank you ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button