Source: https://mokxi.com/libraries/qrcode
Updated: 2026-11-02

Libraries / Data and time
Arduino library · Data and time

# QRCode: generate a QR code on the board itself

Richard Moore’s QRCode library builds a QR code on the microcontroller from any text, a URL, a WiFi login or a serial number, so a device can show a code that changes without a phone app or an internet service. It hands you the code as a grid of dark and light squares (modules), and you draw them on a display or print them to Serial.

Open the example in the editor See the calls

Built in on Mokxi: #include <qrcode.h> and it builds, with nothing to install. Free, and no account needed.

## What QRCode does

Two numbers control the code. The version, from 1 to 40, sets its size: version 1 is 21 by 21 modules and each version adds 4. The error correction level, ECC_LOW to ECC_HIGH, sets how much of the code can be damaged and still read, at the cost of how much text fits. Version 3 with ECC_LOW holds 53 bytes of text, enough for a short URL.

The buffer for the code is yours to provide, sized with qrcode_getBufferSize(version). On a 128x64 OLED, a version 3 code at two pixels a module is 58 pixels square, which fits with room for the quiet zone scanners need around it.

Library Manager name | QRCode

Author | Richard Moore

Include | #include <qrcode.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | OLED display, 128x64

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <qrcode.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "QRCode" by Richard Moore from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add QRCode to lib_deps in PlatformIO. Mokxi follows the calls of release 0.0.1, so a sketch written here builds there too.

What to know in the simulator: The mask is the lowest penalty under the standard’s rules; another library may pick another, and either scans.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### QRCode qrcode

Holds the code’s size and a pointer to its modules once it is built.

### qrcode_getBufferSize(3)

How many bytes a version 3 code needs. Use it to size a uint8_t array.

### qrcode_initText(&qrcode, qrcodeData, 3, ECC_LOW, "https://mokxi.com")

Builds the code for the text at that version and error correction level. It returns 0 on success and a negative number if the text does not fit.

### qrcode_getModule(&qrcode, x, y)

True when the module at x, y is dark. qrcode.size is the number of modules along each side.

### qrcode_initBytes(&qrcode, qrcodeData, 3, ECC_LOW, data, length)

The same for binary data of a given length, always using byte mode.

## Example: A QR code on the Serial Monitor

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### The code is blank or qrcode_initText() returns a negative value

The text is too long for the version and error correction chosen. Raise the version by one or two, or drop to ECC_LOW, and size the buffer again with qrcode_getBufferSize().

### Phones will not scan the code on the screen

Draw each module at least two pixels wide, leave a blank border of about four modules around the code, and if a scanner struggles with white on black, draw dark modules on a lit background.

### The board resets when making a large code

A high version needs a big buffer, and a local array that large overflows an Uno’s 2 KB of RAM. Keep to small versions on AVR boards, or make the buffer a global so the compiler reports its size.

## Keep going

### Learn

- Arduino OLED Display (SSD1306) Tutorial

### Parts

- OLED display, 128x64

### More data and time libraries

- Madgwick
- PID
- TimerOne
- MsTimer2
- Low-Power
- RTClib
- DS1307RTC
- DS3231 (NorthernWidget) and DS3231 (Rinky-Dink Electronics)

Every built-in library · Open the editor

## Try QRCode without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
