How to use a transistor with arduino

Cant tell what yer doing here, the picture shows a regular transistor but you linked an opto coupler. Depending on what youre tryin to do a common way to use 4N25 is

When "some voltage" is present current flows in LED of optocoupler and turns on its transistor. That pulls D2 LOW against the pullup resistor in Arduino. When "some voltage" goes away or reverses polarity then the optcoupler turns OFF and D2 goes high.

int optoPin = 2;            // 4N25 opto coupler connected to digital pin 2

void setup()
{
  pinMode(optoPin, INPUT);      // sets the digital pin as input
  digitalWrite(optoPin, HIGH);  // turns on the internal pull up
}

void loop()
{
  if (digitalRead(optoPin) == LOW) {
  // do stuff when "voltage is present"
} 
}