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

 

Schematic

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. Calculate the size using Ohm’s law the same as you would when using a regular LED.
Ohm’s law states that R = V / I. To use this to work out the resistor size we use the formula in the form of R = (V suplly – V forward voltage drop) / I.
Most LEDs have a forward voltage of around 2v and use about 20mA (or 0.02A) of current so when using 5V supply and a 3V photoisolator we have: R = (5-2) / 0.02A. Which equals 150 ohms. 150 ohms is the minimum and larger resistors can also be used.

Since I used the LTH-301-32 which is 5V I didn’t need a large resistor and used a 100 ohm resistor I had on hand.

 

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
    delay(50);
}

 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.

 

 

27 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: http://www.cromatek.com.br/pdf/opto/C860TP.pdf
    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

  7. HI my friend,
    I have followed your code on my Arduino Yno,
    this is really easy to build and use it for different project,
    Thank u very much

    • It can be difficult to get accurate readings for water drops from an interrupter. When I first started using them the trigger was very hit and miss. I had better success when I made the infrared light beam narrower by adding small pieces of thin black tube/straw.

      To get a slightly wider sensor, I would normally cut the interrupter in half and use a small piece of perf board to mount the two pieces.
      For times when I needed a wider sensor I used separate LEDs and photo transistors + small pieces of drinking straw.

  8. I have Optical slotted Switches Types OPB990t51
    Five ends of wire
    E) led = black and red)
    S) Sensor = Green – Blue – White )
    How to connect to Arduino

  9. I have a photo interrupter from a HP J6480 printer. It has three wires, Red, Black and Green. Does anyone know how to wire to an arduino uno?

Leave a Reply

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


five + 2 =

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>