Kodenshi SG-2BC opto switch

Hello!

I've been trying to interface the Kodenshi SG-2BC optical sensor with an arduino but can't seem to get it working.

This is the datasheet: http://pdf1.alldatasheet.com/datasheet-pdf/view/78838/KODENSHI/SG2BC.html http://www.farnell.com/datasheets/83024.pdf

Based on a few other sources (linked at the bottom of this post) I have built the following circuit: http://imgur.com/IhYYlhR

However, I'm too new to electronics to understand why I'm using the resistor values they suggest. I'm not even sure if they are correct for this sensor.

When use an analog input to read from the sensor I have a very weird output: 1023, 434, 1023, 480, 1023, 540, ..., 1023, 1023, 1023, 1023, 950, 1023, 910, 1023, 840, ...

As you can see it alternates between 1023 and a second number. Every second number seems to grow towards the maximum and then gradually shrink back to 0, then grow back to 1023, etc etc. Covering the sensor changes nothing to this pattern.

Anyone that can help me to connect it properly?

Sources: http://letsmakerobots.com/content/optosensor http://www.navitron.org.uk/forum/index.php?topic=8881.0 http://forum.arduino.cc/index.php/topic,10786.0.html http://forum.arduino.cc/index.php?topic=86894.0 http://www.utopiamechanicus.com/288/arduino-photo-interruptor-slotted-optical-switch/

“Photointerrupter”…looks like a digital sensor to me.