Hey, so currently I am trying to achieve a working electromagnet that will be powered by an AVR microcontroller and will be turned on and of when metal is sensed. Currently I have LED reflecting and sensing the block which passing through the photo diode and tells the AVR when to turn on the electromagnet. My problem is with the electromagnet. I have made my own and current I need to put 9V through it with 0.5Amps. Now I know I cna use a mosfet as a switch to turn it on and off however I am not sure how to work out the values for the resistors in the circuit. I will be using a similar circuit to the one shown on this page http://www.embeddedrelated.com/showarticle/77.php. However I am unsure how to develope the resistor values I would need to ensure my magnet works correctly. Any help?