Raspberry Pi

10 Raspberry Pi 5 IoT Projects with MQTT (From Sensor Hubs to AI Cameras)

Ten practical Raspberry Pi 5 IoT projects that use MQTT for messaging, with the hardware, topic layout and starting code for each, from a home sensor hub to an AI camera and a factory gateway.

Raspberry Pi 5 surrounded by sensors, a camera and a dashboard screen, illustrating raspberry pi 5 iot projects with MQTT
Run this on your own MQTT brokerGet a private, managed MQTT broker on the Free plan and start from ready-made code samples.
Try it free Code samples No card required

These Raspberry Pi 5 IoT projects show what the newest Pi does well: more CPU headroom, fast NVMe storage, two camera connectors and an optional AI accelerator, all in a board that still runs the same Python and Node-RED tools as before. Each of the ten projects below uses MQTT for messaging, so the pieces can talk to each other, to dashboards and to your phone. You can try every one against the free broker at broker.connectmq.com before moving it to private credentials.

What the Raspberry Pi 5 Changes for IoT

The Pi 5 is a significant step up from the Pi 4 for always-on projects. Its quad-core Cortex-A76 CPU runs heavier workloads such as local databases, computer vision and multiple protocol bridges at the same time. A PCIe connector accepts NVMe SSDs through the M.2 HAT+, which removes the SD card as a reliability weak spot. The board adds a real-time clock (with a battery connector), a power button and two four-lane camera/display connectors. GPIO moved to the new RP1 I/O controller, which is why current libraries such as gpiozero with the lgpio backend are the way to drive pins.

The trade-offs are power and heat: the Pi 5 wants a 5 V 5 A USB-C supply to run USB peripherals at full current, and it benefits from the Active Cooler under sustained load. For battery-powered sensor nodes, a Pico W or an ESP32 is often the better choice, with the Pi 5 acting as the hub, since they sleep between readings and wake only to publish.

A Shared Topic Layout

All ten projects use the same topic convention, so you can combine them later without renaming anything:

connectmq/demo/<your-id>/<project>/<device>/<measurement>
connectmq/demo/<your-id>/<project>/<device>/status          (retained, Last Will)
connectmq/demo/<your-id>/<project>/<device>/<output>/set    (commands, not retained)

And the same minimal publisher, which every project extends:

import json, time, uuid
import paho.mqtt.client as mqtt

PREFIX = "connectmq/demo/p5x9m3"
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id=f"pi5-{uuid.uuid4().hex[:8]}")
client.will_set(f"{PREFIX}/hub/pi5/status", "offline", qos=1, retain=True)
client.connect("broker.connectmq.com", 1883, keepalive=30)
client.loop_start()
client.publish(f"{PREFIX}/hub/pi5/status", "online", qos=1, retain=True)

while True:
    with open("/sys/class/thermal/thermal_zone0/temp") as f:
        cpu_c = int(f.read()) / 1000
    client.publish(f"{PREFIX}/hub/pi5/cpu_temp", json.dumps({"value": cpu_c, "ts": int(time.time())}), qos=1)
    time.sleep(10)

The 10 Projects at a Glance

# Project Key hardware Difficulty
1 Home sensor hub BME280, DS18B20 Beginner
2 Energy monitor Modbus energy meter or CT clamp ADC Intermediate
3 AI camera with object events Camera Module 3 or AI Camera, AI Kit Advanced
4 Multi-protocol gateway BLE, LoRa, Modbus Intermediate
5 Wall-mounted MQTT dashboard Touch display Beginner
6 Local time-series stack NVMe SSD Intermediate
7 Smart irrigation controller Relays, soil moisture sensors Intermediate
8 Air quality station PM2.5 and CO2 sensors Beginner
9 Machine monitoring gateway Modbus TCP or CAN Advanced
10 Fleet health monitor Nothing extra Beginner

1. Home Sensor Hub

Wire a BME280 (temperature, humidity, pressure) over I2C and a few DS18B20 probes on one-wire, then publish each reading every minute with retained messages so dashboards show values immediately. The Pi 5 has headroom to also run Node-RED or Home Assistant on the same board. DS18B20 probes are waterproof, which makes them a good fit for tanks, fridges and outdoor readings.

2. Energy Monitor

Read a DIN-rail energy meter over Modbus RTU with a USB-RS485 adapter, or measure current with CT clamps and an ADC HAT. Publish power every few seconds and energy totals every minute. Threshold alerts on power draw can warn you when a device is left on. Have a qualified electrician fit anything inside a distribution board.

3. AI Camera with Object Events

This is where the Pi 5 shines. Use Camera Module 3 with the Hailo-based AI Kit or AI HAT+, or the Raspberry Pi AI Camera, which runs the model on the sensor itself. Run detection locally and publish events, not video: a small JSON message such as {"label": "person", "confidence": 0.91, "zone": "driveway"} on .../camera/front/detections. Keep images on the Pi or upload them separately; MQTT carries the metadata. The camera motion detection over MQTT tutorial is a good non-AI starting point.

4. Multi-Protocol Gateway

