Finally got the photo interrupter working!

A photo of my working photo interrupter. Here is the trick to getting a new photo interrupter working (tipped off by this thread). There are 2 sides to the gate; the transistor and the emitter.

  • look at the datasheet and see which side is the emitter and which is the collector.
  • start by setting up the phototransistor as an analog input analogread() will output values from 0-1023
IR emitter:
  • look at the datasheet to see how much voltage and current the LED can handle. Mine was 50mA
  • Hook up the LED to that output. In my case digital I/O gives 5V and 40mA.
  • watch the serial monitor I started off getting values that ranged from 0 to 3, then after fiddling with resistors (taking away the resistor to the emitter and adding a 10K to the transistor).
  • Got to the point where I read 10-20 when the gate was blocked and 1010-1020 when the gate is open. (my Photo interrupter took a 10K resistor, my Photo Reflective Sensor will take a 100k or 1m resistor all I have is 10K resistors and 5 of them in series brought the reading up to 400)
  • Now change the code from analogRead() to digitalRead() (and switch the input wire) see if you get 111100001110001111 when you move something between the gate.

Here is the test code that I used:

int val;

void setup()


pinMode(13, OUTPUT);
pinMode(2, INPUT);

Serial.begin(9600); // sets the serial port to 9600

digitalWrite(13, HIGH);

void loop()


val = digitalRead(2); // read digital input pin 2
//val = analogRead(0); // read analog input pin 0

Serial.print(val); // prints the value read
Serial.print(" "); // prints a space between the numbers

delay(100); // wait 10ms for next reading



Comments Off on Finally got the photo interrupter working!

Filed under import, Uncategorized

Comments are closed.