Using Optical Switches

breadboard -300Applying micro controllers to the real world often involves sensing motion, position or the proximity of objects.  A very simple sensor is the optical switch consisting of an IR LED emitter and an IR-sensitive phototransistor.  These can be arranged to detect directly transmitted light (photo interrupter) or the reflection of light (proximity detector) and they can be packaged into a self-contained sensor or used as separate emitter / receivers.  The photo below shows an interrupter type and a proximity detector type that may be purchased for less than a buck a piece.

photo switches copy
The interrupter is often used to sense rotary motion.  With one sensor, the rotational speed of a shaft can be calculated; using two sensors, the speed and direction of rotation can be determined.  The interrupter may also be used to determine position of items moving in a linear path.  The illustration below shows an interrupter used as a limit switch to detect when the slide has reached the end of its travel.
 
speed and direction
 
limit switch
The proximity type can detect the presence of an object, such as a finger.  Imagine one of these behind an IR-transparent opaque panel.  Move your finger near a spot to turn a device on, and near another spot to change modes, all with no controls visible.
 
With a little ingenuity, these sensors can be applied to many different applications!
 
The sensors are cheap so they must be difficult to use, right?  Actually, they couldn't be much easier to use!  One resistor to adjust the LED current and a second to load the transistor are all that's needed.  Fairchild Semiconductor's AN-3005 - Design Fundamentals for Phototransistor Circuits shows two methods of connecting these sensors.  I've used the more common collector resistor arrangement in the circuit shown below with aVishay TCRT5000 reflective proximity detector purchased from eBay for a couple bucks for ten.  These are offered by many vendors on eBay for around the same price.
 
schematicThe schematic shows the circuit I used.  A 100 ohm resistor provides about 26 mA to the LED.  A 5k resistor is the collector load, which the above link recommends as a good value to be sure the phototransistor operates in the switching mode.  The values here should work well with most sensors of either the transmissive or reflective type - they all seem very similar in the requirement s for the transistor and LED.
 
 
The circuit is shown on a breadboard above.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
To test this simple circuit, I used the logic tool function of the PICkit 2.  High states are indicated by a 1, low states by a 0.  Pin 6 of the logic analyzer was connected to the optical  switch circuit.  With noting near the sensor, the collector resistor pulls the output high and a high state / 1 is shown.  With my finger within about half-an-inch (12 mm), IR reflected by my finger turns the phototransistor on, pulling the output to near ground, resulting in a low state / 0 being shown on the logic tool.
 
PICkit logic tool
 
This switches have IR-filters, so they don't respond to daylight much (direct sunlight may swamp them out).  They are sensitive to IR light from any source.  A convenient sources is an IR remote control.  Switching to the PICkit logic analyzer mode and pointing a handy IR remote at the sensor resulted in the following trace showing the remote control pulses.
 
remoteoutput
 
 
I'm going to use one of these proximity sensors to detect if the sliding door is open for my fan controller.  The edge of the sliding glass door will be in front of the sensor if the door is not open far enough to operate the fan.  The reflected IR from the door will activate the phototransistor, resulting in a low output.
 

slider proximity

 

Not bad for 25 cents worth of parts.  Optical sensors with a transistor output will all operate similarly to this.  Some sensors are logic level output, in which case the circuit is even easier, eliminated the collector resistor.


Posted: 2 years 3 months ago by Jon Chandler #11927
Jon Chandler's Avatar
Sorry Gary,

Another one of my eBay items in action. This one however was especially cheap.

I should mention there is a short article on using opto-couplers here. These devices are exactly the same, except for a bit of real world between the emitter and receiver.
Posted: 2 years 3 months ago by Jon Chandler #11928
Jon Chandler's Avatar
I just had an idea. The fan has an IR remote control but the receiver is pointing out the open door rather than into the room. When not using the sensor to check if the door is open, I could possibly use the proximity switch's IR LED as a blaster to control the fan!
Posted: 2 years 3 months ago by W4GNS #11929
W4GNS's Avatar
Sorry Gary,

Another one of my eBay items in action. This one however was especially cheap.

I should mention there is a short article on using opto-couplers here. These devices are exactly the same, except for a bit of real world between the emitter and receiver.



Hummm..... Been reading C textbooks all day, guess I deserve a quick trip over to EPay to look at the goodies.
Posted: 2 years 3 months ago by Baldor #11930
Baldor's Avatar
I should make some experiments with the IR led and phototransistor from the scrollweel of an old mouse... These are easy to desolder.
Posted: 2 years 3 months ago by W4GNS #11942
W4GNS's Avatar
I should make some experiments with the IR led and phototransistor from the scrollweel of an old mouse... These are easy to desolder.



Good idea, I think I have a couple USB mouses around somewhere, that I could hack up.
Posted: 2 years 3 months ago by Baldor #11943
Baldor's Avatar
And if you can find some old mouses, non optical, you have a pair of optical encoders realy cheap.
Posted: 2 years 3 months ago by Baldor #12025
Baldor's Avatar
Salvaged the optical sensor from an old logitec mouse. Actualy, is 2 phototransistors, the center pin is the common collector, and the two lateral pins are the emiters. Obvious once you think about it, for a scrollwheel you not only need to count pulses, but also know the direccition of movement. Seems the range for the detections is short. I should do some tests.
Posted: 2 years 3 months ago by be80be #12026
be80be's Avatar
opto-couplers The best place to get them is old printers. My friends give me about 4 printers a year which have lots of goodies in them steppers and Opto-couplers are the easy parts to get.

I've never seen 2 phototransistors with out 2 IR diodes. But the ones I have reused where not every long range as what is in the printer
Posted: 2 years 3 months ago by Baldor #12027
Baldor's Avatar
http://www.rapidonline.com/Electronic-Components/Kingbright-L-610MP4BT-BD-Phototransistor-72-8968

And the range is very short. I'm measuring 0.4uA with the IR led 4cm apart, and declines very fast with distance. (Obvious, the inverse of the square of dist)
Posted: 2 years 3 months ago by be80be #12029
be80be's Avatar
That makes sense because two tell which way wheel is moving Is found by which one switches first.

Forum Activity

Member Access