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
- Go to the Azure Portal
 - Search for IoT Hub → Click Create
 - Set:
- Resource Group: 
raspberry-pi-group - Region: 
East US - Name: 
mypicowhub - 

 
 - Resource Group: 
 - Networking: Public access
 - Review + Create → Confirm and deploy
 
Give it time to deploy, can take a while.
Step 2: Register Your Device
- Go to your IoT Hub → Devices → + Add Device
 - Device ID: 
picow1 - Auth Type: Symmetric Key → Enable auto-generate keys
 - 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

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

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
- Go to the 
picosensorsdatabase → Data connections → Add connection - Choose IoT Hub:
- IoT Hub: 
mypicowhub - Table: 
iotdata - Format: 
JSON - Mapping: 
iotmap 
 - IoT Hub: 
 
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.
                  

