Analog Pin Not Reading Sensor Output

I have set up my Arduino as shown below, with the only difference being that I'm using an ITR9608-F Opto Interrupter instead of the one shown.

And here's the schematic.

I was able to get the sensor to work by simply replacing an LED in the output (-) pin of the sensor, but can't get Arduino to read it and I don't know why. Here's the code I used.

int val;
int led=13;

void setup() {
pinMode (led,OUTPUT);

void loop() {
val = (analogRead(A1));
if (val < 500)


EDIT: I don't know why but the images I put on here are not showing up for me, I tried 3 different image hosts.

Don't use image hosts.

Please post the images in line, following this image guide.

Thanks, I have fixed the image issue using the guide.

The optocoupler is wired incorrectly, according to your diagram. Below is one way to do it (Vout at the collector will be LOW when the LED is on). Another way is to have the load resistor R2 in the emitter lead, to ground, and output at the emitter will be HIGH when the LED is on. |500x254

Thanks a lot for your help, I've tried to figure it out through YouTube videos. I picked up Arduino like a month ago and have enjoyed learning all this. Is S1 a step-down module? And I think I do understand what you mean about having the R2 resistor onto ground, I think that is similar to what I was trying to do.

S1 is a push-button switch, just to illustrate an input.

It doesn't matter which way you connect R2 (from 5V to collector-pin4 or from emitter-pin3 to ground), but the logic is switched.

Thank you! I will give this a try shortly.

I have a quick question. On your diagram, you have #3 set to ground, but on my sensor datasheet #4 is set to ground and #3 is connected to positive. Is this just a difference in sensor model or am I just misunderstanding how it works?

So this is how I was able to get my sensor to work on a breadboard. I thought that by replacing the LED with a wire and running it to the Arduino A1 pin that it would take that as a signal but I guess this is where my lack of electrical knowledge stunts me.

The pins are different for different optocouplers. Pay attention to the individual data sheet and the schematic diagram of the internals.

For your ITR9608-F optocoupler, here is the data sheet.

The schematic diagram in that sheet looks like this. The emitter of the phototransistor is pin 4 and goes to ground, while the collector is pin 3 and goes to Vcc, so those two pins are the opposite of the PC817 pinout I posted. A load resistor is required, in line with either the collector or the emitter.


Also make sure you understand the pin numbering. Pin numbers are usually not displayed on the device package.


Ok, so I feel a bit better now, I thought it might be different and I'm glad I was able to recognize that. I have been using the datasheet, that's what lead me to ask about the difference. Thanks!

+1 karma for using the data sheet!