---
title: "DIN rail enclosure, 3D printed: a case for a PCB, relay or Shelly that clips onto a 35 mm rail"
description: "The clip geometry that snaps onto a 35 mm DIN rail, module widths in 17.5 mm steps, terminal access, and a prompt for a rail-mounted ESP32 or relay housing."
canonical: https://speakcad.com/blog/din-rail-enclosure-3d-print
published: 2026-09-08
updated: 2026-09-08
publisher: SpeakCAD
---

# DIN rail enclosure, 3D printed: a case for a PCB, relay or Shelly that clips onto a 35 mm rail

> The clip geometry that snaps onto a 35 mm DIN rail, module widths in 17.5 mm steps, terminal access, and a prompt for a rail-mounted ESP32 or relay housing.

## The rail

A standard top-hat DIN rail is 35 mm wide and 7.5 mm deep (15 mm on heavy versions). Devices clip onto its two lips. Widths of commercial modules come in multiples of 17.5 mm, so a 2-module device is 35 mm wide and a 4-module one is 70 mm. Matching those widths keeps a printed case tidy in a consumer unit.

## The clip

A printed clip has a fixed hook on one side and a sprung latch on the other:

- Hook: a 1.5 mm lip that catches the top rail edge
- Latch: a 1.2 mm thick cantilever, 20 mm long, with a 45° lead-in and a 1 mm lip, that flexes over the bottom edge
- Rail slot: 35.4 mm between the hook and the latch face, 7.8 mm deep

Print the clip with the cantilever lying flat (in the plane of the layers) so it flexes along the layer lines instead of snapping across them. PETG lasts longer than PLA here. The AI orients it correctly when you ask for a DIN clip.

## Two ways to build

1. **A DIN adapter plate** that a device screws or clips onto: fastest, works with any existing case, for a Shelly or a bare sensor board.
2. **A DIN enclosure** with the clip on the back and the board inside, modular width, terminals reachable from the front.

## The prompt (enclosure)

> **Prompt** A 4-module DIN rail enclosure, 70 mm wide, 90 mm tall, 58 mm deep, for an ESP32 DevKit (55 x 28 mm, no holes, edge rails) and a 2-channel relay board (50 x 38 mm, 3 mm corner holes). 2 mm walls, a DIN clip on the back for a 35 mm rail with a 1.2 mm sprung latch, two 25 x 8 mm terminal openings on the front face, a micro USB cutout on the side, hex vents on top, screwed front cover with M3 pillars.

## The prompt (adapter)

> **Prompt** A DIN rail adapter plate 60 x 40 x 4 mm with a clip for a 35 mm rail on the back, a 1.5 mm fixed hook and a 20 mm long sprung latch, and four 3.2 mm holes on a 45 x 30 mm pattern on the front for a small PCB.

## Home automation modules

Shelly, Sonoff and Zigbee devices are the usual suspects. The library has a [Shelly 2PM Gen3 DIN adapter](/library/shelly-2pm-gen3-din-adapter) and a [Home Assistant Yellow DIN rail clip](/library/home-assistant-yellow-din-rail-clip) ready to open. Give the device's outline and it gets a pocket on the plate.

## Safety

Mains wiring belongs in enclosures rated for it. A printed housing is fine for low-voltage boards and for holding a mains device that already has its own insulated case. Keep 8 mm creepage between low-voltage and mains terminals if both are in one box, and ask for an internal wall.

## Prompts to try

