How To Set Up A Photo Interrupter (or Slotted Optical) Switch On The Arduino

As usual, I expected easy – but got anything but.

For my Big Project, I needed an photointerrupter – what they are is a small device that shines a light from one side to the other, where there’s a detector.

The idea is that if anything breaks that light beam, you take note of it, and use the information as you wish. For example, if you put a disk on a motor shaft with a small hole cut in it, the beam will be broken except for that one spot – so count the ‘breaks’, and you get an RPM for the motor.

rpi574 opto isolator

The catch however was getting it to work. The one I bought at eBay was a simple 4-pin variety, called the RPI-574. One side was an infrared led, and the other was a phototransistor (although with only two pins I think it should be called a photodiode). When the LED was on, the phototransistor would conduct; when it was off (or something blocked the light falling on the transistor) it wouldn’t conduct.

With that part ready, my first goal was to scour the Internet for examples of these types of projects. My idea was to design it first, get it working, and THEN import to the Arduino. To make a long evening short, I couldn’t get a single example I found to work right, even to do something simple like light up an LED.

So I gave up and attacked it another way. Looking at the specifications for the device, the diode side was easy. I saw a reference to using a 150 ohm resistor, so I used an available one (180ohm) and connected it to power. I then checked the current through it – the specs said the maximum for it was 50mA, and I read 20mA, so I figured I was OK.

In reality, I should have started with 5v and worked backwards; realizing that R = V / I, I could have said R = 5v / 0.05A, or 100ohm. Anything over that would keep my current under 50mA, no matter what the resistance of the diode might be.

In any case, I had proof the diode was working, so now on to the photo-transistor. My next step was to connect power to it, and then connect the other lead to a resistor (again, 100ohm) and to ground:

At this point, I hooked in my multimeter, and checked the current. Then, I put a piece of paper into the photointerrupter to cut the beam, and watched as the milliamps went to zero. I had a working detector!

SOME ITEMS YOU MIGHT ENJOY
BANNER SM31EQDP MINI BEAM PHOTOELECTRIC SENSOR FULLY FUNCTIONAL WARRANTY
$20.00
End Date: Wednesday Jan-10-2018 17:01:23 PST
Buy It Now for only: $20.00
Buy It Now | Add to watch list
Omron Standard Slot Photoelectric Sensor, Sensing Method: Through Beam, Power
$50.49
End Date: Wednesday Jan-10-2018 13:35:36 PST
Buy It Now for only: $50.49
Buy It Now | Add to watch list
Omron L-Slot Photoelectric Sensor, Sensing Method: Through Beam, Power
$38.67
End Date: Wednesday Jan-10-2018 13:35:29 PST
Buy It Now for only: $38.67
Buy It Now | Add to watch list


6 thoughts on “How To Set Up A Photo Interrupter (or Slotted Optical) Switch On The Arduino

  1. Brilliant, thanks for taking the time to write this up. I was looking for exactly this having salvaged a couple of slotted optical sensors from an old printer.

  2. hi,
    First, thanks for tutorial, do i have an issue about plugging photo interrupter on arduino board 3.3v.
    Most of photo interrupter are 5v. How can i plug it to 3.3v arduino board please.
    Thanks

  3. Did you ever get this working? I’m trying to do the same thing with a raspberry pi but I’ve got the additional problem of trying to step it down to 3.3V for the signal. Any luck!? Thanks!

  4. Re this circuit, I’ve done the following using just an Arduino and a H21A6 from RapidOnline:

    The spec for the R21A says that the LED requires 1.2v and draws 50mA. This means if we are using the Arduino to supply bower (5v) we need an 82ohm resistor, I used 100.

    Pin 1 now goes to VCC (5volts) from the Arduino and pin 2 goes via the 100 Ohm resistor to ground.

    Pin 3, bottom right if Pin 1 is top left, goes to the Arduino and Pin 4 goes to ground.

    That’s it, all you need to do now is set the input pin on the Arduino as INPUT_PULLUP, and then you can read the status with DigitalRead which will return a HIGH or LOW state.

    Enjoy!!

  5. Just add threshold detection transitor or Opamp circuit after the optical sensor circuit, and you will have your digital signal that you can then send to a digital input.

  6. Hi sir, I am using OPL560 photo transistor, it has 3 leads 1. ground 2. output 3. Vcc. now resistor has to connect to which terminal either 2 or 1.

Leave a Reply

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