Interfacing DHT11 with Raspberry Pi Pico for Temp & Humidity

Interfacing DHT11 with Raspberry Pi Pico for Temp & Humidity Interfacing DHT11 with Raspberry Pi Pico for Temp & Humidity

If you’ve ever wanted a small desk gadget that tells you the room temperature and humidity at a glance, the DHT11 sensor paired with a Raspberry Pi Pico is one of the easiest and cheapest ways to get there. It’s a classic beginner sensor, but most tutorials stop at printing values to the serial console — which is fine for testing, but not much use once you unplug the USB cable and want the readings on a standalone display.

In this project, we’re going one step further. We’ll interface the DHT11 with the Raspberry Pi Pico using MicroPython, print live readings to the Serial Monitor for debugging, and simultaneously push the same data to a 0.96″ SSD1306 OLED display so the whole thing works as a self-contained mini weather station — no laptop required once it’s flashed and powered.

By the end of this tutorial, you’ll have a working temperature and humidity monitor that you can mount anywhere — a grow tent, a server cabinet, a nursery, or just your desk — and read the numbers instantly on a crisp OLED screen.

Requirements

Hardware Requirements:

Product NameQuantityamazon logoamazon logo india
Raspberry Pi Pico1https://amzn.to/36gKUluhttps://amzn.to/3sTnD1Z
DHT11 Temperature and Humidity Sensor1https://link.amazon/B0fcLPaN5https://link.amazon/B00WlMMR9
0.96" SSD1306 OLED display (128×64)1https://amzn.to/34f0GNihttps://amzn.to/35HZK4E
USB-A to Micro-USB cable1Data-capable (not charge-only)
Breadboard1https://amzn.to/3CcBR16https://amzn.to/3tH3k6X
Few Connecting Wireshttps://amzn.to/3H2BV4ehttps://amzn.to/3J0WVu2
You can buy the required components from the given best buy links. We choose the components according to value for money.

Software Requirements:

  • Thonny IDE (or any MicroPython-compatible IDE)
  • MicroPython firmware flashed on the Pico
  • ssd1306.py driver file

Component Details

DHT11 Temperature and Humidity Sensor

The DHT11 is a low-cost digital sensor that measures both temperature and relative humidity and outputs a single-wire digital signal — no analog-to-digital conversion needed, and no extra library to calibrate manually. Internally it uses a resistive humidity sensing element and a negative temperature coefficient (NTC) thermistor, along with a small chip that handles the analog-to-digital conversion and sends out a calibrated digital signal.

DHT11 temperature and humidity sensor with pinout

Key specifications:

  • Operating voltage: 3.3V – 5.5V
  • Humidity range: 20% – 90% RH, ±5% accuracy
  • Temperature range: 0°C – 50°C, ±2°C accuracy
  • Sampling rate: 1 reading per second (1Hz) — don’t poll it faster than this
  • Interface: Single-wire digital (proprietary timing protocol, not I2C or SPI)
  • 3 or 4 pin package (3-pin modules already have the pull-up resistor built in)

Its biggest limitation is the slow sampling rate and the strict timing protocol — if you read it more than once a second, or your wiring has a loose connection, you’ll get checksum errors. We’ll handle that gracefully in code.

Similar Article: Interfacing BMP280 with Raspberry Pi Pico & Display on OLED

SSD1306 OLED Display

The SSD1306 is a monochrome OLED driver chip used in most cheap 0.96″ and 1.3″ displays. It communicates over I2C using just two wires (SDA and SCL), draws very little current, and doesn’t need a backlight since each pixel is self-illuminating — which also gives it excellent contrast and very wide viewing angles.

Key specifications:

  • Resolution: 128 × 64 pixels
  • Interface: I2C (default address usually 0x3C)
  • Operating voltage: 3.3V – 5V
  • Very low power consumption (only lit pixels draw current)

Similar Article: Interfacing SSD1306 OLED Display with Raspberry Pi Pico

Circuit Diagram and Wiring

The Raspberry Pi Pico has multiple I2C buses and GPIO pins, so it’s important to pick pins that don’t clash with each other, especially if you plan to add more sensors later. Here we’re using I2C0 for the OLED and a separate free GPIO pin for the DHT11’s single data line.

dht11 with Raspberry pi pico circuit diagram

 

DHT11 to Raspberry Pi Pico:

DHT11 Pin Pico Pin
VCC 3V3 (Pin 36)
GND GND (Pin 38 or 3)
DATA (OUT) GP11 (Pin 15)

SSD1306 OLED to Raspberry Pi Pico (I2C0):

OLED Pin Pico Pin
VCC 3V3 (Pin 36)
GND GND (Pin 38 or 18)
SCL GP1 (Pin 2)
SDA GP0 (Pin 1)

If you’re using a bare 4-pin DHT11 (not the breakout module), add a 10kΩ pull-up resistor between the DATA pin and 3V3 — without it the sensor’s signal line will float and you’ll get constant read failures. The 3-pin breakout modules already have this resistor built in, so you can skip it.

Keep the DHT11’s data wire reasonably short (under 20cm on a breadboard) — its single-wire timing protocol is sensitive to noise, and long jumper leads on a breadboard are a common cause of intermittent checksum errors.

Installing the SSD1306 Driver on Pico

MicroPython doesn’t ship with the SSD1306 driver built in, so you need to add it once:

  1. Open Thonny IDE and connect your Pico (make sure MicroPython firmware is already flashed).
  2. Go to Tools > Manage Packages.
  3. Search for ssd1306 and install micropython-ssd1306.
  4. This automatically uploads the ssd1306.py driver file to your Pico. If you’d rather do it manually, you can find the official driver source on the MicroPython GitHub repository and save it onto your Pico’s filesystem as ssd1306.py using Thonny’s “Save as > Raspberry Pi Pico” option.

