When making something motorized with Legos, I'm frequently running out of motors. I found it is rather easy to adapt the cheap geared "TT motor" found on Asian websites for around a dollar to accommodate a Lego shaft and mount it on a Lego plate. I'll describe the process in steps. Note that it will not become a Lego quality motor in the sense that it will be noisier :-)
Finding these motors (bottom figure) is easy; they are often named "TT motor" or "geared robot motor" or something similar. They have nice shafts for specific wheels and are used with 3 to 6 Volts.
First step: opening the gear unit.
Step 1: Opening the Gear Box
The gear box opens easily via two screws and an elastic band which keeps the motor in place. When it is open, use some force to remove the gears from the axis which has the shafts. You can use a screwdriver, but be careful not to break parts. It will look like the picture.
There is one gear (labelled "A") still in the yellow box; this one is driven by the motor. This gear drives the double gear "B" on the right in the picture - this gear runs loosely on the iron shaft. Gear B connects to gear C, which is lying in front of the yellow enclosure. This one finally drives the last gear "D", which has a shaft attached to it with two flat sides. This one was fixed to the iron axle as well as the other shaft.
Next step: drilling gears B and D.
Step 2: Adjust the Gears to Fit a Lego Axis
Gear B must run smoothly over the lego axis, drill it with a 4.8 mm drill. The smaller gear of gear B has notches, try to keep these as small as possible. Make it rotate smoothly over your lego axle.
You have to hold the gear while drilling: make sure you don't damage the teeth. Do not let the gear slip if you hold it in a vice: the teeth will be damaged. Hold the gear with pliers instead.
You'll have to enlarge the hole in one side of the yellow enclosure as well with the 4.8mm drill (the half which is in the top of the picture).
Gear D must be fixed tightly on the lego axle, so drill it with a smaller drill, around 4.5mm will do.
Now, put gear D on the lego axle of your choice (I chose a length of 8). Mount the gears in the correct order:
First A. Then lie B in the yellow enclosure. Then put gear C on the iron axle; with gear B in between. Then insert the lego axle with gear D in it, and the result should look like the picture. Slip gear D such that the axle comes out as you would like. You can modify this a little bit later, when the motor is finished.
Step 3: Mount It on a Lego Plate
The motor itself is now finished!
The last step is to mount the motor on a lego plate such that you can actually use it in a lego project.
I chose to mount it on a 2x8 thin plate such as in the picture. For mounting it at the correct height, such that the axles match regular holes of lego-technic blocks, the studs are a little too high. Remove them with a sanding machine.
I made a small set up to glue the motor at the correct height, see the third picture. The 2x8 is below the motor.
I used bison two-component epoxy to glue the motor to the two-by-eight. Do not use too much glue and make sure it does not flow too much: if it goes through the holes it will be difficult to remove it from the substrate below, and it will be impossible to mount the motor on another lego plate.
And with that, it is finished! Now connect it normally to your microcontroller, or 3-6V DC power supply, or batteries or whatever.
Order one motor more than you need - they are around $1 and something can go wrong.
You can mount it on a larger plate for more easy inserting it into a lego contraption.
I found that mine works sufficient, but there is a little too much room for the axle, you could increase quality by adding bushings or small rings.
Have fun with these cheap lego motors!