DEV Community

Cover image for Visualize Temperature & Humidity with Raspberry Pi Pico W DHT11 — Build an IoT Prototype with Miniviz
Yoshida.T
Yoshida.T

Posted on

Visualize Temperature & Humidity with Raspberry Pi Pico W DHT11 — Build an IoT Prototype with Miniviz

Visualize Temperature & Humidity with Raspberry Pi Pico W × DHT11 — Build an IoT Prototype with Miniviz

Japanese: devto_pico_temphumi.ja.md

This guide walks through reading temperature and humidity with a Raspberry Pi Pico W and a DHT11, sending the data to Miniviz, and visualizing it.

It’s a solid setup for IoT prototypes, hobby electronics, and learning.

Table of contents

What is Miniviz?

Miniviz is a service for easily storing, visualizing, and notifying on IoT data and images.

It fits prototypes (PoC), hobby projects, and education.

Miniviz - IoT Data Visualization & Graphing Platform

What you’ll build

You’ll use a Raspberry Pi Pico W and a DHT11 temperature/humidity sensor to collect readings and visualize them in Miniviz.

What you need

  • Raspberry Pi Pico W (referred to as “Pico” below)
  • DHT11 temperature/humidity sensor
  • Breadboard and jumper wires
  • MicroPython environment
  • Miniviz project ID and API token

Wiring the Pico and DHT11

Wire it as shown in the photo.

Image: wiring photo

Pinout

Pico pin DHT11 Role
36 VCC Power
20 (GP15) DATA Signal
38 GND Ground

Image: yellow VCC, blue GND, green GP15

Reading sensor data

Set up VS Code and MicroPython

This walkthrough uses the MicroPython workflow in VS Code.

  • Install the MicroPico extension — it helps manage talking to the Pico and transferring code.
  • Run MicroPico: Configure project from the Command Palette (Ctrl+Shift+P) This creates Pico-specific completion and connection settings in your folder.

Image: extension UI

Image: bottom status bar / MicroPico controls

Install the Pico firmware

  1. Download the correct UF2 file for your board (Pico or Pico W) from the official site.
  2. Hold the BOOTSEL button on the board while plugging in USB.
  3. When the Pico appears as a USB drive, copy the UF2 onto it.
  4. It will reboot automatically; you’re ready.

MicroPython on Raspberry Pi Pico

Sample read script

Once your environment works, run this sample.

The onboard LED blinks on each successful read.

from machine import Pin
import dht
import time

led = Pin("LED", Pin.OUT)

# DHT11 connected to GPIO 15
sensor = dht.DHT11(Pin(15))

print("Starting measurements...")

while True:
    try:
        # Trigger measurement
        sensor.measure()

        # Get values
        temperature = sensor.temperature()
        humidity = sensor.humidity()

        print(f"Temperature: {temperature}°C, Humidity: {humidity}%")

        # Blink onboard LED on success
        led.on()
        time.sleep(0.1)
        led.off()

    except OSError as e:
        print("Failed to read sensor. Check wiring!")

    # Wait for 2 seconds (DHT11 requirement)
    time.sleep(2)
Enter fullscreen mode Exit fullscreen mode

You should see temperature and humidity in the console.

Image: output after clicking Run

Sending data to Miniviz

Get your project ID and token

Extend the script with Wi-Fi, time sync (NTP), and HTTP so you can POST to Miniviz.

Create a project in Miniviz and copy the project ID and API token.

See the quick reference for details.

Image: project ID and token screen

Source code to send to Miniviz

Replace Wi-Fi credentials, project ID, and token with your own.

import network
import urequests
import time
import machine
import dht
import ntptime

# ================= Configuration =================
WIFI_SSID  = "YOUR_WIFI_SSID"       # Wi-Fi SSID
WIFI_PASS  = "YOUR_WIFI_PASSWORD"   # Wi-Fi Password
PROJECT_ID = "YOUR_PROJECT_ID"      # Miniviz Project ID
TOKEN      = "YOUR_TOKEN"           # Miniviz API Token
LABEL_KEY  = "PicoW_DHT"            # Label for the device
SEND_INTERVAL = 120                 # Interval between sends (seconds)
# =================================================

