Author avatarSid | Last edit 15/01/2023 by Disisid


ESP32 connected to DHT22, to read temperature and humidity



Step 1 - Install Thonny or Other Python IDLE

Step 2 - Setup Circuit

+ pin on DHT22 to VCC on ESP

out pin on DHT22 to GPIO pin 15 on ESP(can change depending on code)

- pin on DHT22 to GND on ESP

Step 3 - Setup IFTTT

Go to

Create an account

Step 4 - Create a new applet

First, click create in the upper right hand corner

Step 5 - set up applet

Then, hit Add next to IF THIS

Step 6 - Select webhooks

Once you are on choose a service, type in Webhooks in the search bar and click Webhooks

Step 7 - Select request type

On webhooks, select receive a web request

Step 8 - Set up Webhooks Account

- If you already have a webhooks account, skip this step

Otherwise, click the connect button and follow the steps on their website to create a webhooks account

Step 9 - Name event for trigger

Name the event for the trigger esp32 (it is case sensitive so be careful)

Step 10 - Set up reaction

Once the trigger is set up, click Add next to Then That

Step 11 - Select google sheets

In the search bar, search sheets and click google sheets

Step 12 - Set up sheets

Select Add row to spreadsheet

Step 13 - Connect to sheets

Click the Connect button

Step 14 - Sign in using gmail

Use your gmail to sign in to sheets

Step 15 - Source Code for thonny

import network
import urequests as requests
from machine import Pin
from dht import DHT22
from time import sleep
wifi_ssid = "WIFI NAME"
wifi_password = "WIFI PASS"

webhook_url = "<insert api key here>"

sta_if = network.WLAN(network.STA_IF)

if sta_if.isconnected() == False:
    sta_if.connect(wifi_ssid, wifi_password)

while sta_if.isconnected() == False:
    #sta_if = network.WLAN(network.STA_IF)
    #sta_if.connect(wifi_ssid, wifi_password)
    print(".", end = "")

dht22 = DHT22(Pin(15))

while True:
    temperature = dht22.temperature()
    humidity = dht22.humidity()
    temp = temperature * 9/5 + 32
    url = webhook_url + "?value1=" +  str(temp) + " F" + "&value2=" + str(humidity) + "%"
        r = requests.get(url)
    except Exception as e:
        print(e, "error")