use ; // Define constants pi = 3.1415926; // Create single width gear tooth module tooth1_wide(mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash){ tooth(mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash); rotate(360/number_of_teeth) tooth(mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash); } // Create double width gear tooth module tooth0_wide( mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash){ hull(){ tooth(mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash); rotate(360/number_of_teeth) tooth(mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash); } } // Create gear in which tooth width encodes data module gear_coded_width ( code ="101010101010", mm_per_tooth = 4, //this is the "circular pitch", the circumference of the pitch circle divided by the number of teeth number_of_teeth = 24, //total number of teeth around the entire perimeter thickness = 2, //thickness of gear in mm hole_diameter = 4, //diameter of the hole in the center, in mm twist = 0, //teeth rotate this many degrees from bottom of gear to top. 360 makes the gear a screw with each thread going around once teeth_to_hide = 0, //number of teeth to delete to make this only a fraction of a circle pressure_angle = 28, //Controls how straight or bulged the tooth sides are. In degrees. clearance = 0.0, //gap between top of a tooth on one gear and bottom of valley on a meshing gear (in millimeters) backlash = 0.0 //gap between two meshing teeth, in the direction along the circumference of the pitch circle ) { p = mm_per_tooth * number_of_teeth / pi / 2; //radius of pitch circle c = p + mm_per_tooth / pi - clearance; //radius of outer circle b = p*cos(pressure_angle); //radius of base circle r = p-(c-p)-clearance; //radius of root circle t = mm_per_tooth/2-backlash/2; //tooth thickness at pitch circle k = -iang(b, p) - t/2/p/pi*180; //angle to where involute meets base circle on each side of tooth deg=360/number_of_teeth; difference(){ for (a=[0:len(code)-1]) { if (code[a] == "1") { rotate(2*deg*a) tooth1_wide(mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash); } else { rotate(2*deg*a) tooth0_wide(mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash); } } cylinder(h=2*thickness, r=hole_diameter/2, center=true, $fn=20); } } // Create a gear in which the presence or absence of a tooth encodes data module gear_coded_simple ( code ="101010101010101010101010", mm_per_tooth = 4, //this is the "circular pitch", the circumference of the pitch circle divided by the number of teeth number_of_teeth = 24, //total number of teeth around the entire perimeter thickness = 2, //thickness of gear in mm hole_diameter = 4, //diameter of the hole in the center, in mm twist = 0, //teeth rotate this many degrees from bottom of gear to top. 360 makes the gear a screw with each thread going around once teeth_to_hide = 0, //number of teeth to delete to make this only a fraction of a circle pressure_angle = 28, //Controls how straight or bulged the tooth sides are. In degrees. clearance = 0.0, //gap between top of a tooth on one gear and bottom of valley on a meshing gear (in millimeters) backlash = 0.0 //gap between two meshing teeth, in the direction along the circumference of the pitch circle ) { p = mm_per_tooth * number_of_teeth / pi / 2; //radius of pitch circle c = p + mm_per_tooth / pi - clearance; //radius of outer circle b = p*cos(pressure_angle); //radius of base circle r = p-(c-p)-clearance; //radius of root circle t = mm_per_tooth/2-backlash/2; //tooth thickness at pitch circle k = -iang(b, p) - t/2/p/pi*180; //angle to where involute meets base circle on each side of tooth deg=360/number_of_teeth; difference(){ union(){ for (a=[0:len(code)-1]) { if (code[a] == "1") { rotate(deg*a) tooth(mm_per_tooth, number_of_teeth, hole_diameter, thickness, twist, pressure_angle, clearance, backlash); } } cylinder(h=thickness, r=r, center=true, $fn=20); } cylinder(h=2*thickness, r=hole_diameter/2, center=true, $fn=20); } } thickness = 2; // To be printed with PLA or other nonconductive material // Simple coded gear with teeth omitted to encode 1s or 0s translate([0,40,0]) gear_coded_simple(); translate([0,40,thickness]) gear(4,6,2,2*thickness); // Gear in which width of teeth encode data // 1 : 2 separate teeth // 0 : 1 tooth equal to the width of 2 adjacent teeth and the space between them gear_coded_width(); translate([0,0,thickness]) gear(4,12,2,2*thickness);