]> www.fi.muni.cz Git - things.git/blob - hc-sr04.scad
dc5b789f8abf691d168e326e5f3a311c03725761
[things.git] / hc-sr04.scad
1 eps = 0.01;
2 infty = 100;
3
4 wall = 1.5;
5
6 cyl_r = 8 + 0.5;
7 cyl_x = 27 / 2;
8 cyl_h = 8; // above pcb, max 13.8;
9
10 pcb_x = 45 + 1.0;
11 pcb_y = 20 + 1.0;
12 xtal_h = 5;
13 pcb_supp = 3; // side support thickness
14 pcb_h = 8; // 1.2 + space for connector etc
15 pcb_thick = 2.5;
16
17 cyl_base = pcb_x/2 + wall - cyl_x;
18
19 conn_x = 10 + 0.5;
20 conn_y = 15;
21
22 cable_w = 7;
23 cable_h = 3.5;
24
25 mount_h = 3;
26 screw_sp = 5;
27
28 clip_r = 1;
29 clip_h = 8;
30
31 module sensor() {
32         hull() {
33                 // space above pcb
34                 translate([-pcb_x/2, -pcb_y/2, -eps])
35                         cube([pcb_x, pcb_y, pcb_h-pcb_thick+eps]);
36                 // connector
37                 translate([-conn_x/2, pcb_y/2-eps, -eps])
38                         cube([conn_x, conn_y+eps, pcb_h-pcb_thick+eps]);
39         }
40         // cable protrusion
41         translate([-cable_w/2, pcb_y/2+conn_y-eps, -eps])
42                 cube([cable_w, 2*wall + eps, cable_h]);
43
44         // cylinders
45         for (x = [-1, 1]) translate([cyl_x*x, 0, pcb_h - eps])
46                 cylinder(r = cyl_r, h = cyl_h + 2+wall + eps);
47         // pcb
48         translate([-pcb_x/2, -pcb_y/2, pcb_h-pcb_thick-eps])
49                 cube([pcb_x, pcb_y, pcb_thick+eps]);
50         // space below the pcb (xtal, etc)
51         translate([-pcb_x/2+pcb_supp, -pcb_y/2, pcb_h-pcb_thick - eps])
52                 cube([pcb_x - 2*pcb_supp, pcb_y, xtal_h+pcb_thick+eps]);
53 };
54 module case_body() {
55         hull() {
56                 // pcb
57                 translate([-pcb_x/2-wall, -pcb_y/2-wall, 0])
58                         cube([pcb_x+2*wall, pcb_y+2*wall, pcb_h+wall]);
59
60                 // cylinders
61                 for (x = [-1, 1]) translate([cyl_x*x, 0, pcb_h + cyl_h])
62                         cylinder(r = cyl_base, h = wall);
63
64                 translate([0, 8, pcb_h + cyl_h])
65                         cylinder(r = cyl_base, h = wall);
66
67                 // connector
68                 translate([-conn_x/2-wall, pcb_y/2-wall, 0])
69                         cube([conn_x+2*wall, conn_y+2*wall, pcb_h-pcb_thick+wall]);
70         }
71         for (x = [0, 180]) rotate([0, 0, x]) hull() {
72                 // eps-wide cube
73                 translate([pcb_x/2-eps, -4/2-wall, pcb_h + cyl_h + wall -eps])
74                         cube([eps, 4+2*wall, eps]);
75                 // bottom plate
76                 translate([pcb_x/2+wall, -screw_sp/2-wall, 0])
77                         cube([screw_sp+wall, screw_sp+2*wall, wall]);
78         }
79 }
80
81 rotate([180, 0, 0]) // rotate it for easier print
82 difference() {
83         case_body();
84         difference() {
85                 sensor();
86                 // pcb clip
87                 translate([-clip_h/2, -pcb_y/2, pcb_h-pcb_thick-clip_r/2])
88                 rotate([0, 90, 0])
89                 cylinder(r=clip_r, h = clip_h, $fn = 4);
90         }
91         // mount holes
92         for (x = [0, 180]) rotate([0, 0, x]) {
93                 translate([pcb_x/2+wall, -screw_sp/2, wall])
94                         cube([screw_sp +wall+eps, screw_sp, pcb_h + cyl_h + eps]);
95                 translate([pcb_x/2+1+wall, -3/2, -eps])
96                         cube([3, 3, wall + 2*eps]);
97         }
98         // text
99         translate([0, 3.5, pcb_h + cyl_h + eps])
100                 rotate([0, 0, 90])
101                 linear_extrude(height=wall)
102                 text("CVT FI", font="DejaVu Sans:style=Bold", size=5,
103                         halign="center", valign="center");
104
105 }
106