Go supports IoT work in two ways. On Linux-based devices such as a Raspberry Pi, standard Go cross-compiles to a single static binary for ARM. On microcontrollers with only kilobytes of memory, TinyGo compiles a large subset of Go to small firmware images. Pair either with MQTT for messaging and you have a practical IoT stack.
Which route you take depends on the hardware: if the device runs an operating system with megabytes of RAM, use the standard toolchain; if it is a bare microcontroller, use TinyGo.
Go has several properties that suit devices in the field:
GOOS=linux GOARCH=arm64 go build runs on your laptop and produces a binary for the device.context, which removes many dependencies from the device image.The costs are a runtime and garbage collector, so a standard Go binary is typically a few megabytes and is not meant for chips with tens of kilobytes of RAM.
For boards such as the Raspberry Pi, build on your development machine and copy the binary over:
-ldflags="-s -w" strips symbol and debug information to shrink the binary. Run it under systemd with Restart=always so the device recovers by itself after a crash or reboot.
On a Linux board you reach GPIO, I2C and SPI through libraries rather than the standard library. Well-known options are periph.io (periph.io/x/conn and periph.io/x/host), Gobot (gobot.io/x/gobot), and libraries built on the Linux GPIO character device. Check each project's documentation for the board it supports, as pin naming differs between boards.
Whatever the library, structure the code so hardware sits behind an interface. That keeps the logic testable on your laptop:
MQTT is the common lightweight publish and subscribe protocol for IoT. The Eclipse Paho Go client (github.com/eclipse/paho.mqtt.golang) is widely used:
The call uses QoS 1, which delivers the message at least once. In production, use TLS (ssl:// brokers), per-device credentials or certificates, and buffer readings locally when the network is down.
TinyGo is a separate compiler based on LLVM that targets microcontrollers and WebAssembly. It supports many boards from vendors such as Arduino, Adafruit, Raspberry Pi (RP2040) and Espressif, plus several chip families. The supported-language and standard-library subset is smaller than regular Go, so check the TinyGo documentation for your target and for packages you depend on.
The machine package gives access to pins, I2C, SPI, UART and ADC, with names defined per board. Replace pico with your board's target name, which you can list in the TinyGo documentation.
| Aspect | Standard Go | TinyGo |
|---|---|---|
| Typical target | Linux boards, gateways, servers | Microcontrollers, WebAssembly |
| Memory needed | Megabytes | Kilobytes |
| Standard library | Complete | Partial |
| Goroutines and channels | Full | Supported, with a smaller scheduler |
| Reflection and some packages | Full | Limited |
context for shutdown and log/slog for structured logs on Linux-class devices.No. Classic AVR boards have far too little memory for the standard Go runtime. TinyGo supports some Arduino boards, mainly the ARM-based ones, and has limited AVR support, so check your exact board.
For firmware with strict timing or tiny memory budgets, C or Rust still dominate. TinyGo is a good fit when you value readability and fast iteration and your board is supported.
MQTT is the usual choice for telemetry and commands over unreliable networks. Use HTTPS or gRPC when the device is powerful and talks to a service directly.
Hide the hardware behind an interface and substitute a fake in tests, as in the Sensor example above.
Use standard Go with cross-compilation for Linux-based devices, TinyGo for microcontrollers, and MQTT for telemetry. Keep hardware behind interfaces, design for flaky networks, and ship small, signed, updatable binaries.