Back to list
dev_to 2026年3月21日

Raspberry Pi Pico W と DHT11 で温湿度を可視化——Miniviz を使用して IoT プロトタイプを構築

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

Translated: 2026/3/21 5:07:03
minivizraspberry-pi-pico-wdht11micropythoniot-prototype

Japanese Translation

このガイドでは、Raspberry Pi Pico W と DHT11 を使用して温度と湿度を読み取り、Miniviz にデータを送信し、それを可視化する方法を解説します。これは、IoT プロトタイプ、趣味の電子機器、および学習向けの堅実なセットアップです。 Miniviz とは 構築するもの 必要なもの ピン配置 VS Code と MicroPython の設定 Pico ファームウェアのインストール サンプル読み取りスクリプト Miniviz への送信用プロジェクト ID とトークンを取得 Miniviz へ送信するためのソースコード Miniviz でのデータ表示 チャートの作成 まとめ Pro プラン ベータ / モニタリングプログラム Miniviz は、IoT データと画像を簡単に保存、可視化、通知するサービスです。これは、プロトタイプ(PoC)、趣味のプロジェクト、そして教育に適しています。 Miniviz — IoT データ可視化およびグラフ化プラットフォーム あなたは Raspberry Pi Pico W と DHT11 温度/湿度センサーを使用して、読み取りデータを収集し、Miniviz で可視化します。 Raspberry Pi Pico W(ここでは「Pico」と呼びますが) DHT11 温度/湿度センサー ブレッドボードとジャンパーケーブル MicroPython エンドビジョン Miniviz プロジェクト ID と API トークン 写真に示すように接続します。 画像:ワイヤリング写真 Pico ピン DHT11 役割 36 VCC 電源 20 (GP15) DATA シグナル 38 GND 接地 画像:黄色の VCC、青色の GND、緑色の GP15 このウォークスルーでは、VS Code における MicroPython ワークフローを使用します。 MicroPico 拡張機能のインストール——これは、Pico への通信とコードの転送を管理するのに役立ちます。 MicroPico を実行:コマンドパレット(Ctrl+Shift+P)からプロジェクトを設定 これにより、フォルダーに Pico 固有の完成と接続設定が作成されます。 画像:拡張機能 UI 画像:下部ステータスバー/MicroPico コントロール 公式サイトから適切な UF2 ファイルをダウンロード(Pico または Pico W)。 ボードに USB を接続する際に BOOTSEL ボタンを押します。 Pico が USB ドライブとして現れたら、UF2 をそれにコピーします。 自動的にリブートされ、準備完了です。 MicroPython on Raspberry Pi Pico 環境が動作するようになったら、このサンプルを実行します。 ボード上の LED は、各成功した読み取りでパルプします。 from machine import Pin import dht import time led = Pin("LED", Pin.OUT) # DHT11 が GPIO 15 に接続されている sensor = dht.DHT11(Pin(15)) print("測定を開始しました...") while True: try: # メasurement トリガー sensor.measure() # 値を取得 temperature = sensor.temperature() humidity = sensor.humidity() print(f"Temperature: {temperature}°C, Humidity: {humidity}%") # 成功時にボード上の LED を点灯 led.on() time.sleep(0.1) led.off() except OSError as e: print("センサーの読み取りに失敗しました。ケーブル接続を確認してください!") # DHT11 要件に合わせて 2 秒待機 time.sleep(2) コンソールで温度と湿度が表示されるはずです。 画像:Run をクリックした後の出力 スクリプトを Wi-Fi、タイムシンク(NTP)、そして HTTP で拡張し、Miniviz へ POST できるようにします。 Miniviz でプロジェクトを作成し、プロジェクト ID と API トークンをコピーします。 詳細については、クイックリファレンスを確認してください。 画像:プロジェクト ID とトークン画面 Wi-Fi クレデンシャル、プロジェクト ID、トークンを自分自身のものに入れ替えます。 import network import urequests import time import machine import dht import ntptime # ================= 設定 ================= WIFI_SSID = "YOUR_WIFI_SSID" # Wi-Fi SSID WIFI_PASS = "YOUR_WIFI_PASSWORD" # Wi-Fi パスワード PROJECT_ID = "YOUR_PROJECT_ID" # Miniviz プロジェクト ID TOKEN = "YOUR_TOKEN" # Miniviz API トークン LABEL_KEY = "PicoW_DHT" # デバイス用のラベル SEND_INTERVAL = 120 # 送信間隔(秒) # ================================================= # ハードウェアセットアップ 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(): """Wi-Fi に接続し、NTP を使用して時間同步を行う""" wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(WIFI_SSID, WIFI_PASS) print(f"接続中、

Original Content

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. What is Miniviz? What you’ll build What you need Pinout Set up VS Code and MicroPython Install the Pico firmware Sample read script Get your project ID and token Source code to send to Miniviz Viewing data in Miniviz Creating a chart Wrap-up Pro plan beta / monitor program Tags 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 You’ll use a Raspberry Pi Pico W and a DHT11 temperature/humidity sensor to collect readings and visualize them in Miniviz. 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 Wire it as shown in the photo. Image: wiring photo Pico pin DHT11 Role 36 VCC Power 20 (GP15) DATA Signal 38 GND Ground Image: yellow VCC, blue GND, green GP15 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 Download the correct UF2 file for your board (Pico or Pico W) from the official site. Hold the BOOTSEL button on the board while plugging in USB. When the Pico appears as a USB drive, copy the UF2 onto it. It will reboot automatically; you’re ready. MicroPython on Raspberry Pi Pico 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) You should see temperature and humidity in the console. Image: output after clicking Run 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 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() You should see send logs in the console. Image: log on successful send Open the Database section to inspect incoming points. It may take on the order of ~30 seconds to show up. Image: Database view Use Viz → create a chart. This example uses a line chart. Image: chart setup Image: resulting line chart 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. 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 #IT #indiedev #IoT #electronics #RaspberryPi #RaspberryPiPico