ESP32 IoT Blynk DHT22
Temperature and Humidity Logger

Project Overview

This project uses an ESP32 microcontroller to read temperature and humidity data from a DHT22 sensor and sends the data to the Blynk Cloud IoT platform for real-time monitoring and logging. It is ideal for weather stations, indoor climate logging, and home automation.

Completed: 2024
Status: Completed

Live Simulation

Applications

  • Weather station
  • Indoor climate logging
  • Home automation

Pin Configurations

  • DHT22 VCC → ESP32 3v3
  • DHT22 GND → ESP32 GND
  • DHT22 DATA → ESP32 D2 (GPIO2)

Schematic

Temperature and Humidity Schematic

How It Works

  1. Initialize Wi-Fi and connect to your local network.
  2. Measure temperature and humidity using the DHT22 sensor.
  3. Send data to Blynk Cloud using HTTP GET requests.

Code

main.py
Copied to clipboard!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

import machine

import dht

import time

import network

import urequests

pin = machine.Pin(2)

sensor = dht.DHT11(pin)

BLYNK_AUTH = "AUTH from blynk"

BLYNK_URL = "http://blynk.cloud/external/api/update"

wifi = network.WLAN(network.STA_IF)

wifi.active(False)

time.sleep(0.5)

wifi.active(True)

wifi.connect("network SSID", "password")

while wifi.isconnected() == False:

print(".", end="")

time.sleep(1)

def send_to_blynk(temp, hum):

try:

url_temp = f"{BLYNK_URL}?token={BLYNK_AUTH}&V0={temp}"

url_hum = f"{BLYNK_URL}?token={BLYNK_AUTH}&V1={hum}"

r1 = urequests.get(url_temp)

r1.close()

r2 = urequests.get(url_hum)

r2.close()

except:

print("Error")

while True:

sensor.measure()

temp = sensor.temperature()

hum = sensor.humidity()

print("Temp: ", temp)

print("Humidity: ", hum)

send_to_blynk(temp, hum)

time.sleep(5)

Go Back