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.

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 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.

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

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()
{
Serial.println(val); // print the sensor value to the serial monitor
delay(50);
}```

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 detector

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

33 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. hi, i want this photo interrupter for my project so from which website i can get this? plz guide me

3. You can also get a lot of photo interrupters from thrown away printers. They come complete with resistors and LEDs.

4. 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).

5. Friends,
I want to connect above arduino with java program. Please help to code Serial Monitor value into java out put.

• 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.

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

7. 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.

• It seems the pin may be floating. Do you have a pull down resistor?

8. 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

9. 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

10. 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.

11. 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

12. 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?

13. Hi there, i know this post is old but i wanted to know what code did you use for the water drop and what code did u use to turn on the led

• The above was an experiment as part of a very early drop controller. I found the interrupter too unreliable for water drops and went a different route.

The LEDs are inline with the interrupter. Not the best example (doubles the current draw) but kept the circuit simple.

If you are interested in water drop photography have a look at http://www.dropcontroller.com.

14. The “water drop detector” does not identify the connections on the photo interrupter you used. As well, the colour bands on the resistors are not quite distinct enough to let the user to clearly i.d. the values of the resisters. (200 ohms / 2Kohms?)

My interrupter is a KH1A57HR — SHARP 95.

A year ago I saw a video demonstrating automated water-drop photographer, and mention was made aboard using Arduino. I realise that your item is originally quite old (as these sort of these are “old”, anyway. Nonetheless — quite interesting, and in line with a project I am building. My uses a 12v solenoid valve controlled by an Optocontroller and a relay. My problem, of course, is finding the exact moment at which to trigger the shutter.

15. I’m wondering about the schematic. I see from the code you’ve used analogRead because the change in the voltage is relatively small when the emitter voltage is connected via a resistor to ground. That may be necessary for a “dual interrupter” in the case where the two transistors share a collector, but for a single interrupter, if you get the right values according to the datasheet, you can connect the collector to 5V via a resistor and the voltage at the collector will swing between light and dark sufficiently to use digitalRead.