You can also use 16X2 LCD Module with Raspberry pi Pico instead of OLED display.

The DHT11 doesn’t need any extra library — MicroPython’s built-in dht module handles it natively.

MicroPython Code

Here’s the complete code. Copy this into a new file in Thonny, save it as main.py on the Pico (so it auto-runs on boot), and hit Run.

from machine import Pin, I2C
import dht
import time
import ssd1306

# ---------- OLED Setup (I2C0) ----------
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000)
OLED_WIDTH = 128
OLED_HEIGHT = 64
oled = ssd1306.SSD1306_I2C(OLED_WIDTH, OLED_HEIGHT, i2c)

# ---------- DHT11 Setup ----------
sensor = dht.DHT11(Pin(11))

def show_reading(temp_c, humidity):
    oled.fill(0)
    oled.text("DHT11 Monitor", 5, 0)
    oled.hline(0, 10, 128, 1)

    oled.text("Temp:", 0, 22)
    oled.text("{} C".format(temp_c), 70, 22)

    oled.text("Humidity:", 0, 40)
    oled.text("{} %".format(humidity), 80, 40)

    oled.show()

def show_error(message):
    oled.fill(0)
    oled.text("DHT11 Monitor", 5, 0)
    oled.hline(0, 10, 128, 1)
    oled.text("Sensor Error!", 10, 25)
    oled.text(message[:16], 5, 40)
    oled.show()

print("Starting DHT11 + SSD1306 monitor...")
print("--------------------------------------")

while True:
    try:
        sensor.measure()
        temperature = sensor.temperature()
        humidity = sensor.humidity()

        print("Temperature: {} C   |   Humidity: {} %".format(temperature, humidity))

        show_reading(temperature, humidity)

    except OSError as e:
        print("Failed to read DHT11 sensor:", e)
        show_error(str(e))

    time.sleep(2)

How the Code Works

  • I2C initialization — I2C(0, scl=Pin(1), sda=Pin(0)) sets up I2C0 on GP0/GP1 for the OLED. Keeping this on a different bus/pin group than the DHT11’s data pin avoids any electrical or timing conflicts between the two.
  • DHT11 object — dht.DHT11(Pin(15)) creates a sensor instance on GP15. Calling sensor.measure() triggers a fresh reading; sensor.temperature() and sensor.humidity() then return the last measured values.
  • show_reading() — clears the OLED buffer, writes a header, a divider line, and the temperature/humidity values, then pushes the buffer to the display with oled.show(). Nothing appears on the physical screen until show() is called — this is a common trip-up for beginners moving from LCDs to buffer-based OLED displays.
  • show_error() — instead of leaving the last good reading frozen on screen when a read fails, this refreshes the display with a clear error message so you immediately know the sensor is misbehaving rather than assuming it’s still reporting live data.
  • try/except OSError — the DHT11’s single-wire protocol occasionally drops a bit or times out, which MicroPython’s dht driver reports as an OSError. Wrapping the read in a try/except means one bad reading doesn’t crash your whole script — it just logs the error and tries again on the next loop.
  • time.sleep() — the DHT11 can only be sampled reliably about once per second. A 2-second gap keeps every reading well within spec and also makes the OLED text comfortable to read rather than flickering.

Output on Serial Monitor and OLED

Once uploaded, open Thonny’s Shell (Serial Monitor) and you’ll see continuous readings scroll by:

dht11 with Raspberry pi pico output on thonny shell

 

dht11 with Raspberry pi pico output on oled display

At the exact same time, the OLED screen shows a clean two-line readout with a “DHT11 Monitor” header, a divider, and the current temperature and humidity — updating every 2 seconds in sync with the serial output. If you disconnect the sensor’s data wire mid-test, you’ll immediately see the “Sensor Error!” message on the OLED instead of a stale, misleading reading, while the shell logs the exact OSError for debugging.

[Errno 110] ETIMEDOUT DHT11 Raspberry Pi Pico sensor error

Common Errors and How to Fix Them

  • [Errno 110] ETIMEDOUT in the shell — almost always a wiring issue. Check that DATA is on GP15, and that you have a pull-up resistor if you’re using the bare 4-pin sensor.
  • OLED stays blank — double-check the I2C address; most SSD1306 boards use 0x3C, but a few clones use 0x3D. You can scan for the address with i2c.scan() before initializing the display.
  • Readings freeze or repeat the same number — the DHT11 only refreshes internally once a second; if your loop runs faster than that, you’re reading stale data. Keep the delay at 2 seconds or more.
  • ImportError: no module named ‘ssd1306’ — the driver file wasn’t saved onto the Pico itself; re-save ssd1306.py directly to the board’s filesystem, not just to your computer.

If you run into wiring or code issues beyond this, drop your setup details in the comments or check our other Pico tutorials on circuitschools.com — we keep them updated as readers report edge cases.

Applications

  • Standalone room temperature/humidity monitor
  • Grow tent or greenhouse climate logging
  • Server room or electronics cabinet environment checks
  • A beginner-friendly base project to later add data logging, Wi-Fi (on a Pico W), or alerts

Conclusion

This project is a great next step after a basic “blink an LED” Pico tutorial — you’re reading a real-world sensor, handling its quirks gracefully, and displaying the result on two outputs at once. The same try/except and OLED pattern used here scales nicely if you want to add more sensors (a BMP280 for pressure, for instance) to the same I2C bus and build out a fuller environmental dashboard.

Add a Comment

Leave a Reply

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