# An ESP32 sensor box with heat-set inserts, a vented lid and a sliding PCB tray

> One prompt gave me a three-part ESP32 enclosure: a base with M3 heat-set inserts, a PCB tray that slides in on grooves and a vented lid. I typed a sensor window into the code by hand, and the agent picked up my edit on the next turn and built on it. The board size, standoffs and USB opening are all sliders, so you can fit it to your own board.

Page: https://printpal.io/guides/design-stories/esp32-sensor-box-heat-set-inserts-cad-agent
Updated: 2026-11-29
Designed with: AI CAD agent
Reading time: 13 min

## Key takeaways

- **One prompt made all three parts.** In 4 minutes Opus wrote 207 lines of OpenSCAD: a base with four Ø4.0 × 6 mm heat-set insert holes, a tray that slides on 1.2 mm grooves and a lid with countersunk screws. It came with 13 named features and 13 sliders.
- **You can edit the code yourself, and the agent keeps your edit.** I typed a sensor window into the code editor in Advanced mode. It rendered straight away, with its own feature chip and four new sliders, and no AI call.
- **The next turn built on my code.** Asked for a twin window and wall-mount keyholes, Opus kept my parameter names, my feature name and my comment, and wrapped my one cut in a loop instead of rewriting it.
- **Check what the agent assumed.** My prompt never said how high the USB port sits, so the agent used 6 mm and listed it under "Defaults adopted". With an ESP32 DevKit on headers, the port sits at 11.7 mm. One slider fixes it.
- **83 minutes and 46 g of PLA for all three parts,** with no supports. Add four M3 inserts, four M3 × 6 countersunk screws and four M2 self-tapping screws.

## The plan: a box you open without unscrewing the board