Combine Bluetooth sensors, a LoRa radio and a Modbus device on one Pi 5, each running as its own service and publishing into one topic tree. The extra cores let all three bridges run without competing for CPU. Follow the Raspberry Pi BLE to MQTT bridge for the Bluetooth side, then add others one at a time.

5. Wall-Mounted MQTT Dashboard

Attach the official touch display, boot into a full-screen browser and show a dashboard that subscribes over secure WebSocket on port 8084. Because the Pi 5 renders web pages smoothly, charts and live gauges stay responsive. Add buttons that publish commands to .../set topics for lights or relays elsewhere in the house.

6. Local Time-Series Stack

Put an NVMe SSD on the M.2 HAT+ and run Telegraf, InfluxDB and Grafana. Telegraf subscribes to your MQTT topics as a normal client and writes to InfluxDB, and Grafana graphs the history. The SSD handles the constant writes far better than an SD card. The Grafana and InfluxDB on Raspberry Pi guide covers the setup.

7. Smart Irrigation Controller

Capacitive soil moisture sensors through an ADC, a relay board for valves and a weather forecast fetched by a small script: the Pi decides when to water and publishes every decision. Make commands non-retained and add a maximum run time per valve in the code, so a lost connection never leaves the water running.

8. Air Quality Station

A PM2.5 particle sensor over serial and an NDIR CO2 sensor over I2C give a useful indoor air picture. Publish both every 30 seconds, and alert when CO2 climbs, which is a practical reminder to ventilate a room. Give the sensors a few minutes to warm up before trusting the first readings.

9. Machine Monitoring Gateway

In a workshop or small factory, a Pi 5 can poll a PLC over Modbus TCP or listen to a machine's CAN bus, then publish states and counters under an ISA-95 style path such as site1/workshop/line1/press2/state. That structure feeds a Unified Namespace and works with tools that understand plant hierarchies. For cabinet installs, consider an industrial Compute Module based device with 24 V power and DIN-rail mounting.

10. Fleet Health Monitor

If you run more than one Pi, have each publish CPU temperature, throttling flags, disk space and uptime every minute, plus a retained Last Will status. One dashboard then shows the health of every device, and alerts fire before a full disk or overheating causes downtime. The minimal publisher above is already the first step: add disk usage from shutil.disk_usage("/") and the output of vcgencmd get_throttled.

Making Any Project Production-Ready

Every project above starts on the free public MQTT broker, which is perfect for experiments but readable by anyone. Before you rely on a project, work through this list:

  1. Move to a private broker with TLS on port 8883 and per-device credentials.
  2. Run each script as a systemd service with automatic restart.
  3. Boot from NVMe or USB SSD rather than an SD card.
  4. Buffer readings locally during network outages.
  5. Harden SSH, enable the firewall and keep the OS updated.
  6. Publish a heartbeat and Last Will so you know when a device stops.

The Raspberry Pi reliability tips cover points 2 to 4 in depth, and the Raspberry Pi MQTT tutorial is the place to start if MQTT on the Pi is new to you. The official Raspberry Pi 5 documentation lists the board's connectors and power requirements.

A cloud MQTT broker ties all ten projects together: sensors at home, a gateway in the workshop and a dashboard on your phone all connect outbound to the same broker, with no port forwarding. ConnectMQ provides exactly that as a managed service, with a live topic explorer, threshold alerts and a devices view built into the portal.

Build Your Next Pi 5 Project on ConnectMQ

Create a free ConnectMQ Serverless broker at app.connectmq.com, no credit card required, and you will have TLS credentials in a couple of minutes. Point any of these projects at it and watch your topics appear in the browser as soon as the Pi connects.

Frequently Asked Questions

Is the Raspberry Pi 5 overkill for simple IoT projects?

For a single sensor, often yes; a Pico W or Zero 2 W is cheaper and uses less power. The Pi 5 pays off when one device runs several services, a database or computer vision.

Do Pi 4 projects work on the Pi 5?

Most do. The main exception is GPIO code written for RPi.GPIO, which does not support the Pi 5; switch to gpiozero or lgpio.

Which MQTT library should I use on the Pi 5?

paho-mqtt 2.x is the standard choice for Python, and Node-RED's built-in MQTT nodes work well for flow-based projects. Both run unchanged on the Pi 5.

Can several projects share one broker?

Yes. Give each project its own topic branch and each device its own client ID, and one broker can serve all of them, within your plan's connection limits.

Related articles

Pico W vs Pico 2 W for MQTT: RP2040 vs RP2350 Performance, Memory and TLS

The Pico 2 W keeps the Pico W's footprint and Wi-Fi chip but swaps the RP2040 for the faster RP2350. This comparison looks at what that means for MQTT devices: CPU, memory, TLS, security features, software support, and which board to buy for which project.

8 min read

Raspberry Pi RFID MQTT Access Logging with the RC522 Reader

Wire an RC522 RFID reader to a Raspberry Pi, read tags in Python, check them against a local allowlist and publish every access attempt as an MQTT event that loggers, dashboards and alerting tools can consume.

7 min read

All articles →

Your private MQTT broker is a few clicks away

Create an account, get your broker credentials and connect your first device — no servers to install, patch or scale.