Connecting Photo-Interrupt directly to Personal Computer

We recently had  customer inquiring about connecting one of our Photo Interrupt Boards directly to a computer.

Photo Interrupter board

We though about this for a few minutes and decided the best way to do this would be to use a FTDI to Serial breakout board. The FTDI presents itself as a serial port when connected to a computer.

Using an FTDI would be the perfect solution as the FTDI can supply power to the board and it can monitor at least 1 signal line – CTS (Clear To Send). CTS is a signal line used by a device connected to the FTDI, the device uses the line to signal the computer that it can send data to it (this is known as hardware flow control). For our purposes we use it to signal an interrupt.

The FTDI Breakout comes in 5V and 3.3V – either of which would be suitable to the task.

FTDI and Photo Interrupt


We wired up the system, using this connection wire, as follows: GND of the FTDI to GND of the photo interrupt , +3.3V/+5V of the FTDI to +5V of the photo interrupt and finally we connected the signal line of the photo interrupt to the CTS pin of the FTDI.

In order to monitor this from a computer you connect the FTDI to a USB cable in this case a mini USB cable you might need to install a driver for the FTDI device which can be obtained at When the device is installed it will show up as a serial port (COMxx). For the purpose of keeping this tutorial short we will not go into determining which COM port you need to use.

Now for the code, We threw together this quick sample in C# as it requires the least number of lines of code to achieve our purpose.

As you can see the code is pretty self-explanatory – our FTDI in on COM port 22 so we initialize the serial port for ‘COM22’. We don’t really care about the port speed as we are not going to be transferring any data, we just want to know the state of CTS.

We then set up a function to be called whenever CTS changes state i.e. when the interrupt controller gets interrupted.

And finally we open the com port and wait, we do however print out the count continuously.

Whenever the beam of the interrupt controller is broken the ‘serialPort_PinChanged’ function will be called. All we do is increment the count variable which of course will be reflected in the console window.

Now that you can connect your photo interrupt to your computer you can count almost anything that interrupts the beam i.e. water drops, etc.

If you have any ideas for future tutorials please send your suggestions to

{ 0 comments… add one }

Leave a Comment