Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a bog standard barcode scanner with a USB output and I'm trying to figure out how to connect it to a PIC.

Basically, the idea is that I use the scanner to scan a barcode and the barcode is then passed to the PIC which in turn uses the barcode to do either lock or unlock a solenoid lock (the lock is something I'm going to work on later).

So I've been looking at ways to try and connect the barcode scanner to the PIC with somewhat limited success. So far it seems like one way might be to convert the USB output to an RS232 output and then connect it to the PIC and try to interpret the output but I'm not entirely sure whether that will work, or even how to do it.

So I was wondering if anyone had any ideas on a simple way I could go about connecting the scanner to the PIC please. Is the idea I have so far any good and, if so, are there any good ways to go about doing it? Or is it just needlessly complicated and is there a better way of doing it?

Thanks very much.

share|improve this question
I believe standard USB Barcode Readers work like a keyboard, if you can find a USB Keyboard solution the barcode reader may work directly with that – MattP Jan 18 at 7:55
up vote 6 down vote accepted

You would be better off with a barcode reader with serial or PS/2 interface. Sometimes it is as easy as swapping the cable for a different one to change the interface type, depends on your barcode scanner model.

If you really want to use the USB barcode reader, you need either

  • a PIC that can be an USB host like PIC24FJ256GB106 or PIC32MX420FxxxH or
  • a standalone USB host controller like MAX3421E
  • a software implemented USB host stack - I know they exist for Atmel, not sure about PIC

Even with these hardware solutions it would still take some effort to implement enumeration, the HID device class and so on.

Outside the scope of your question and probably more expensive than a serial or PS/2 barcode scanner, but there is a precompiled firmware for FTDI's Vinculum chips that bridges an USB HID device to a microcontroller's SPI interface, see USB HID to SPI Master Sample Application ROM.

share|improve this answer
Thanks! So if I were going to use a serial barcode reader instead, how would I go about connecting that to a PIC? Would I need any kind of special interface circuit between the reader and the PIC or could I just connect the output pins directly to the PIC? – GeorgePotter Nov 4 '12 at 23:15
The barcode reader will need power and you need a level shifter for RS-232<->TTL conversion. There are a lot of tutorials and readymade products available for that. I also edited the answer to include PS/2 barcode readers which are similarly easy to integrate (see computer-engineering.org/ps2protocol) and can do without level conversion. – AndreKR Nov 5 '12 at 0:00
That's brilliant, thanks very much. The whole thing looks a lot less daunting now. – GeorgePotter Nov 5 '12 at 0:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.