5 Replies Latest reply on Sep 14, 2018 4:07 AM by shabaz

    Optek OPB732WZ  and the Raspberry Pi ?

    amasters

      I am hoping that I can use the  OPB732WZOPB732WZ Reflective Photo Interrupter https://uk.farnell.com/optek-technology/opb732wz/opto-switch-reflective/dp/1678639 with a Raspberry Pi which has both 5v and 3.3v supplies on the GPIO.

      I have no great experience with electronics, but attaching optical sensors to a Raspberry Pi appears to be a simple matter according to articles I have read using similar devices.

       

      Any advice on how to connect this device to the Raspberry Pi would be gratefully received.

       

      Many thanks.

      • Reply
        • Re: Optek OPB732WZ  and the Raspberry Pi ?
          shabaz

          Hi Alan,

           

          You can use the circuit in the datasheet, there are four there, and the first one could be tried, although the third one can be better (and more energy efficient since it can be switched off). The third one needs a transistor, something like BC547 or any other generic NPN transistor is fine.

           

          But, the datasheet circuit is powering everything from one rail called VCC. Better in your case to split it, the receiver portion should be connected to the 3.3V supply (because the GPIO operate at that voltage), and the transmit portion can be connected to the 5V supply (because it will consume more current, and there is some limit on the 3.3V rail). The calculations for the resistors are in the datasheet, e.g. RD = (5V-1.8V)/20mA = 0.16k = 160 ohms, use the next highest easily available value, which is 180 ohms.

          For RL, something like 4.7kohm is fine or that ballpark, it is not very critical.

          If you use circuit#3, then the base of the transistor needs a resistor in series with the connection to the GPIO pin that drives it, although it is not shown. That can be a 1k resistor.

           

          I hope that helps, but if you need more help let me know.

          4 of 4 people found this helpful
            • Re: Optek OPB732WZ  and the Raspberry Pi ?
              amasters

              Thanks Shabaz for taking so much trouble to reply.

               

              I have re-visited the datasheet and with your explanation this seems to be much clearer.

               

              However, I am not clear about the purpose of the additional transistor in diagram 3, is this required to turn the infrared light off?   I am planning to run the Raspberry Pi using the mains adaptor plug and it will probably be in use for a maximum of two hours in any day, after which the Raspberry Pi will be turned off.

               

              My intended application is to record the time a piece of reflective tape passes by on a large wheel which has a rotation time of approximately two seconds, but could be a little faster or slower at various times.

               

              Have I interpreted circuit 2 correctly when I think that if the permanently on infrared LED shines on the reflective strip it will turn on the GPIO input pin. It appears to me that circuit 1 would keep the GPIO pin turned on when there is no light shining on it and turn off when there is ??

                • Re: Optek OPB732WZ  and the Raspberry Pi ?
                  shabaz

                  Hi Alan,

                  You're right, the extra transistor is for switching it off, or for pulsing it, for circuitry which isn't attached to the Pi, but can be used to pick up the signal amongst background light. It isn't used in your scenario if you're directly connecting to the Pi, and are running from the mains.

                  Circuit 1 and 2 are similar, one provides an inverted output and the other doesn't. The software can usually be coded to accept either scenario. However electrically circuit 1 is better for this purpose usually, because the output can swing a bit more, and is more flexible in the way it can be wired for some use-cases, not that it matters for your application. Anyway, best to go with circuit 1 usually, unless there is a reason it cannot be handled in software. But either will work.

                  1 of 1 people found this helpful
                    • Re: Optek OPB732WZ  and the Raspberry Pi ?

                      Thanks again for your help Shabaz. I have more confidence now in proceeding with this project.

                        • Re: Optek OPB732WZ  and the Raspberry Pi ?
                          shabaz

                          Hi Alan,

                           

                          Excellent, good luck with the project! I don't think you'll need this link, but just in case it provides any ideas:

                          Cyclops-1000: An Electronic Eye for Rotational Speed Measurement

                          That link is to a microcontroller project however, not Pi based, but maybe bits of it are helpful.

                          I find myself using it from time to time, to check things like small fan speeds end-on, i.e. directed at a fan blade with a white sticker stuck to it. The commercial tachometer tool I've got is actually less useful at such end-on applications and only really works side-on to rotating shafts/objects)

                           

                          If the time you're aiming to measure is of the order of 2 seconds as you mention, then the Pi should work fine for that to accuracy within a few msec hopefully (higher accuracy becomes harder because Linux could context-switch processes at any time).

                          1 of 1 people found this helpful