- A 4-module DIN rail enclosure, 70 mm wide, 90 mm tall, 58 mm deep, for an ESP32 DevKit (55 x 28 mm, no holes, edge rails) and a 2-channel relay board (50 x 38 mm, 3 mm corner holes). 2 mm walls, a DIN clip on the back for a 35 mm rail with a 1.2 mm sprung latch, two 25 x 8 mm terminal openings on the front face, a micro USB cutout on the side, hex vents on top, screwed front cover with M3 pillars. ([open in SpeakCAD](https://app.speakcad.com/signup?next=%2F%3Fprompt%3DA%25204-module%2520DIN%2520rail%2520enclosure%252C%252070%2520mm%2520wide%252C%252090%2520mm%2520tall%252C%252058%2520mm%2520deep%252C%2520for%2520an%2520ESP32%2520DevKit%2520(55%2520x%252028%2520mm%252C%2520no%2520holes%252C%2520edge%2520rails)%2520and%2520a%25202-channel%2520relay%2520board%2520(50%2520x%252038%2520mm%252C%25203%2520mm%2520corner%2520holes).%25202%2520mm%2520walls%252C%2520a%2520DIN%2520clip%2520on%2520the%2520back%2520for%2520a%252035%2520mm%2520rail%2520with%2520a%25201.2%2520mm%2520sprung%2520latch%252C%2520two%252025%2520x%25208%2520mm%2520terminal%2520openings%2520on%2520the%2520front%2520face%252C%2520a%2520micro%2520USB%2520cutout%2520on%2520the%2520side%252C%2520hex%2520vents%2520on%2520top%252C%2520screwed%2520front%2520cover%2520with%2520M3%2520pillars.))
- A DIN rail adapter plate 60 x 40 x 4 mm with a clip for a 35 mm rail on the back, a 1.5 mm fixed hook and a 20 mm long sprung latch, and four 3.2 mm holes on a 45 x 30 mm pattern on the front for a small PCB. ([open in SpeakCAD](https://app.speakcad.com/signup?next=%2F%3Fprompt%3DA%2520DIN%2520rail%2520adapter%2520plate%252060%2520x%252040%2520x%25204%2520mm%2520with%2520a%2520clip%2520for%2520a%252035%2520mm%2520rail%2520on%2520the%2520back%252C%2520a%25201.5%2520mm%2520fixed%2520hook%2520and%2520a%252020%2520mm%2520long%2520sprung%2520latch%252C%2520and%2520four%25203.2%2520mm%2520holes%2520on%2520a%252045%2520x%252030%2520mm%2520pattern%2520on%2520the%2520front%2520for%2520a%2520small%2520PCB.))
- A 2-module DIN rail case, 35 mm wide, 90 mm tall, 60 mm deep, for a Raspberry Pi Pico on 2 mm pegs (47 x 11.4 mm) and a 4-way screw terminal block reachable from the front, DIN clip on the back, micro USB cutout on top, snap-fit front cover. ([open in SpeakCAD](https://app.speakcad.com/signup?next=%2F%3Fprompt%3DA%25202-module%2520DIN%2520rail%2520case%252C%252035%2520mm%2520wide%252C%252090%2520mm%2520tall%252C%252060%2520mm%2520deep%252C%2520for%2520a%2520Raspberry%2520Pi%2520Pico%2520on%25202%2520mm%2520pegs%2520(47%2520x%252011.4%2520mm)%2520and%2520a%25204-way%2520screw%2520terminal%2520block%2520reachable%2520from%2520the%2520front%252C%2520DIN%2520clip%2520on%2520the%2520back%252C%2520micro%2520USB%2520cutout%2520on%2520top%252C%2520snap-fit%2520front%2520cover.))

## FAQ

### Will a printed DIN clip hold?

Yes for light devices. A 1.2 mm PETG cantilever with a 1 mm lip holds a few hundred grams and survives many cycles. Print the latch flat so it bends along the layers, and use PETG rather than PLA in a warm cabinet.

### What width should the case be?

A multiple of 17.5 mm: 35 mm for 2 modules, 52.5 for 3, 70 for 4. The generator rounds to that when you say the module count.

### Can I put mains in a printed box?

Put mains devices that already have their own rated insulation on a printed plate or in a printed housing; keep bare mains terminals in a rated enclosure. For mixed boxes, keep 8 mm between mains and low-voltage parts and ask for an internal wall.

## About SpeakCAD

SpeakCAD is the most intuitive CAD for 3D printing, made for people who own a 3D printer and need a part that fits something they have: tap a face and type a size to shape it with simple tools, or describe it to the AI, on your phone or computer, and download a print-ready STL, 3MF or G-code sliced for your printer.

SpeakCAD works inside ChatGPT and Claude as a plugin (an MCP server): ask the assistant for a part with its measurements and SpeakCAD's own CAD AI designs it, shows it in 3D in the chat and hands over a print-ready STL, 3MF or G-code sliced for your printer.

- Live demo, no account: https://speakcad.com/demo
- In ChatGPT, Claude and other MCP clients: https://speakcad.com/chatgpt-plugin, https://speakcad.com/claude-connector, https://speakcad.com/mcp-server
- Pricing: https://speakcad.com/pricing
- FAQ: https://speakcad.com/faq
- Site index for AI assistants: https://speakcad.com/llms.txt
