Kunkune

ESP-01S to DHT11: Build a WiFi Temperature Sensor

ESP-01S to DHT11: Build a WiFi Temperature Sensor

By Kunkune | Published: 2026-10-21

Category: How-to Guides

Learn how to wire and program an ESP-01S with a DHT11 to create a simple WiFi temperature and humidity monitor. Step-by-step guide with common pitfalls.

Quick answer

Wire the DHT11 data pin to GPIO2 on the ESP-01S, power both modules from a 3.3V source, and upload code that reads the sensor and serves the data over WiFi.

Why GPIO2 works and what to watch out for

The ESP-01S exposes only two usable GPIO pins: GPIO0 and GPIO2. GPIO0 must be pulled high during boot, so it is not ideal for a sensor data line. GPIO2 also needs a pull-up, but it can be shared with the DHT11 data line if you add a 4.7kΩ resistor between the pin and 3.3V. This is the most reliable single-pin setup for this module.

A common mistake is connecting the DHT11 data pin directly to GPIO0. That often prevents the ESP-01S from booting correctly. Stick with GPIO2 and verify your pull-up resistor is in place.

Step-by-step build guide

  1. Wire the modules: Connect VCC and GND of both the ESP-01S and the DHT11 module to a 3.3V power supply. Connect the DHT11 data pin to GPIO2 on the ESP-01S. Add a 4.7kΩ pull-up resistor between GPIO2 and 3.3V if your DHT11 module does not include one. Double-check that you are using 3.3V, not 5V, or you may damage the ESP-01S.
  2. Prepare the Arduino IDE: Install the ESP8266 board package via Boards Manager. Select 'Generic ESP8266 Module' as the board. Set Flash Size to '1M (64K SPIFFS)' and Upload Speed to 115200. Install the DHT sensor library by Adafruit. The wrong flash size setting can cause upload failures. Stick with 1M (64K SPIFFS) for the ESP-01S.
  3. Write and upload the sketch: Use the DHT library example 'DHTtester' as a base. Change the DHT pin to 2 (GPIO2) and DHT type to DHT11. Add WiFi connection code using the ESP8266WiFi library. Optionally, create a simple web server that returns the temperature and humidity as plain text or JSON. If the upload fails, hold GPIO0 low (connect to GND) while powering on the module, then release it after the upload starts.
  4. Test the sensor readings: Open the Serial Monitor at 115200 baud. You should see temperature and humidity values printed every few seconds. If you see 'NaN' or 'Failed to read', check the wiring and pull-up resistor. A common cause of NaN readings is a missing or incorrect pull-up resistor on the data line.
  5. Access data over WiFi: After the ESP-01S connects to your network, it prints its IP address to the Serial Monitor. Enter that IP in a browser to see the sensor data if you added a web server. For remote access, forward a port on your router or use a cloud IoT platform. The ESP-01S has limited memory; avoid running too many services at once or it may crash.

Parts you will need

  • DHT11 Temperature Sensor Module 8266 with ESP-01S: DHT11 Temperature Sensor Module 8266 This module includes the DHT11 sensor and a built-in pull-up resistor, which simplifies wiring with the ESP-01S.
    DHT11 Temperature Sensor Module 8266 with ESP-01S
    DHT11 Temperature Sensor Module 8266 with ESP-01S
  • ESP-01S WiFi Module: ESP-01S ESP8266 WiFi Module Its compact size and two usable GPIOs make it a practical choice for a low-cost WiFi temperature sensor, but you must plan pin assignments carefully.
    ESP-01S WiFi Module
    ESP-01S WiFi Module

Shop Related Products

ESP-01S WiFi Module

ESP-01S WiFi Module

$1.47 $2.45

Shop Now
DHT11 Temperature Sensor Module 8266 with ESP-01S

DHT11 Temperature Sensor Module 8266 with ESP-01S

$3.53 $4.90

Shop Now