An optocoupler is basically a light and a light sensor used to communicate between two circuits. This is desirable in situations where you need complete isolation from a load and very fast communication. A simple transistor will give you that fast switching speed without the isolation. Relays give you the isolation you need, but don't have a switching speed anywhere near fast enough to handle the pulses used to drive a stepper motor. Optocouplers are the solution, since they provide total isolation and have a very fast switching speed. My homemade ones will handle about 300 hertz, but fancy ones used in industry can be switched at kilohertz. In my version, the light is an LED, the sensor is a photoresistor, and a MOSFET transistor switches the actual current through the load.
Step 1: Parts Required
1 Photoresistor- These are cheap little components that conduct electricity in the presence of light.
1 NPN transistor- I used a 3904 from Mouser. Almost any brand will do.
1 N- channel MOSFET transistor- I used one labeled IRFZ44N that I got in bulk on eBay.
2 resistors, with values 10,000 Ohms and 100 Ohms, respectively. If your microcontroller supplies more than 5 volts, you should substitute a 470 Ohm resistor for the 100 ohm one.
1 ordinary diode
Electrical tape or a small enclosure that light will not penetrate