Optek / TT Electronics OPB720B-06Z Connection Help

I am trying to use a Optek / TT Electronics OPB720B-06Z as an object detector on a conveyor belt. I am using it to count the number of items passing the sensor. By my understanding it will send a voltage over 3.5V when the light beam is reflected back with a reflector and a voltage of .8V or less when an object blocks the light.

I've tried connecting the output to a digital input on an Arduino Uno, but it never returns a LOW signal when blocked. I've also tried connecting to an analog input to read the input. It always returns a high value of over 800.

I'm supplying it with a 5V input. I've tried with a pull-up resistor and without one. I'm wondering if anyone has used one of these photo sensors and has any advice how to make it work. I've tried the break beams from Adafruit, but they are unreliable. I need a very accurate count and therefore high reliability object detection at about 4 to 8" distance.

The sensor output is open collector NPN, did you set the input pin to " pinMode(inputPin,INPUT_PULLUP);"?
The pin should go LOW when the sensor is blocked. Post your code and a wiring diagram.

I did use the digitalWrite(SENSORPIN, HIGH), I even tried adding a physical pull up resistor. Below is the full test script:

/*
Test Optical Reflector Sensor!
*/
#include “SerialDebug.h”

#define SENSORPIN 4
#define LEDPIN 13
// variables will change:
int sensorState = 0,; // variable for reading the pushbutton status
int analogPin = A0;

void setup() {
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN, INPUT_PULLUP);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup

// initialize the analog pin as an input:
//pinMode(analogPin, INPUT);
//digitalWrite(analogPin, HIGH); // turn on the pullup
Serial.begin(9600);
}

void loop() {

//try reading the analog input
//readAnalog();

readDigital();

debugHandle();
delay(1000);
}

void readAnalog() {
//read the analog input
int val = analogRead(analogPin); // read the input pin
//convert to volts
float proximityV = (float)val * 5.0 / 1023.0;

// check if the sensor beam is broken
if (proximityV <= 0.8) {
digitalWrite(LEDPIN, HIGH);
}
else {
digitalWrite(LEDPIN, LOW);
}
printD(F(","));
printD(val);
printD(F(","));
printlnD(proxV);
}

void readDigital() {
// read the state of the pushbutton value:
sensorState = digitalRead(SENSORPIN);

// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState == LOW) {
digitalWrite(LEDPIN, HIGH);
sensorState = LOW;
}
else {
digitalWrite(LEDPIN, LOW);
}

printD(F("sensorState = "));
printlnD(state);
}

I am not sure what you are doing with digitalWrite(SENSORPIN, HIGH); // turn on the pullup
.

set up the SENSORPIN as input
read it using digital.Read() .