# Hardware Setup
dht_sensor = dht.DHT11(machine.Pin(15))
try:
    led = machine.Pin("LED", machine.Pin.OUT)
except ValueError:
    led = machine.Pin(25, machine.Pin.OUT)

def connect_wifi():
    """Connect to Wi-Fi and sync time via NTP"""
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(WIFI_SSID, WIFI_PASS)

    print(f"Connecting to {WIFI_SSID}...", end="")
    while not wlan.isconnected():
        led.toggle()
        time.sleep(0.5)

    print("\n✅ Wi-Fi Connected!")
    led.off()

    # Attempt time synchronization using NTP
    ntptime.host = "ntp.nict.jp"
    try:
        print("Syncing time via NTP...", end="")
        ntptime.settime()
        print(" Done!")
    except:
        print(" Failed (Using internal clock)")

def send_data_to_miniviz(temp, hum):
    """Send measurement data to Miniviz and log details"""
    url = f"https://api.miniviz.net/api/project/{PROJECT_ID}?token={TOKEN}"

    # Calculate UNIX timestamp in milliseconds
    # Assuming time.time() is synced to 1970 Epoch
    unix_time_sec = time.time()
    ts_ms = int(unix_time_sec * 1000)

    # Create Miniviz-compliant payload
    payload = {
        "timestamp": ts_ms,
        "label_key": LABEL_KEY,
        "payload": {
            "temperature": temp,
            "humidity": hum
        }
    }

    print("\n" + "=" * 40)
    print("📡 Data Packet Prepared")
    print(f"  [Timestamp] {ts_ms}")
    print(f"  [Label]     {LABEL_KEY}")
    print(f"  [Metrics]   Temp: {temp}°C, Humidity: {hum}%")
    print("-" * 40)

    try:
        print("🚀 Sending request to Miniviz...", end="")
        res = urequests.post(url, json=payload)

        if res.status_code in [200, 201]:
            print(f"\n✅ Success! (Status: {res.status_code})")
            print(f"  Response: {res.text}")
            # Blink LED twice on successful transmission
            for _ in range(2):
                led.on()
                time.sleep(0.1)
                led.off()
                time.sleep(0.1)
        else:
            print(f"\n❌ Server Error (Status: {res.status_code})")
            print(f"  Reason: {res.text}")

        res.close()
    except Exception as e:
        print(f"\n⚠️ Network/Connection Error: {e}")
    print("=" * 40)

def main():
    connect_wifi()

    print("\nStarting Telemetry (Ctrl+C to stop)")

    while True:
        try:
            # Read from sensor
            dht_sensor.measure()
            t = dht_sensor.temperature()
            h = dht_sensor.humidity()

            # Send data
            send_data_to_miniviz(t, h)

        except OSError as e:
            print(f"❌ Sensor Read Error: {e}")

        # Wait for the next interval
        time.sleep(SEND_INTERVAL)

if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

You should see send logs in the console.

Image: log on successful send

Viewing data in Miniviz

Open the Database section to inspect incoming points.

It may take on the order of ~30 seconds to show up.

Image: Database view

Creating a chart

Use Viz → create a chart.

This example uses a line chart.

Image: chart setup

Image: resulting line chart

Wrap-up

You used a Raspberry Pi Pico to stream temperature and humidity into Miniviz with minimal setup.

Miniviz also supports many other sensor payloads and images — give it a try.

Pro plan beta / monitor program

We’re looking for people to try the Pro plan and share feedback. Individuals, students, and companies who can use it for a while and report back may receive Pro access for a limited time — contact us or DM for details.

There’s also a 14-day free trial. Pro lifts limits and adds image workflows — worth a look.

Miniviz - IoT Data Visualization & Graphing Platform

Tags

#IT #indiedev #IoT #electronics #RaspberryPi #RaspberryPiPico

Top comments (0)