Ever wanted to build a positioning encoder? Here’s one and you do not even need any sensors. The circuit uses an LED as a light emitter and another LED as a light receiver. This is possible due to the ability of the LED to generate a very tiny current when a light is shining into it, almost like a small solar panel. A red LED is used because tests indicated that they gave the best results. It is possible though to use a different color than red and the best combination might be found by trial and error. Please note that not all red LEDs give the same result, so you might have to get hold of a few different types and then find the best one. When a receiver LED is not illuminated by its associated sender device, it will prevent a tiny current of about 50 nA from flowing out of opamp pin 3 to ground.
Once the LED is illuminated, this current is allowed to flow. In fact, even more, current flows because the ‘solar cell’ quality of the LED causes pin 3 to go negative with respect to ground. Because of the series-connected LEDs D18-D20, the supply voltage, Vcc, will have to be a few volts higher than the relay coil voltage. If that is the case, the values of R1-R4 are subject to experimenting because the operation of the light barriers depends on the supply voltage and the efficiency of the LEDs used. The LEDs (transmit and receive) are mounted onto the sides of a tube and can ‘see’ each other through two 3-mm holes. The light barrier is then “broken” when a rod is inserted into the tube. This approach can of cause be multiplied as many times as required. Here, four barriers are shown, which allow up to five-rod positions to be detected.
Each position, including ‘rod not inserted’ is translated into a discrete resistance value which is created by connecting resistors in parallel, and may be measured on the output connector for further processing by an ADC or what have you. The values of the resistors on the relay contacts may be adapted to suit your needs. The LM324 opamp is a quad type, making the layout a bit easier. On the output of each opamp, a series resistor and a zener diode ensure proper voltage levels for the buffer transistor, which drives the relay. Across each relay coil sits a back EMF protection diode (always a good idea to add). As a matter of course, the transistor driving the relay has to be able to handle the required coil current.