An opto coupler is a device that combines a led, a transparent isolation barrier , and a photo-transistor in one package. You drive the led with a resistor in series using almost any dc voltage you want, compensating for the voltage with the resistance. Higher the input voltage , higher the resistor value. You get the forward current spec from the datasheet and use Ohms Law to calculate the correct resistor value. You can even drive it with ac , creating a zero-crossing detector. The output , being a transistor , replaces the transistors you are currently using with the added benefit of electrical isolation note this spec on the datasheet :
Isolation test voltage VISO 5000 VRMS
No, that’s not a misprint. It says 5000V
So you wire the output stage just like you wired the transistors you have working now. Nothing different. It is an open collector output so it is sinking the current, which, presumably is what you are doing. All you have to do is read the datasheet, find the forward current;
Forward current IF 50 mA
apply Ohm’s Law:
5V/0.050A = 100 ohms.
Done. Put a 100 ohm resistor in series with the ANODE pin (A)(pin-1), connect the CATHODE (C)(pin-2) to GND , connect the other end of the 100 ohm resistor to you digital output pin and you’re in business.
What about common ground of the arduino and the driver? is this obsolete when using opto-couplers?
Think about it. You’re using an optocoupler because you want isolation so the second you plug the opto into your circuit and wire it properly , your circuit has TWO SIDES .
1-arduino side , with arduino GND going to PIN-2 (CATHODE) of the opto.
2. Stepper motor side, which we sometimes like to call “the OUTSIDE WORLD”) with the opto TRANSISTOR EMITTER (E)(pin-4) CONNECTED TO THE STEPPER MOTOR GND. Once you have done that, get an ohm meter and put it on resistance mode and put one lead on the arduino GND and the OTHER lead on the STEPPER motor GND. What do you expect to see ?