Build a Real-Time Azure IoT Sensor Pipeline with Raspberry Pi Pico W + BME280

Build a Real-Time Azure IoT Sensor Pipeline with Raspberry Pi Pico W + BME280

Why Use Azure IoT?

Azure IoT Hub is a fully managed service that lets you ingest, process, and route device telemetry at scale. Whether you're building a smart building, remote monitoring system, or industrial automation tool, Azure IoT is a powerful backbone for your solution.

But cloud platforms can be confusing. This tutorial gives you a real, fully working end-to-end setup using the Raspberry Pi Pico W and BME280 sensor, pushing live sensor data into Azure using HTTP and viewing it in Azure Data Explorer (ADX).

Components You’ll Need

  • Raspberry Pi Pico W
  • ShillehTek BME280 Sensor (Temp, Humidity, Pressure)
  • Jumper Wires
  • Breadboard (optional)
  • Azure Account (free tier works)

What You'll Build

  • Send sensor data from the Pico W to Azure IoT Hub using HTTP
  • Ingest and store it in Azure Data Explorer
  • Query the data using Kusto

Step 1: Create an Azure IoT Hub

  1. Go to the Azure Portal
  2. Search for IoT Hub → Click Create
  3. Set:
    • Resource Group: raspberry-pi-group
    • Region: East US
    • Name: mypicowhub
  4. Networking: Public access
  5. Review + Create → Confirm and deploy

Give it time to deploy, can take a while.

Step 2: Register Your Device

  1. Go to your IoT Hub → Devices → + Add Device
  2. Device ID: picow1
  3. Auth Type: Symmetric Key → Enable auto-generate keys
  4. Click Save

Step 3: Create a SAS Token

In your terminal with Azure CLI installed, you can download the CLI with their official instructions, once you have the CLI you can run:

az iot hub generate-sas-token --hub-name mypicowhub --device-id picow1 --duration 3600

FYI make sure you sign into the Azure CLI first

This will give you the Authorization header to paste in your Pico code.

Step 4: Create Azure Data Explorer Cluster + Database

  1. Search for Azure Data Explorer Clusters
  2. Click + Create → Fill:
    • Cluster Name: picocluster
    • Workload is Dev/test

Once that is done you can add a database to the cluser:

Step 5: Create the Table + Mapping

Open your cluster → Query editor → Run:

.create table iotdata (
  deviceId: string,
  temperature: real,
  humidity: real,
  pressure: real,
  timestamp: datetime
)

Then create the JSON mapping:

.create table iotdata ingestion json mapping 'iotmap' '[{"column":"deviceId","path":"$.deviceId"},{"column":"temperature","path":"$.temperature"},{"column":"humidity","path":"$.humidity"},{"column":"timestamp","path":"$.timestamp"}]'

Step 6: Create the IoT Data Connection

  1. Go to the picosensors database → Data connectionsAdd connection
  2. Choose IoT Hub:
    • IoT Hub: mypicowhub
    • Table: iotdata
    • Format: JSON
    • Mapping: iotmap

All details are shown here (see image):

Step 7: Wire Up Your Pico W + BME280

  • BME280 VCC → Pico 3.3V
  • BME280 GND → Pico GND
  • BME280 SDA → GP0
  • BME280 SCL → GP1

Step 8: Final MicroPython Code

BME280 Library Code here:

Upload this to your Raspberry Pi Pico W:

import network
import time
import urequests
import json
from machine import Pin, I2C
import bme280

WIFI_SSID = 'SMA'
WIFI_PASS = 'mmmyellow'

IOTHUB_NAME = 'mypicowhub'
DEVICE_ID = 'picow1'
HEADERS = {
    'Authorization': 'SharedAccessSignature sr=mypicowhub.azure-devices.net%2Fdevices%2Fpicow1&sig=YOUR_SIG_HERE',
    'Content-Type': 'application/json'
}
URL = f'https://{IOTHUB_NAME}.azure-devices.net/devices/{DEVICE_ID}/messages/events?api-version=2020-09-30'

def connect_wifi():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(WIFI_SSID, WIFI_PASS)
    while not wlan.isconnected():
        print("Connecting...")
        time.sleep(1)
    print("WiFi connected:", wlan.ifconfig())

def get_iso_timestamp():
    t = time.localtime()
    return "{}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}Z".format(t[0], t[1], t[2], t[3], t[4], t[5])

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
bme = bme280.BME280(i2c=i2c)

