Connecting a photo interrupter/optoisolator to an Arduino

In an early version of the camControl device (before the dropController) I used an interrupter/optoisolator to detect the water drops. The plan was to detect the water drop, wait a little bit and then activate the shutter.

There are various different kinds of photo interrupter, different shapes and different sizes but all do the same job.
Photo interrupter

A photo interrupter has a LED at one side (normally IR) and a photo transistor at the other. When the LED in emitting light the photo transistor allows a current to flow. Remove the light and the current stops.

Photo interrupters can have 4 or 5 pins. Both types work in the same way.I purchased a range of different models and sizes. Some with 5 pins, some with 4 pins.

Connecting The Photo InterrupterPhoto interrupter

Remember to add a resistor to the LED side (not shown above). The value will be based on the voltage and the LED/interrupter used

The interrupter/optoisolator below is a Liteon LTH-301-32. This is a 5V, 20mA device. This is good for detecting water drops because it has a 15mm gap size.

To get started I created a small test circuit with just the interrupter. This allowed me to experiment and make sure things worked before I added it to the camera controller.Interrupter Test Circuit

Difficult to tell from the above photo but the red LED is on. Below, with the beam broken the LED goes out.Interrupter Test Circuit: Beam broken



Photoisolator Schematic

R1 10K resistor is a pull down resistor. This gives a clean reading when there is no current. R2 depends on the photoisolator you use. Since I used the LTH-301-32 which is 5V I didn’t really need a resistor but I added a small one just to be safe.


The Arduino Sketch

/* Analog Read Interrupter
* -----------------------

int ruptPin = 2; // select the input pin for the interrupter
int val = 0; // variable to store the value coming from the sensor

void setup()
    Serial.begin(9600); // set up Serial library at 9600 bps

void loop()
    val = analogRead(ruptPin); // read the value from the sensor
    Serial.println(val); // print the sensor value to the serial monitor

 Serial Monitor

Connecting an interrupter to an Arduino: Serial monitor









The top numbers show the value before the beam is broken. The bottom numbers are when the beam is broken.

To make use of this all you need to do is set a trigger value. Anything below 600 would do. In the Camera Controller I have a potentiometer which allows me to fine tune the trigger value while making water drops.


Water drop detectorWater drop detector - optoisolator Module

 Above is the water drop detector I built. It connects to the camera control device by a standard 3.5 headphone/audio lead.



19 thoughts on “Connecting a photo interrupter/optoisolator to an Arduino

  1. Hi HH,

    yes you can. The above code is very simple. It just reads the value from the sensor and displays it. Once you have the value you will need to determine if the beam is broken and what to do if it is.
    I use the sensor to detect water drops. When a drop passes through the sensor the value goes low. When the low value is detected, the Arduino waits a short while and then triggers a camera or a flash.

  2. plz, tell me how to photointeruppter programing sketch with arduino that can displayed into LCD 16×2, for reding the speed of motor dc(RPM).

    • The photo interrupter gives an analogue value which is unlikely to work with digitalRead, usually the low value is not low enough or the high value is not high enough and digitalRead requires a faily clean digital HIGH/LOW signal.

      In the example above I received a value of 615 when the beam was unbroken, this is not high enough to be read as HIGH when using digitalRead.
      Look in to Shmitt Triggers; these take an analogue signal and converts it in to a digital signal and would allow you to use digitalRead.

  3. Pingback: Stop at the end of a track | DL-UAT

  4. Hello everyone. I tried to do this tutorial, but my readings are not as the one showed here. The max value I got was 136 and the min 0, but there is no big gap between them, I got values like 1 2 3 6 8 15 17 20 22 26 28 30 … 136. What I’m doing wrong?
    Here’s the sensor I’m using:
    Arduino UNO.

  5. lovely…. hi everyone, please can someone help me out wit a configuration/circuit to incorporate the opto interrupter to a pi-controller for dc motor speed control with computer interface just simple components

  6. sir ask lng sam lng po ba ito sa photo interuptor TCST1230 try kc nmn tong circuit mu but it din’t work ehh bka pag iba model d nagana?? ask lng po alam nyu po ba

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 7 = sixteen

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>