Simple USB receiver for IR data using PL2303HX and GP1UX31QS

In my previous post, I described infrared (IR) data transmission from the PIC18F4620 to a PC using the PICkit 2 as the receiving device. That example showed how a program running on the PIC could easily print messages on the computer screen in real time using the PICkit 2 application.

In this post, I describe an alternative receiver for the same transmitted IR data stream, this one using on a low-cost USB-to-serial converter (the PL2303HX, currently available from for $4.99). The same 36kHz IR receiver module (GP1UX31QS, available from for about 48 cent) is used again and the PIC circuit with the IR LED is precisely the same as that in the previous example. The big advantage of using a USB-to-serial converter rather than the PICkit 2 is that the data received can be channeled into any program running on the PC that can read data from a COM port (that’s what serial ports are called in Windows).

Ok, there’s not much to it really. Here’s how to connect the GP1UX31QS IR receiver to the PL2303HX USB-to-serial converter:

To display the data received by the PL2303HX, simply open it as a virtual COM port in any program that can read data from a serial port (e.g. Hyperterminal in Windows XP). The virtual COM port should be opened at 2,400 baud.

This entry was posted in Uncategorized. Bookmark the permalink.

15 Responses to Simple USB receiver for IR data using PL2303HX and GP1UX31QS

  1. paulleamy says:

    Last post on this are very helpful, cant wait to give it a shot!!!

    • batchloaf says:

      Thanks Paul. We’ve just ordered in a batch of the GP1UX31QS IR receivers and the PL2303HX USB-to-serial converters, so hopefully they’ll arrive in the next few days and we’ll be able to give some out to teams that want to try them.

  2. Vito says:

    Hello, I have a similar adapter, a CP2102 (USB 2.0 to UART TTL Serial Converter Module 6PIN CP2102), I would like to know exactly how to connect them to the place of PL2303HX), if possible.
    Also you can use a classic TSOP1738 or a TSOP1838, in place of the GP1UX31QS?
    Thank you.

    • batchloaf says:

      Hi Vito. I have previously used one of the TSOP devices with the PL2303HX (in exactly the same way as shown in the post) and it worked perfectly. I can’t remember exactly which TSOP device it was, but it might have been the TSOP1736. It was definitely a 36kHz model. The devices for other frequencies (e.g. TSOP1738 for 38kHz or TSOP1740 for 40kHz) will work fine too, but in case you’re using the PIC code I linked to in the post for your transmitter, its PWM frequency will need to be adjusted accordingly to make sure the IR led is modulated at the same frequency as the receiver.

      Regarding the connection between the IR receiver and the USB-to-serial converter, the exact details depend on the specific device you’re using. The CP2102 is a surface mount chip that is used in many different USB-to-serial converters, so I don’t know exactly which one you’re using. I’m assuming of course that you do have a breakout board of some kind, rather than just the surface mount chip itself (which would be complicated to use). Basically, all you need to do in most cases is connect the three pins of the IR receiver (e.g. TSOP1738) to three of the pins on the USB-to-serial converter – GND, 5V and Tx. Power is supplied to the IR receiver through the 5V and GND pins and it outputs any data received via the Tx pin.

      Possible complications that you could face are:

      • If the USB-to-serial converter is a 3.3V (rather than 5V) device and only provides that output voltage, I’m not sure whether the IR receiver will work the same. It probably will, but I’m not sure.
      • It’s possible that you might need a pull-up (or pull-down?) resistor on the Tx pin. This has been required for certain devices that I’ve used in the past, but I haven’t had to do it recently.
      • Vito says:

        Thank you for having responded to me.
        So I only use an infrared receiver that works at 36 kHz (at the time that I should not have, but only those from 38 KHz), without making any modifications to the source, right?

        My USB-TTL (with integrated CP2102), I took a few months ago on, with this Subject Number: 370532286388
        In any case, as shown in the figure, starting from left to right (the connector strip with 6-pin, facing upward) and with the USB connector facing down, I have the following pins:
        1) Reset (no wire connected to the breadboard from the USB-TTL);
        2) 3.3 V (blue wire);
        3) 5V (purple wire);
        4) TX (gray wire);
        5) RX (white wire);
        6) GND (black wire).

        Now, how should the connection exactly?

        Hello and thank you.

      • batchloaf says:

        Hello again Vito.
        I’m doing a bit of guesswork here since I don’t have the components that you’re using, but I think the connections you want are:

        If that doesn’t seem to be working, you could try moving the wire from the RXD pin to the TXD pin, because these pins are labeled the opposite way around on some devices.

        There’s no problem using my previous code example with a 38kHz receiver – there’s just one tiny change you need to make to a single line of code. Change line 66 from this…

            PR2 = 55;

        to this…

            PR2 = 52;

        The IR modulation signal should then be close to 38kHz.

  3. Yugen says:


    Is this method is effective in sniffing any type of IR remote control devices? I am just concern
    about the sniffed data being corrupted due to noise issues or signal timing mismatch.

    Any advice?


    • batchloaf says:

      Hi Yugen,

      Firstly, it will only work for devices that transmit at the correct carrier frequency (36kHz for my device). Also the bit rate will be quite limited. Basically, all this receiver detects is the presence or absence of 36kHz infrared and it takes a few cycles (about 10?) to detect when the signal appears. That really limits the amount of times it can detect the 36kHz signal switching on and off each second. Beyond that though, it’s just up to you to decrypt the signal. It should work for most TV remotes, provided they’re at the right frequency. A lot of them are actually 38kHz as far as I know, but this device might respond to those too? You can get a 38kHz version of the same device which would probably work better though.


      • Yugen says:

        Hi Ted,

        The device I am planning to work with is a 38kHz IR remote. I am actually trying to sniff out the data for each button pressed. My plan is to use it for automation testing purposes.

        My only concern is that there will be lost bits/data when I am trying to sniff out the command for each button press.


      • batchloaf says:

        Hi Yugen,

        With any binary communication channel, it’s possible for bit errors to occur. In this case, the error rate is likely to be low when the transmitter and receiver are separated by an appropriate distance and the transmitter is directly pointing at the receiver. However, the error rate could certainly be quite high under some conditions, such as when the distance is large between the remote control and the receiver and/or when the remote control is not pointing at the receiver. Since TV remote controls are designed to be used in very variable and non-ideal circumstances, they always use some kind of error checking in the protocol. Different error-checking methods are used in different manufacturers’ protocols. Sometimes it’s as simple as transmitting each code twice and if the two received codes are different the message is discarded. Whatever method of error checking is used, transmissions with errors are simply ignored. That means that when you press a button, it either does what you expect or nothing happens and you have to try again.

        Anyway, thinking more carefully now about what you’re trying to do I think the method used in this article may not be applicable. This example shows how to transmit information from a microcontroller to a serial port on a PC (actually a USB-to-serial converter). The serial port expects data to be packaged as a series of (normally) 8-bit bytes with start and stop bits, which is quite different to how most TV remotes transmit their codes. You cannot therefore just hook up this type of infrared receiver to a serial port and receive codes from a TV remote by reading data from the serial port – you would need something else to decode the binary signal coming out of the IR receiver. There are other USB devices that you can buy to receive TV remote signals, but I haven’t used them.


  4. Yugen says:

    Hi Ted,

    Thank you so much for your explanation. It has cleared up all my doubts. Thank you for taking the time to explain & share your views with me. Really appreciate it.



  5. Mike Walton says:

    Hi Ted,

    I hope this post is still active.

    I have a tea shop in which we use a plastic cup sealing machine. The sealing machine has a sensor that detects the location of the sealing film. The film is clear on the edges with black markers. When a cup has been sealed the film is advanced until the black marker covers the sensor and the film is ready for the next cup. There is also an LED display that shows the number of cups that have been sealed.
    The sensor is a FOTEC KU-07G. Its data sheet is:
    Can I use the PL2303HX to connect to the FOTEC sensor or do I need to use something more sophisticated like the Arduino?

    Kind regards,


    • batchloaf says:

      Hi Mike,

      I’m assuming you’re trying to connect the output of the FOTEK sensor to a PC – is that correct?

      Although there’s probably some roundabout way of connecting this FOTEK sensor to a PC using a PL2303HX, it’s not really the way to do it. The PL2303HX is a USB-to-serial converter, which means that it’s expecting a serial input signal – a sequence of evenly spaced ones and zeros (bits) that are grouped into sets of 8 (bytes), with each byte representing a number or character of text. That’s the type of signal that it would be receiving in my example above. In your case, the sensor output isn’t that kind of signal. Although you can think of the output of your sensor as a binary signal (i.e. it’s always either 1 or 0, high or low), it’s not what I’d call a serial signal because it doesn’t actually represent a series of bits, let along bytes representing characters of numbers.

      You can buy USB signal acquisition devices that allow software running on a PC to read the value of a voltage signal connected to the device – some expensive, some cheap. However, what I would normally use for something like this is exactly what you suggested: an Arduino. You can buy an Arduino Nano and USB cable on for about $2.50 and it would allow you to read the sensor state via USB. You would need to write a very short program to run on the Arduino (I can provide an example if you tell me more about what software is actually reading the signal on the PC, so that I know what form the Arduino should relay the readings in).

      Some electronic interfacing (specifically voltage conversion) also needs to be done between the FOTEK sensor (which runs at 10-30V) and the Arduino Nano (basically a 5V device). It’s just one or two resistors, but reducing the sensor output voltage is important because connecting a 10V signal from the sensor directly to the Arduino may damage the Arduino.

      Speaking of which, you will also need a 10V (or more) voltage supply for the FOTEK sensor. I’m not sure why the minimum operating voltage of the sensor is so high. There are many similar devices that operate at 3.3V or 5V. However, 10-30V is what the FOTEK datasheet specifies, so I guess you should stick to that. I suppose they are expecting the sensor to be connected to a PLC (programmable logic controller) or something like that which uses 10V inputs.

      If you want to give the Ardunio approach a try, I can try to sketch out a basic circuit and a some really short Arduino code.


      • Mike Walton says:

        Hi Ted,

        Thank you so much for replying to my question.

        I have a teashop that uses a machine to seal the top of each cup. Here is a Youtube link of a similar machine.

        The sealing film is transparent with black markers on the side. When the FOTEK sensor

        detects the black marker the led counter is incremented.
        I want to be able to see the total cups counted each day without going to the shop and without using a camera.
        I tested the FOTEK and the black wire is 12v when the light is blocked, otherwise it is 0v.

        I want to give the Ardunio approach a try, If you can sketch out a basic circuit and a some Arduino code I would really appreciate it.
        I went ahead and ordered an Arduino on Aliexpress and it should arrive any day now.

        I don’t actually need to use a PC if it is possible to send an email or GSM message directly from the Arduino. If I need the PC I will write the code in C.

        Thanks again,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s