Help for count an optocuplor on arduino

There is a slight error in your code with missing ')' or spurious 'delay('. I don't think you need the delay for testing or it should be on separate line

void loop()
{
    sensorValue = analogRead(sensorPin);    
    Serial.println(sensorValue);                  
}

You say it does not work using digital pin but did the pin stay high or low, ambient light can effect some of these types of sensor. Try it in a darkened room or cover with you hand to mask most of the light and try it. Do you need a pullup/pulldown/inlinee resistor on the out pin? Did you get any datasheet of connection instructions with the device?