Jason Brownstein published a detailed tutorial on how to embed electronic components into 3d printed objects as they are being printed. He published the accompanying g-code also so you can adapt it for your projects. he used an example of a Lego block with small led light.
Detailed guide can be found at:
http://www.lunchboxelectronics.com/how-to-embed-electronics-into-a-3d-print