Public Domain Modulus Gear OpenSCAD code
This code defines a gear based on its modulus rather than pitch in mm, Modulus is the ration of tooth count:diameter, effectively the pitch of the gear is modulus * pi, ie, a gear of mod=1 has a tooth pitch of 3.1514mm.
The advantage of using modulus rather than pitch to define a gear is that it is very easy to prototype - for example, a gear of mod = 1 will have a diameter that matches the tooth count, with mod = 2, radius = tooth count.
This code is based on the poblic domain Parametric Involute Spur Gear code by Leemon Baird found at http://www.thingiverse.com/thing:5505
The file here is designed as both a library file (just use include at the start of your own OpenSCAD file, after removing the modgear call), and as a customizer so you can create and download your own custom gears directly from Thingiverse!
Note: If using the options of a square or hexagonal center hole, be aware that the size is diagonal (corner to corner) not the side length. This, for a square bore 4 mm an a side, the hole size should be set to 5.7 mm (This requires applying the Pythagorean theorem).