First - please note that this only applies to the “Stud” style connector, and not the old train 3-pin connector or the new RJ style connectors used on the NXT. It is expected that the RJ connectors may be orderable, and simply crimped.
Before you proceed with anything like this, bear in mind that you must still think safely. If you have not already done so, read Robot Building Safety now.
There are two basic ways to do this, the first is to cut into an original cable, and the second is to modify a brick to make your own connector.
The most simple way to hook something into a Lego electronic device (like the Lego RCX), is to slice a lego cable, and then splice your device into the cable. Since you are cutting a connector in half, you get two adaptors this way. The cables themselves are multicore, so you will probably need to tin them, and maybe even crimp them into a connector.
For finding and selecting tools. please read Robot Tools
First, please wear your goggles, and make sure you are doing this on a well lit bench. If you intend to solder you must have ventilation, and a soldering stand.
Select a Lego cable, probably one of the shorter ones will do (since the long ones are less common and pretty useful intact). Cut it roughly in half.
This gives a nice finish, and may be both cheaper and more flexible. However using real Lego parts gives good compatibility. This does require soldering, and can be a little tricky as you are soldering onto very fine exposed metal areas and run the risk of melting plastic, which smells very bad.
As 2x2 Basic bricks are abundant, this is the cheapest method. This can be achieved with stiff wire or 4mm cheese head screws, but they are more fiddly than this method. This method involves salvaging tin from a biscuit tin, and actually modifying the studs, so the potential for compatibility problems is increased.
MindSensors also have an elegant method using a PCB designed to fit over the contact studs. If you can design it, one of the many PCB services will be able to produce this for you. With a few surface mount components - tiny and flexible Lego compatible circuits can be made.
There are probably plenty more methods, and variations on these. Tweet Us your comments or links to this page if you have another method, or enhancements to a method here.
Be aware, that as these Lego connectors are not polarised - you may(or may not) wish to add diodes to maintain the correct polarity. You can use a single diode to allow one way only usage, or use a Diode Bridge to allow any orientation.
Time to build your own robot! Using a Raspberry Pi with parts and some time, you can use my book to learn how to make and program a robot with automatic behaviours.