Most ESP32 projects in our [Arduino and ESP32 build guides](https://printpal.io/guides/arduino-esp32-projects-to-3d-print) end the same way: a perfboard with a dev board and a sensor on it, and nowhere to put it. A snap-fit case, like the Raspberry Pi 5 case in our [Kimi vs Opus vs Astra test](https://printpal.io/guides/design-stories/kimi-vs-opus-vs-astra-cad-agent), is great for a board you set up once. A sensor box needs something different: a lid you can take off over and over, and a board you can lift out to reflash or rewire.

So this box has three parts. The **lid** screws into brass heat-set inserts, which survive being opened many times, unlike screws driven straight into plastic. The board sits on a **tray** that slides out of the back on grooves, so you never unscrew the board to get at it. The **base** has vents low on both sides and in the lid, so air can flow past the sensor.

All of it happened in one chat on **Claude Opus 5.5** with **Advanced mode** on. Advanced mode adds a code editor next to the chat, and this story is mostly about what happens when you use it.

**One chat, two AI turns**

| Step | Who did it | AI turns | Time |
|---|---|---|---|
| Base, tray and lid from one prompt | Opus | 1 | 4 min 7 s |
| A sensor window typed into the code | Me, in the code editor | 0 | instant render |
| A twin window and wall-mount keyholes | Opus, building on my edit | 1 | 2 min 41 s |

*Times are from the chat's own timers. Each Opus turn costs 3x a Kimi message.*

> **Not printed yet** Nothing in this story has been printed yet. The board in the renders is a stand-in I modelled from typical sizes (a 50 × 70 mm perfboard, an ESP32 DevKit on 8.5 mm headers and a BME280 breakout). The fit checks measure the files against it; they are not test prints.

## Turn 1: the whole box from one prompt

I wrote the prompt the way I would brief a person: what each part does, every size I know, which hardware goes where, and which numbers should be sliders. The insert hole is the standard size for M3 heat-set inserts (Ø4.0 mm, 5.7 mm long), with 0.3 mm extra depth so the insert can sit below the surface.

**Prompt (AI CAD agent, Claude Opus 5.5 · 3x):**

> Design a three-part enclosure for an ESP32 sensor board: a base box, a sliding PCB tray and a vented lid. My board is a 50 x 70 mm perfboard (1.6 mm thick) with an ESP32 dev board and a BME280 soldered on; the tallest part is 15 mm above the board. It has four 2 mm mounting holes, 3 mm in from each edge. The tray is a 2 mm plate with four 5 mm tall standoffs (M2 self-tapping pilot holes) under those holes. It slides into the base along grooves in the two long walls through an open back end, and has its own back wall that closes that end when it is pushed home. The board's USB-C port faces the front wall, so cut a 12 x 7 mm opening there, centred on the board by default. The lid screws down with four M3 screws into heat-set inserts: put 4.0 mm wide, 6 mm deep insert holes in 8 mm bosses in the base corners, keeping the bosses clear of the tray's path, with countersunk M3 clearance holes in the lid. Add vent slots in the lid over the board and a row of low vent slots in both long walls so air flows past the sensor. 2 mm walls and 1 mm clearance around the board. Make the board size, the mounting hole positions, the standoff height and the USB opening's position and size sliders, so other people can reuse this box for their own board. Lay the three parts out side by side, each oriented to print without supports.

*The last two sentences matter most: "make these sliders" and "print without supports".*

![The CAD agent chat with the long enclosure prompt and Opus thinking at 47 seconds about giving the outer shape boss ears at the corners so the walls stay thin](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/thinking.webp)
*Thinking at 47 s: putting the bosses in ears at the corners, and noting that the lid has to follow the same outline.*

### Attempt 1: Three parts, 13 features, laid out to print

Tool: AI CAD agent, Claude Opus 5.5 · 3x

Opus put the four insert bosses in "ears" on the outside corners, so the inside of the box is a clean 52 × 72 mm channel for the tray. Each groove takes 1.2 mm out of the 2 mm wall, so it added a 45° rib on the outside to bring the wall back to 2 mm there. The lid got a 3 mm skirt at the back that stops the tray sliding out while the lid is on.

![The CAD agent with the base, tray and lid laid out side by side in the viewer, an 8 of 8 done checklist and thirteen feature chips from groove_ribs to vented_lid](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/app-v1.webp)
*The result: 13 feature chips, one for each `// @feature:` marker in the code.*

- **Time:** 4 min 7 s
- **Code:** 207 lines, 13 features
- **Sliders:** 13, plus 3 colours
- **Layout:** 199.8 × 78.2 × 28.6 mm
- **Base:** 68 × 76 × 28.6 mm

What worked:

- Every number from the prompt is in the code: 4.0 × 6 mm insert holes, Ø1.6 M2 pilots, 2 mm walls and 1 mm clearance.
- The design brief listed what it would check before writing any code: 4 insert holes, 4 countersunk holes, 4 pilot holes, 18 side vents and 12 lid vents.
- It warned that the layout is just under 200 mm wide and fits a 220 mm bed.

What did not:

- The USB opening sits 6 mm above the board, which is a guess. My prompt never said how high the port is. It is listed under "Defaults adopted", and I come back to it below.
- The low side vents sit mostly below the board. That is fine for airflow, but none of them are next to the sensor, which is what my hand edit fixes next.

## Turn 2: I edited the code myself

The BME280 sits near the left wall, and an ESP32 runs warm. A temperature sensor in a closed box mostly measures the chip next to it, so I wanted an opening right beside the sensor. It is a small cut, so instead of asking for it I opened the **Code** pane and typed it in.

**esp32_box.scad · my hand edit**

```cpp
// added to the parameters at the top: each one becomes a slider
// Sensor window: position along the left wall (+Y = back)
sensor_window_y = 20;
// Sensor window: centre height above the board top
sensor_window_z = 6;
// Sensor window length along the wall
sensor_window_length = 14;
// Sensor window height
sensor_window_height = 6;

// added inside base_box(), after the side vents
        // @feature: sensor_window
        // open slot beside the BME280 so it reads room air, not the ESP32
        translate([-(cavity_width / 2 + wall_thickness / 2), sensor_window_y,
                   board_top_z + sensor_window_z])
            cube([wall_thickness + 2 * groove_depth + 2, sensor_window_length, sensor_window_height],
                 center = true);
```

When I stopped typing, the model re-rendered, going from 7,530 to 7,550 triangles. Because I followed the file's conventions, the page treated my code like the agent's. The `// @feature: sensor_window` line became a **chip**, and the four commented numbers became **sliders** in the Params tab. No AI was involved.

![The CAD agent with the code pane open on the hand-typed sensor_window block, and a new sensor_window chip among the feature chips above the chat](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/hand-code.webp)
*My block in the Code pane, and a `sensor_window` chip in the feature list.*

> **Hand edits are part of the file** The agent reads the **current** code at the start of every turn, not the last code it wrote. So anything you type is part of what it builds on. Write a `// @feature:` marker and a comment line above each new number, and your edit gets a chip and sliders like everything else.

## Turn 3: the agent builds on my edit

Next I wanted the same slot on the other side, so air flows straight across the sensor instead of into a dead end. I also wanted a way to hang the box on a wall. I clicked my new chip, which put `@feature[sensor_window]` in the message, and pointed at my own code:

**Prompt (AI CAD agent, Claude Opus 5.5 · 3x):**

> @feature[sensor_window] I added this slot by hand, next to the BME280. Give it a twin in the right-hand long wall so air can flow straight across the sensor, driven by the same sensor_window sliders. Then add two wall-mount ears to the base with keyhole slots for 4 mm screws, placed where they do not block the tray, the vents or the USB opening, so the box can hang on a wall.

*"Driven by the same sensor_window sliders" asks it to reuse my parameters, not invent its own.*

### Attempt 2: My window, twinned, plus keyholed ears

Tool: AI CAD agent, Claude Opus 5.5 · 3x

Opus did not rewrite my window. It wrapped my `translate` in a two-step loop that mirrors it to the right wall, kept my comment and added one of its own below it. For the ears, it put a 3 mm plate on each long wall at floor level with a keyhole slot. That is below the vents (which start at Z 7.3 mm), in the middle of each wall and outside the tray's path. The layout became two columns, which brought it down from 200 mm wide to 158 mm.

![The CAD agent viewer showing the base with keyhole ears on both sides, and a 10 of 10 done checklist ending with Edited model +48 −5, 8,682 tris, 158.4 × 156.9 × 28.6 mm, 2 m 41 s](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/app-ears.webp)
*New chips: `wall_mount_ears` and `wall_mount_keyholes`. `sensor_window` is the same chip as before.*

- **Time:** 2 min 41 s
- **Change:** +48 / −5 lines
- **Layout:** 158.4 × 156.9 × 28.6 mm
- **New sliders:** mount_screw_diameter, mount_ear_y
- **My 4 sliders:** kept as written

What worked:

- My four parameter names, their values, the feature name and my comment are all unchanged.
- The only change it made to my lines was the comment "the left wall", which became "both long walls". That is correct now.
- The keyhole slot runs from the head hole toward the back, because the box hangs USB-down. The brief explained why.

What did not:

- The ears stick out about 9 mm on each side, so the box is 85 mm wide on the wall instead of 68 mm.
- The box hangs with its floor flat against the wall, so the screw heads have to be set about 4 mm proud before you hang it. The brief says so, but it is easy to miss.

**esp32_box.scad · after turn 3**

```cpp
// Sensor windows: position along both long walls (+Y = back)
sensor_window_y = 20;

        // @feature: sensor_window
        // open slot beside the BME280 so it reads room air, not the ESP32
        // (twinned in both long walls for straight cross-flow over the sensor)
        for (s = [-1, 1])
            translate([s * (cavity_width / 2 + wall_thickness / 2), sensor_window_y,
                       board_top_z + sensor_window_z])
                cube([wall_thickness + 2 * groove_depth + 2, sensor_window_length, sensor_window_height],
                     center = true);
        // @feature: wall_mount_keyholes
        for (sx = [-1, 1])
            translate([sx * mount_keyhole_x, mount_ear_y, -1])
                linear_extrude(height = mount_ear_thickness + 2) keyhole_2d();
```

![My hand edit: Drag to compare the base with one hand-typed sensor window and the base after the agent added the twin window and the wall-mount ears](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/base-hand.webp)
![After turn 3: Drag to compare the base with one hand-typed sensor window and the base after the agent added the twin window and the wall-mount ears](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/base-ears.webp)
*Same camera, same scale. Before: my one window, on the far wall. After: its twin on the near wall, and the keyhole ears at floor level.*

**esp32_box.scad · keyhole_2d()**

```cpp
// keyhole: head hole at -Y, slot runs toward +Y (box hangs USB-down)
module keyhole_2d() {
    translate([0, -mount_slot_travel / 2]) circle(d = mount_head_diameter);
    hull() {
        translate([0, -mount_slot_travel / 2]) circle(d = mount_slot_width);
        translate([0,  mount_slot_travel / 2]) circle(d = mount_slot_width);
    }
}
```

## Inside the box

Renders show the outside. To check the inside, I cut the assembled box in two places, with the stand-in board on the tray and the lid on.

![Two cross-sections of the assembled box. The top one cuts through the corner bosses and shows the insert holes, the countersunk lid holes and the tray plate in its grooves. The bottom one cuts through the sensor windows, the purple BME280 and the ESP32 dev board on its headers.](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/sections.webp)
*Top: through the corner bosses. Bottom: through the sensor windows, with the BME280 beside the left one.*

- **Insert bosses.** The Ø8 boss leaves 2 mm of plastic around the Ø4.0 hole, which is the usual minimum for an M3 heat-set insert. The holes are 6 mm deep, so the 5.7 mm insert sits just below the surface.
- **Grooves.** The tray plate runs in 1.2 mm grooves with 0.3 mm clearance on each side. With the lid off it slides all 80 mm out without touching anything. I checked this in 5 mm steps.
- **The lid locks the tray.** With the lid on, the tray's back wall hits the lid's 3 mm skirt after about 0.2 mm of travel, so the tray cannot slide out.
- **Nothing collides.** Assembled, the base, tray, lid and stand-in board overlap by 0 mm³.
- **Air path.** The 18 side vents sit low, mostly beside and below the board, and 12 slots in the lid sit above it. Warm air from the ESP32 can rise out of the lid while room air comes in at the sides and through the sensor windows. I have not measured this; it is just how the openings are placed.

## Fit it to your own board

This is what the sliders are for. In the **Params** tab, the board size, mounting hole insets, standoff height and the USB opening each have a slider and a typing box. The base, the grooves, the tray, the bosses, the vents and the lid are all calculated from them.

![The base and tray growing from a 50 by 70 mm perfboard to a 70 by 90 mm one as the board_width and board_length sliders move, then shrinking back](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/board-size-poster.webp)
Video: https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/board-size.mp4
*board_width and board_length, from a 50 × 70 to a 70 × 90 mm perfboard. The walls, bosses, vents and standoffs all follow.*

![The Params tab with sliders for perfboard width 50, length 70, thickness 1.6, tallest component 15, hole insets 3 and 3, standoff height 5 and the USB opening, next to the base and lid in the viewer](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/params.webp)
*Key dimensions first, then everything else. Moving a slider re-renders in under a second, with no AI call.*

**Now the USB port.** My prompt said "centred on the board" but gave no height, so the agent set the opening's centre 6 mm above the perfboard and listed it under "Defaults adopted". On my stand-in, the DevKit sits on 8.5 mm female headers. That puts the port's centre 11.7 mm above the perfboard, and the opening misses it completely.

![Default: 6 mm: Drag to compare the front of the closed box with the USB opening at the default height, showing only the perfboard behind it, and at 11.7 mm, showing the silver USB-C port](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/usb-default.webp)
![Set to 11.7 mm: Drag to compare the front of the closed box with the USB opening at the default height, showing only the perfboard behind it, and at 11.7 mm, showing the silver USB-C port](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/usb-fixed.webp)
*Same camera. At 6 mm you see the perfboard through the hole. At 11.7 mm the USB-C port sits in the middle of it.*

One slider fixes it. To make the fix permanent in the code, type it as a chat line. A message that is only `name = value` pairs is applied in the browser without calling the AI:

**Prompt (AI CAD agent):**

> usb_center_above_board = 11.7

*Typed as a normal chat message. Free, and it survives the next edit.*

The same goes for a port that is not centred. The `usb_offset_x` slider starts at 0, so a port left of centre needs a negative number. Type `usb_offset_x = -6` (or whatever you measure) the same way.

**What to measure, and where it goes**

| Your board | Sliders to change |
|---|---|
| A different perfboard or PCB | `board_width`, `board_length`, `board_thickness` |
| Mounting holes not 3 mm from the edge | `hole_inset_x`, `hole_inset_y` |
| Something taller (an OLED on headers, a big capacitor) | `component_height` |
| DevKit on headers, or soldered flat | `usb_center_above_board`: port centre above the board |
| Micro-USB, or a plug with a big boot | `usb_width`, `usb_height` |
| Sensor somewhere else along the wall | `sensor_window_y`, `sensor_window_z` |
| Thicker wall screws | `mount_screw_diameter` |

## Printing and assembly

![The base, tray and lid building up layer by layer in print orientation: the base upright, the tray plate-down with its back wall rising, and the lid upside down](https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/print-build-poster.webp)
Video: https://printpal.io/static/assets/img/guides/design-stories/esp32-sensor-box/print-build.mp4
*The three parts in the orientation the agent chose. None needs support.*

The base prints upright, the tray prints plate-down and the lid prints upside down, so its countersinks face the bed. The longest bridge is the 14 mm top of each sensor window, and the USB opening is a 12 mm bridge. A bridge that short prints cleanly in PLA.

**Bambu Studio estimates, X1 Carbon, 0.20 mm layers, PLA, 2 walls, 15% infill**

| Part | Printed size | Time | Filament |
|---|---|---|---|
| Base (with wall ears) | 85.4 × 76 × 28.6 mm | 42 min | 25.2 g |
| Tray | 53.8 × 73.7 × 25.4 mm | 22 min | 12.0 g |
| Lid | 68 × 78.2 × 5 mm | 19 min | 8.7 g |
| All three |  | 1 h 23 min | 45.9 g |

*Each part sliced on its own. They also fit on one plate together.*

- **2** AI turns
- **1** hand edit the agent kept
- **0** supports
- **0 mm³** overlap, assembled

- **Hardware:** 4 × M3 heat-set inserts (Ø4.0 hole, up to 5.7 mm long), 4 × M3 × 6 countersunk screws, 4 × M2 × 6 self-tapping screws for the board, and 2 × 4 mm screws for the wall. An M3 × 8 is too long: it would reach the bottom of the 6 mm hole.
- **Set the inserts first.** Use a soldering iron with an insert tip at about 220 °C for PLA. Press each insert straight down until it sits just below the top of the boss, then let it cool before you fit the lid.
- **Then the board.** Screw the perfboard to the tray's standoffs, slide the tray in from the back with the USB end first, and screw the lid on.
- **Use PETG** if the box will be outdoors or in the sun. PLA starts to soften at around 55 °C, which a box in direct sun can reach.

1. **Measure your board before the first prompt.** Width, length, hole positions, the tallest part, and **how high the USB port sits** above the board. Anything you leave out, the agent will guess.
2. **Ask for sliders and named features.** They are what make the box reusable, and the chips are what make later edits precise.
3. **Make small changes yourself.** A slot, a hole or a different number is often quicker to type than to explain. Copy the file's style, with a `// @feature:` marker and a comment line above each number, and it gets a chip and sliders.
4. **Then ask for the next step by pointing at your edit.** Click its chip and say what to do with it. The agent starts from the code as it is now, your lines included.
5. **Read "Defaults adopted".** That is where the agent lists what it guessed. Check each one against your board.

**Design an enclosure for your board** Open the CAD agent, switch on Advanced mode, and describe your board with its sizes and the hardware you have. Then edit, drag and print. [Open the CAD agent](https://printpal.io/cad-agent)

## Sources and method

Made on November 29, 2026, in one CAD agent chat on a PrintPal Pro account, with Claude Opus 5.5, Advanced mode and Auto-improve on. The prompts are shown above, unedited. The hand edit was typed into the page's code editor and is shown in full. Times are from the chat's timers. The OpenSCAD for each version and the chat text were saved straight from the page, and the claims about what each turn kept or changed come from line diffs between those files. Renders, animations and cross-sections are those files rendered with OpenSCAD's manifold backend, with a stand-in board (a 50 × 70 mm perfboard, an ESP32 DevKit on 8.5 mm headers and a BME280 breakout) modelled from typical sizes. Overlaps and the tray's slide path were measured as mesh intersections. Print times and filament are Bambu Studio estimates for an X1 Carbon at 0.20 mm in PLA. Nothing has been printed. PrintPal makes the CAD agent.

- [PrintPal AI CAD agent](https://printpal.io/cad-agent)
- [ESP32-DevKitC user guide](https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32/esp32-devkitc/user_guide.html)
- [Bosch BME280 product page](https://www.bosch-sensortec.com/products/environmental-sensors/humidity-sensors-bme280/)
- [OpenSCAD documentation](https://openscad.org/documentation.html)
- [Bambu Studio](https://bambulab.com/en/download/studio)

## More guides

- [Clearing my desk with one parametric under-desk mount: power strip, headphones, controller](https://printpal.io/guides/design-stories/parametric-under-desk-mount-cad-agent): One prompt gave me a screw-on power strip holder. Then I dragged five sliders to turn it into a controller tray and used two @feature edits to make a headphone hook and a clamp-on version for desks you cannot drill. That was four AI turns and two free edits in one CAD agent chat, and each holder fits what I actually own.
- [Arduino and ESP32 projects to 3D print, with parts lists, wiring and code](https://printpal.io/guides/arduino-esp32-projects-to-3d-print): Sixteen builds with a printed enclosure: ten click-together ESP32 gadgets you can flash from the browser, and six wired projects with a full parts list, a wiring diagram, working code and print settings.
- [Kimi K3.1 Pro vs Claude Opus 5.5 vs GPT-6 Astra: three real parts, nine CAD agent runs](https://printpal.io/guides/design-stories/kimi-vs-opus-vs-astra-cad-agent): I gave the three models in the CAD agent picker the same three prompts: a Gridfinity bin, a snap-fit Raspberry Pi 5 case and a screw-top jar. Then I checked every file against the real thing: the Gridfinity baseplate, the Pi 5 drawing and a simulated lid being screwed on.
- All design stories: https://printpal.io/guides/design-stories

- All guides: https://printpal.io/guides
- PrintPal for LLMs: https://printpal.io/llms.txt
