Arduino Case
A two-part case for the Arduino Uno (R3 or R4), Mega 2560 or Nano. The board drops onto standoffs in a tray, held by pins through its mounting holes or by self-tapping screws, with the hole pattern and the USB and DC jack cutouts taken from a table per board. The lid has ventilation slots and an inner lip that presses into the tray; set open_top to make it a frame so jumper wires and a shield can go in from above, and raise the free height to 18 mm for a shield. The Uno case is 75 x 59 x 24 mm; the print layout with the lid beside the tray is 75 x 127 x 22 mm. Both parts print open side up with no supports. Wall thickness, free height and lip clearance are parameters, and a closed view shows the lid on the case.
# Arduino Case - two-part case for the Uno, Mega 2560 or Nano with the connectors cut out
#
# The board drops onto standoffs inside a tray (pins through the mounting holes,
# or holes for self-tapping screws); the hole pattern, the USB and DC jack cutouts
# come from a table per board. The lid has ventilation slots and an inner lip that
# presses into the tray; `open_top` turns it into a frame so jumper wires and a
# shield can go in from above. Both parts print open side up with no supports.
#
# Board origin: x along the long edge from the USB end, y across from the DC jack
# edge (the Uno drawing with the USB connector on the left).
@param choices:["uno", "mega", "nano"] group:"Board" desc:"Arduino Uno R3 / R4, Mega 2560, or Nano"
$board = "uno"
@param choices:["pins", "screws"] group:"Board" desc:"Pins through the mounting holes, or holes for self-tapping screws (M3 Uno / Mega, M1.6 Nano)"
$fix = "pins"
@param 1.6..3 step:0.2 group:"Case" desc:"Wall thickness (mm)"
$wall = 2
@param 10..30 step:1 group:"Case" desc:"Free height above the board (mm; 18 fits a shield)"
$tall = 14
@param 0.1..0.3 step:0.05 group:"Case" desc:"Lid lip clearance per side (mm, smaller is tighter)"
$fit = 0.15
@param group:"Case" desc:"Lid is an open frame instead of a plate with vents"
$open_top = false
@param choices:["print", "closed"] group:"Output" desc:"Print layout, or the lid on the case"
$view = "print"
$uno = $board == "uno"
$mega = $board == "mega"
$nano = $board == "nano"
# --- board table ---------------------------------------------------------
$L = if $uno then 68.6 else if $mega then 101.6 else 43.2
$W = if $nano then 17.8 else 53.3
$n_holes = if $mega then 6 else 4
# Uno / Mega hole pattern (the Mega adds two at its far end); Nano: 1.3 mm in from each corner
def hx($i) = if $nano then (if $i % 2 == 0 then 1.3 else $L - 1.3)
else (if $i == 0 then 14.0 else if $i == 1 then 15.3 else if $i == 2 then 66.1 else if $i == 3 then 66.1 else if $i == 4 then 90.2 else 96.5)
def hy($i) = if $nano then (if $i < 2 then 1.3 else $W - 1.3)
else (if $i == 0 then 2.5 else if $i == 1 then 50.7 else if $i == 2 then 7.6 else if $i == 3 then 35.5 else if $i == 4 then 50.7 else 2.5)
$hole_d = if $nano then 1.6 else 3.2
$pcb_t = 1.6
$so_d = if $nano then 4 else 7
$clr = 1
$floor_t = 2
$so_h = 4 # standoff height: solder tails and the Nano's header pins clear the floor
$z_b = $floor_t + $so_h
$z_t = $z_b + $pcb_t
$h_in = $so_h + $pcb_t + $tall
$rim = $floor_t + $h_in
$in_w = $L + 2 * $clr
$in_d = $W + 2 * $clr
$out_w = $in_w + 2 * $wall
$out_d = $in_d + 2 * $wall
$cx = $L / 2
$cy = $W / 2
$corner = 3
def rr($w, $h, $r) = rect ($w - 2 * $r) ($h - 2 * $r) | offset $r
# --- connector cutouts through the x = 0 wall: centre y, width, height above the board --
$pad = 1.5
def usb_end($y, $w, $h) = box ($wall + 2 * $clr + 0.2) ($w + 2 * $pad) ($h + 2 * $pad) center:(true, true, false) | translate (-$clr - $wall / 2) $y ($z_t - $pad)
$cuts = if $nano then usb_end(8.9, 8, 4)
else union [usb_end(37.5, 12.5, 11), usb_end(7.5, 9.5, 11)] # USB-B and the DC jack
# --- tray ---------------------------------------------------------------
$outer = rr($out_w, $out_d, $corner) | extrude $rim | translate $cx $cy 0
$inner = rr($in_w, $in_d, $corner - $wall) | extrude $h_in | translate $cx $cy $floor_t
$shell = $outer - $inner
$pin_d = $hole_d - 0.3
$screw_d = if $nano then 1.3 else 2.6 # self-tapping M1.6 / M3
def at_holes($s) = union [$s | translate hx($i) hy($i) 0 for $i in range($n_holes)]
$so1 = cylinder ($so_d / 2) $so_h | floor | translate 0 0 $floor_t
$standoffs = at_holes($so1)
$pin1 = cylinder ($pin_d / 2) ($pcb_t + 0.5) | floor | faces >Z | chamfer 0.4 | translate 0 0 $z_b
$pins = at_holes($pin1)
$sh1 = cylinder ($screw_d / 2) ($so_h + 1) | floor | translate 0 0 ($floor_t - 0.4)
$screw_holes = at_holes($sh1)
$tray0 = $shell + $standoffs
$tray1 = if $fix == "pins" then ($tray0 + $pins) else ($tray0 - $screw_holes)
$tray = $tray1 - $cuts
assert $tray.solids == 1
assert $tray.bbox.x ~ $out_w
assert $tray.bbox.y ~ $out_d
assert $tray.bbox.z ~ $rim
print "case outer (mm)" [$out_w, $out_d, $rim + 2]
# --- lid, built lid-side down (print pose) ------------------------------------------
$lid_t = 2
$lip_h = 2
$lid_plate = rr($out_w, $out_d, $corner) | extrude $lid_t
$lip_out = rr($in_w - 2 * $fit, $in_d - 2 * $fit, $corner - $wall) | extrude $lip_h | translate 0 0 $lid_t
$lip_in = rr($in_w - 2 * $fit - 2 * $wall, $in_d - 2 * $fit - 2 * $wall, 1) | extrude ($lip_h + 1) | translate 0 0 $lid_t
$lip = $lip_out - $lip_in
$frame_w = 5
$opening = rr($out_w - 2 * $wall - 2 * $frame_w, $out_d - 2 * $wall - 2 * $frame_w, 2) | extrude ($lid_t + 2) | translate 0 0 -1
$n_vent = floor(($L - 16) / 4)
$vent_len = $W - 12
$vent = union [box 2 $vent_len ($lid_t + 2) center:(true, true, false) | translate (-$cx + 10 + $i * 4) 0 -1 for $i in range($n_vent)]
$lid0 = $lid_plate + $lip
$lid = if $open_top then ($lid0 - $opening) else ($lid0 - $vent)
assert $lid.solids == 1
assert $lid.bbox.z ~ ($lid_t + $lip_h)
# --- closed view --------------------------------------------------------------
$lid_on = $lid | rotate 180 0 0 | translate $cx $cy ($rim + $lid_t)
assert clear($tray, $lid_on)
$closed = union [$tray, $lid_on]
assert $closed.bbox.z ~ ($rim + $lid_t)
$print = union [$tray, $lid | translate $cx ($cy + $out_d + 8) 0]
assert $print.solids == 2
if $view == "closed" then $closed else $print