Skip to content

Instantly share code, notes, and snippets.

@markwatson
Last active March 20, 2026 20:18
Show Gist options
  • Select an option

  • Save markwatson/96276d2ccdc69a3305a8f06182efdd35 to your computer and use it in GitHub Desktop.

Select an option

Save markwatson/96276d2ccdc69a3305a8f06182efdd35 to your computer and use it in GitHub Desktop.
Little box for temp sensor
// Uniform Enclosure for DFR1075, 18650 Battery, and Temp Sensor
// Fasteners: M3 Socket Head Cap Screws + M3 Heat-Set Inserts
wall = 2.5;
tolerance = 0.2;
// --- Exterior Dimensions ---
outer_l = 96.0;
outer_w = 56.0;
outer_h = 28.0;
// --- Internal Dimensions ---
int_l = outer_l - wall*2; // 91mm
int_w = outer_w - wall*2; // 51mm
int_h = outer_h - wall; // 25.5mm
// --- Zones ---
batt_zone_w = 22.0;
pcb_zone_w = int_w - batt_zone_w;
pcb_zone_l = 64.0;
// --- Hardware ---
post_w = 8.0;
insert_r = 2.0; // 4.0mm hole for standard M3 short heat-set insert
insert_d = 6.0; // Depth of the insert hole
screw_pass_r = 1.6; // 3.2mm clearance for M3 shaft
screw_head_r = 3.0; // 6.0mm clearance for M3 socket head
screw_head_h = 3.0; // Depth of counterbore
module box_base() {
difference() {
// Main solid body
cube([outer_l, outer_w, outer_h]);
// Hollow out the main internal cavity
translate([wall, wall, wall])
cube([int_l, int_w, int_h + 1]);
// USB-C Port Cutout (Left Wall)
// Oversized to 12x8mm to accommodate various cable boots
translate([-1, wall + batt_zone_w + (pcb_zone_w/2) - 6, wall])
cube([wall + 2, 12, 8]);
// Sensor Ventilation (Right Wall)
for(y = [wall + batt_zone_w + 4 : 3 : outer_w - wall - 4]) {
translate([outer_l - wall - 1, y, wall + 2])
cube([wall + 2, 1.2, int_h - 4]);
}
// Sensor Ventilation (Top Wall)
for(x = [wall + pcb_zone_l + 6 : 3 : outer_l - wall - 4]) {
translate([x, outer_w - wall - 1, wall + 2])
cube([1.2, wall + 2, int_h - 4]);
}
}
// Internal Thermal Partitions (Fully encloses sensor)
translate([wall + pcb_zone_l, wall + batt_zone_w, wall]) {
difference() {
union() {
// Wall separating PCB and Sensor
cube([2, pcb_zone_w, int_h]);
// Wall separating Battery and Sensor
cube([int_l - pcb_zone_l, 2, int_h]);
}
// Wire pass-through port at the bottom of the PCB wall
translate([-1, 4, 0])
cube([4, 5, 4]);
}
}
// Battery Cradle (keeps the round cell centered)
translate([wall + int_l/2, wall + batt_zone_w/2, wall])
battery_cradle();
// M3 Corner Posts
translate([wall, wall, wall]) corner_post();
translate([outer_l - wall - post_w, wall, wall]) corner_post();
translate([wall, outer_w - wall - post_w, wall]) corner_post();
translate([outer_l - wall - post_w, outer_w - wall - post_w, wall]) corner_post();
}
module corner_post() {
difference() {
cube([post_w, post_w, int_h]);
// Heat-set insert pilot hole
translate([post_w/2, post_w/2, int_h - insert_d])
cylinder(r=insert_r, h=insert_d + 1, $fn=32);
}
}
module battery_cradle() {
cradle_l = 72;
cradle_w = 18;
difference() {
translate([-cradle_l/2, -cradle_w/2, 0])
cube([cradle_l, cradle_w, 3]);
translate([0, 0, 9 + 1]) rotate([0, 90, 0])
cylinder(h=cradle_l+2, r=9.5, center=true, $fn=64);
}
}
module box_lid() {
lid_thickness = wall;
difference() {
union() {
// Main lid body
cube([outer_l, outer_w, lid_thickness]);
// Registration Lip (keeps lid seated)
translate([wall + tolerance, wall + tolerance, lid_thickness])
difference() {
cube([int_l - tolerance*2, int_w - tolerance*2, 1.5]);
// Clear the corners for the posts
translate([-1, -1, -1]) cube([post_w + 1, post_w + 1, 4]);
translate([int_l - post_w - tolerance*2, -1, -1]) cube([post_w + 1, post_w + 1, 4]);
translate([-1, int_w - post_w - tolerance*2, -1]) cube([post_w + 1, post_w + 1, 4]);
translate([int_l - post_w - tolerance*2, int_w - post_w - tolerance*2, -1]) cube([post_w + 1, post_w + 1, 4]);
// Clear the thermal partition walls
translate([pcb_zone_l - tolerance, batt_zone_w - tolerance, -1]) {
// PCB/Sensor wall clearance
cube([2 + tolerance*2, pcb_zone_w + tolerance*2, 4]);
// Battery/Sensor wall clearance
cube([int_l - pcb_zone_l + tolerance*2, 2 + tolerance*2, 4]);
}
}
}
// Counterbored M3 Screw Holes
post_centers = [
[wall + post_w/2, wall + post_w/2],
[outer_l - wall - post_w/2, wall + post_w/2],
[wall + post_w/2, outer_w - wall - post_w/2],
[outer_l - wall - post_w/2, outer_w - wall - post_w/2]
];
for (p = post_centers) {
translate([p[0], p[1], -1]) {
// Shaft clearance
cylinder(r=screw_pass_r, h=lid_thickness + 4, $fn=32);
// Head counterbore
translate([0, 0, lid_thickness - screw_head_h + 1])
cylinder(r=screw_head_r, h=screw_head_h + 1, $fn=32);
}
}
}
}
// --- Render Targets ---
box_base();
// Translate lid out of the way for visualization
translate([0, outer_w + wall*3, 0])
box_lid();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment