CNC Machining QR Codes for Stencils

Needed to stencil some QR codes to do a street art project. Found it was really difficult to get QR codes in vector format to create a machinable design so I wrote a breif octave script to do it for me.

The script takes a target URL or payload and uses a free API to return a QR bitmap.

Using the site: and making a call to the API will return a QR code. EG:×27&data= returns:

download (4).png

Octave reads in the script and gives a preview of the API to make sure the QR code has rendered properly. Typically I was setting the resolution to the minimum ie 27×27 to keep the machining complexity as low as possible but also make the pixels as large as possible for spraypainting.

Our installation was to be a dance tutorial. The user is invited to open the link in the QR code which plays a music track. The rest of the installation is a series of dance steps that the user is invited to dance to.

The input QR looks something like this. But we want the squares to be inscribed circles so that the hole think can remain together after being machined.


The script loops through each of the pixels and creates a script file that can be opened in AutoCAD to create a DXF of the QR code.

QR cad.PNG

The code can then be machined.


And installed.


the script can be found at:



Script to take a URL and convert to a AutoCAD interpretable script for creating
QR codes. Script runs a few dialog prompts for inputs and creats a ".scr" file
which can be run in AutoCAD to create a .dxf for CNC machining.

pkg load image;

# Prompted variables
file_out_name = inputdlg ("output name for AutoCAD script"){1}
qr_size = inputdlg ("Size (in minimum pixels) of QR code - may need to run a couple of times to confirm QR is well formed"){1}
rad_drill = inputdlg ("Enter a value for the radius of the pixel ~0.5"){1}
target_url = inputdlg ("Target URL of the QR code"){1}

#Fixed/global variables
api_url = ""
complete_url ="";
fileOut = "";

# build the URL
complete_url = strcat(api_url, "size=", qr_size, "x", qr_size, "&data=", target_url)

#Get QR code online
onlineImg = imread (complete_url);

btn = questdlg ("Is the QR code well formed", "QR Code formed", "Yes", "No", "No");
if (strcmp (btn, "Yes"))
#TODO re-run size prompt url build and request

onlineImg = imcomplement(onlineImg);
onlineImg = im2bw(onlineImg);

#Nested loop through each of the pixels
for i = 1:SIZE
for j = 1:SIZE

#If the pixel is false (ie black) add a circle at that point
if (!onlineImg(i,j))

#add the circle command at the coordinate
fileOut = strcat(fileOut, "Circle ", "\r\n", num2str(i),",",num2str(j)," ",num2str(rad_drill), "\r\n");


#Write the output to file
fid = fopen (fileOutName, "w");


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s