Problem with Arduino "digital glue" !!!!

Hello all,

I’m having trouble connecting a step motor controller (with STEP/DIR outputs) to a motor driver (with CW/CCW inputs) using an Arduino-bootloaded ATMega328P, and the root of the problem seems to be that I am also attempting to use an optoisolator to keep this particular motor/driver separate from three others one the same controller. (They use STEP/DIR input drivers so they’re all set…)

Here’s the test code I’m using:

void setup() {
pinMode(10, INPUT);     //direction input
pinMode(0, OUTPUT);    //indicate CW direction
pinmode(13, OUTPUT);  //indicate CCW direction
}

void loop() {

if (digitalRead(10)) {     //controller output = CW
   digitalWrite(0, LOW);
   digitalWite(13, HIGH);
   }
else {                         //controller output = CCW
   digitalWrite(0, HIGH);
   digitalWite(13, LOW);
}
}
}

Here is my circuit:

http://i46.tinypic.com/zu2ogy.jpg

I have tried several permutations of the NPN phototransistor section, like pulling the Ardiuno pin down instead of up, reversing the connections to pins 4 and 5, and probably others, but I’m obviously not understanding something important because I am consistently unable to change the state of digital input 10.

Any hints would be greatly appreciated!

Thanks,

Patrick

The circuit as you have drawn it looks good to me, but you might try reducing the 1K resistor on the input to 100 ohms or so. The current transfer ratio for the H11AA1 is supposed to be 20% minimum. I would estimate the LED current to be about 1 mA (as you have two LED voltage drops in addition to the 1K resistor), so you are not far above the minimum required to switch the output transistor. If that doesn’t work, test the H11AA1 in isolation from the rest of the circuit, to see if it is working properly.

I tried that and I am now getting the expected result. Thanks very much for the help.

Patrick