The GPIO's canot drive a relay directly because they cannot deliver enough current for a normal relay, also a relay forms a large induction, and switching off currents through such an induction can induce high voltages over the coil which may damage the GPIO port.Also the GPIO cannot source more than 3.3 volt.A ULN2004 can drive up to seven relays, and it can switch 50 Volt signals, the GPIO pins can directly drive it.It costs only a few dimes at Farnell, (and about an euro in a normal electronics shop).

I used an Arduino relay board. They are cheap and usually even equipped with optocoupler and status led. Works like a charm, just hook it up to the GPIO headers and 5V from pin2.I got this one on eBay: link.

I have a little Z-guage model railway I control via a Velleman K8055 USB interface board, using 5V sealed reed relays I got from my local Maplins (http://www.maplin.co.uk/sealed-reed-relays-2605) to trigger the turnouts. Clearly, I could use this set-up with my raspi (someone has already reported success in porting the Linux driver, see http://forum.velleman.eu/viewtopic.php?f=12&t=7838), but it seems silly using an interface board three times the size of the raspi when I should be able to do it directly from the GPIO (plus a small breadboard, in both cases). Unfortunately while the relays are low drain (they have 500 Ohm impedance) they need at least 3.8V to trigger. Can someone suggest a simple circuit with commonly-available components I could use to drive these relays, please?

Even better, to allow me to control a turnout with one GPIO line, could someone help me with a circuit that would briefly energise one relay on the rising edge of the GPIO line, and do the same for a different relay on a falling pulse? This would also reduce the danger of burning out the turnout coils by activating them too long, or activating both coils at once! The 'normal' way these turnouts are activated is by pressing a a switch that temporarily connects the 10VAC output from the transformer unit to the appropriate coil of the turnout.

The question regarding relays comes up fairly frequently, the easiest thing to do is use a darlington driver such as the ULN2004 or ULN2803 that you can power from a 5V or 12v line. Connect the GPIO pins to the input and the output to your relay, there will be enough power to directly activate your relay, no extra components required as it even has a clamp diode built-in.