ESP32 Publish Sensor Readings to Google
Sheets
Project Overview
- First, the ESP32 connects to
your Wi-Fi network
- Then, the DHT11 takes the
temperature and humidity readings;
- ESP32 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
Creating Your IFTTT Account
This project is
created by using IFTTT.IFTTT integrates 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 to the official site: ifttt.com and enter your email to get started.
Creating an Applet
Now let's see how to create a new applet. Follow the next simple 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
3. Search for the
“Webhooks” service and select the Webhooks icon.
4. Select the “Receive
a web request” trigger.
5. Give a name to the
event. Then, click the “Create trigger” button.
6. Click the “that”
word to proceed.
7. Now Search for the
“Google Sheets”, and select the Google Sheets icon.
8. You need to click
the “Connect” button.
9. Select the “Add a
row to spreadsheet” action.
10. Rename the
spreadsheet. leave the “Formatted row” field as default, and then, choose a Google
Drive folder path. If we leave this field empty, IFTTT will create a folder
called “IFTTT” in your Google Drive folder to save the spreadsheet. And last
click the “Create action” button.
Parts Required
For this project, we’ll
use DHT11 sensor readings. Following is the list of parts is needed to build the
project.
1.Esp32
2.DHT11
3. Jumper wires
4. Breadboard
Schematics
DHT11
with ESP32
Use the Following schematic diagram to connect the DHT11 to the Esp32
Code
After making sure you
have the ESP32 board installed on your arduino, you can copy the following
Sketch to Arduino IDE.
//This code is edited by Yogesh Bawane
//for impulsetech Youtube channel https://youtu.be/RpQxJkEZ-fA
//For complete video tutorial visit https://youtu.be/RpQxJkEZ-fA
#include <WiFi.h>
#include <HTTPClient.h>
#include "DHT.h"
#define LDR_PIN 34
#define DHTPIN 23
//our sensor is DHT11 type
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const char * ssid = "impulsetech";
const char * password = "impulse567";
String server = "http://maker.ifttt.com";
String eventName = "sensor_data";
String IFTTT_Key = "drlqzriADlETJtD04KV_NfpVmzvtAVhrEhUSGNRNnN7";
String IFTTTUrl="https://maker.ifttt.com/trigger/sensor_data/with/key/drlqzriADlETJtD04KV_NfpVmzvtAVhrEhUSGNRNnN7";
int value1;
int value2;
int value3;
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Viola, Connected !!!");
}
float getLightPercentage(void)
{
int ldrRawVal;
float percentage;
ldrRawVal = analogRead(LDR_PIN);
percentage = ((float)((ldrRawVal*100)/4096));
return percentage;
}
void sendDataToSheet(void)
{
String url = server + "/trigger/" + eventName + "/with/key/" + IFTTT_Key + "?value1=" + String((int)value1) + "&value2="+String((int)value2) +"&value3=" + String((int)value3);
Serial.println(url);
//Start to send data to IFTTT
HTTPClient http;
Serial.print("[HTTP] begin...\n");
http.begin(url); //HTTP
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void loop() {
value1 = dht.readHumidity();
value2 = dht.readTemperature();
value3 = getLightPercentage();
Serial.print("Values are ");
Serial.print(value1);
Serial.print(' ');
Serial.print(value2);
Serial.print(' ');
Serial.println(value3);
Serial.print(' ');
sendDataToSheet();
delay(10000);
}
Comments
Post a Comment
If you any query please comment