def send_to_azure():
    temp, pressure, humidity = bme.read_compensated_data()
    temp = round(temp / 100, 2)
    pressure = round(pressure / 25600, 2)
    humidity = round(humidity / 1024, 2)

    payload = {
        'deviceId': DEVICE_ID,
        'temperature': temp,
        'humidity': humidity,
        'pressure': pressure,
        'timestamp': get_iso_timestamp()
    }

    print("Sending:", payload)
    try:
        res = urequests.post(URL, headers=HEADERS, json=payload)
        print("Response:", res.status_code)
        res.close()
    except Exception as e:
        print("Error:", e)

connect_wifi()
while True:
    send_to_azure()
    time.sleep(1)

Step 9: Visualize the Data

Run this query in Azure Data Explorer:

iotdata
| where timestamp > ago(10m)
| order by timestamp desc

Or build a chart:

iotdata
| summarize avg(temperature) by bin(timestamp, 1m)
| render timechart

Conclusion

With just a few lines of MicroPython and a tiny sensor, you’ve built a real cloud pipeline using Azure IoT Hub and ADX. This setup is great for learning, prototyping, or even as a foundation for a scalable commercial project.

If you liked this tutorial, please consider subscribing on YouTube, supporting on BuyMeACoffee, or checking out the Raspberry Pi and Arduino components available at ShillehTek.

Create a free account to access full content.

All access to code and resources on ShillehTek.

Signup Now

Already a member? Sign In

Explore More on Our Blog

Build a Real-Time Azure IoT Sensor Pipeline with Raspberry Pi Pico W + BME280

Build a Real-Time Azure IoT Sensor Pipeline with Raspberry Pi Pico W + BME280

How to send live environmental sensor data to Azure IoT Hub and visualize it in Azure Data Explorer.

How to Connect an Arduino Sensor to ROS 2 on a Raspberry Pi

How to Connect an Arduino Sensor to ROS 2 on a Raspberry Pi

Learn how to connect a BME280 sensor to an Arduino and publish real-time sensor data into ROS...

How to Install ROS 2 Humble on Raspberry Pi (Ubuntu 22.04.5 LTS)

How to Install ROS 2 Humble on Raspberry Pi (Ubuntu 22.04.5 LTS)

Learn how to install ROS 2 Humble on a Raspberry Pi 4B running Ubuntu 22.04.5 LTS. This step-by-step guide walks...

Part 5: Building a Wi-Fi Control Interface for Remote Control Robot

Part 5: Building a Wi-Fi Control Interface for Remote Control Robot

Part 4: Adding Obstacle Detection - Raspberry Pi Pico W Robotics Course

Part 4: Adding Obstacle Detection - Raspberry Pi Pico W Robotics Course

Part 3: Motor Control Programming - Raspberry Pi Pico W Robotics Course

Part 3: Motor Control Programming - Raspberry Pi Pico W Robotics Course

Part 2: Robot Assembly - Raspberry Pi Pico W Robotics Course

Part 2: Robot Assembly - Raspberry Pi Pico W Robotics Course

Build a Wi-Fi-Controlled Obstacle-Avoidance Robot with Raspberry Pi Pico W

Build a Wi-Fi-Controlled Obstacle-Avoidance Robot with Raspberry Pi Pico W

Learn how to build a remote-control robot using the Raspberry Pi Pico W and a few simple hardware components. This...

Simple Guide: Build a Reverse Geolocator with Raspberry Pi Pico W and GPS Module

Simple Guide: Build a Reverse Geolocator with Raspberry Pi Pico W and GPS Module

Reverse Geolocator Tutorial with Raspberry Pi Pico W and GPS Module

Learn how to create a reverse...

LoRa and Raspberry Pi Pico W: Building a Sender-Receiver Communication System

LoRa and Raspberry Pi Pico W: Building a Sender-Receiver Communication System

function toggleAuthorBio() { var bio = document.getElementById('authorBio'); var button = document.querySelector('.toggle-button'); if (bio.style.display === 'none') { bio.style.display = 'block'; button.textContent = '▼ About this Author'; // Using Unicode character directly button.classList.add('expanded'); } else { bio.style.display = 'none'; button.textContent = '▶ About this Author'; // Using Unicode character directly button.classList.remove('expanded'); } }